mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Problem: Vim9: can still use the depricated #{} dict syntax. Solution: Remove support for #{} in Vim9 script. (closes #7406, closes #7405)
This commit is contained in:
parent
7f76494aac
commit
e0de171ecd
27
src/dict.c
27
src/dict.c
@ -782,6 +782,20 @@ dict2string(typval_T *tv, int copyID, int restore_copyID)
|
||||
return (char_u *)ga.ga_data;
|
||||
}
|
||||
|
||||
/*
|
||||
* Advance over a literal key, including "-". If the first character is not a
|
||||
* literal key character then "key" is returned.
|
||||
*/
|
||||
char_u *
|
||||
skip_literal_key(char_u *key)
|
||||
{
|
||||
char_u *p;
|
||||
|
||||
for (p = key; ASCII_ISALNUM(*p) || *p == '_' || *p == '-'; ++p)
|
||||
;
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the key for #{key: val} into "tv" and advance "arg".
|
||||
* Return FAIL when there is no valid key.
|
||||
@ -789,13 +803,10 @@ dict2string(typval_T *tv, int copyID, int restore_copyID)
|
||||
static int
|
||||
get_literal_key(char_u **arg, typval_T *tv)
|
||||
{
|
||||
char_u *p;
|
||||
char_u *p = skip_literal_key(*arg);
|
||||
|
||||
if (!ASCII_ISALNUM(**arg) && **arg != '_' && **arg != '-')
|
||||
if (p == *arg)
|
||||
return FAIL;
|
||||
|
||||
for (p = *arg; ASCII_ISALNUM(*p) || *p == '_' || *p == '-'; ++p)
|
||||
;
|
||||
tv->v_type = VAR_STRING;
|
||||
tv->vval.v_string = vim_strnsave(*arg, p - *arg);
|
||||
|
||||
@ -851,17 +862,15 @@ eval_dict(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int literal)
|
||||
*arg = skipwhite_and_linebreak(*arg + 1, evalarg);
|
||||
while (**arg != '}' && **arg != NUL)
|
||||
{
|
||||
char_u *p = to_name_end(*arg, FALSE);
|
||||
int has_bracket = vim9script && **arg == '[';
|
||||
|
||||
if (literal || (vim9script && *p == ':'))
|
||||
if (literal || (vim9script && !has_bracket))
|
||||
{
|
||||
if (get_literal_key(arg, &tvkey) == FAIL)
|
||||
goto failret;
|
||||
}
|
||||
else
|
||||
{
|
||||
int has_bracket = vim9script && **arg == '[';
|
||||
|
||||
if (has_bracket)
|
||||
*arg = skipwhite(*arg + 1);
|
||||
if (eval1(arg, &tvkey, evalarg) == FAIL) // recursive!
|
||||
|
@ -3254,7 +3254,7 @@ eval7(
|
||||
/*
|
||||
* Dictionary: #{key: val, key: val}
|
||||
*/
|
||||
case '#': if ((*arg)[1] == '{')
|
||||
case '#': if (!in_vim9script() && (*arg)[1] == '{')
|
||||
{
|
||||
++*arg;
|
||||
ret = eval_dict(arg, rettv, evalarg, TRUE);
|
||||
|
@ -33,6 +33,7 @@ varnumber_T dict_get_number_def(dict_T *d, char_u *key, int def);
|
||||
varnumber_T dict_get_number_check(dict_T *d, char_u *key);
|
||||
varnumber_T dict_get_bool(dict_T *d, char_u *key, int def);
|
||||
char_u *dict2string(typval_T *tv, int copyID, int restore_copyID);
|
||||
char_u *skip_literal_key(char_u *key);
|
||||
int eval_dict(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int literal);
|
||||
void dict_extend(dict_T *d1, dict_T *d2, char_u *action);
|
||||
dictitem_T *dict_lookup(hashitem_T *hi);
|
||||
|
@ -2172,7 +2172,7 @@ func Test_popup_scrollbar()
|
||||
endfunc
|
||||
|
||||
def CreatePopup(text: list<string>)
|
||||
popup_create(text, #{
|
||||
popup_create(text, {
|
||||
\ minwidth: 30,
|
||||
\ maxwidth: 30,
|
||||
\ minheight: 4,
|
||||
@ -2717,7 +2717,7 @@ def Popupwin_close_prevwin()
|
||||
split
|
||||
wincmd b
|
||||
assert_equal(2, winnr())
|
||||
var buf = term_start(&shell, #{hidden: 1})
|
||||
var buf = term_start(&shell, {hidden: 1})
|
||||
popup_create(buf, {})
|
||||
TermWait(buf, 100)
|
||||
popup_clear(true)
|
||||
|
@ -219,15 +219,15 @@ def Test_prop_find2()
|
||||
# Multiple props per line, start on the first, should find the second.
|
||||
new
|
||||
['the quikc bronw fox jumsp over the layz dog']->repeat(2)->setline(1)
|
||||
prop_type_add('misspell', #{highlight: 'ErrorMsg'})
|
||||
prop_type_add('misspell', {highlight: 'ErrorMsg'})
|
||||
for lnum in [1, 2]
|
||||
for col in [8, 14, 24, 38]
|
||||
prop_add(lnum, col, #{type: 'misspell', length: 2})
|
||||
prop_add(lnum, col, {type: 'misspell', length: 2})
|
||||
endfor
|
||||
endfor
|
||||
cursor(1, 8)
|
||||
var expected = {'lnum': 1, 'id': 0, 'col': 14, 'end': 1, 'type': 'misspell', 'length': 2, 'start': 1}
|
||||
var result = prop_find(#{type: 'misspell', skipstart: true}, 'f')
|
||||
var expected = {lnum: 1, id: 0, col: 14, end: 1, type: 'misspell', length: 2, start: 1}
|
||||
var result = prop_find({type: 'misspell', skipstart: true}, 'f')
|
||||
assert_equal(expected, result)
|
||||
|
||||
prop_type_delete('misspell')
|
||||
@ -322,7 +322,7 @@ func Test_prop_remove()
|
||||
endfunc
|
||||
|
||||
def Test_prop_add_vim9()
|
||||
prop_type_add('comment', #{
|
||||
prop_type_add('comment', {
|
||||
highlight: 'Directory',
|
||||
priority: 123,
|
||||
start_incl: true,
|
||||
@ -336,7 +336,7 @@ def Test_prop_remove_vim9()
|
||||
new
|
||||
AddPropTypes()
|
||||
SetupPropsInFirstLine()
|
||||
assert_equal(1, prop_remove({'type': 'three', 'id': 13, 'both': true, 'all': true}))
|
||||
assert_equal(1, prop_remove({type: 'three', id: 13, both: true, all: true}))
|
||||
DeletePropTypes()
|
||||
bwipe!
|
||||
enddef
|
||||
|
@ -360,26 +360,26 @@ def Test_extend_dict()
|
||||
var lines =<< trim END
|
||||
vim9script
|
||||
var d: dict<number>
|
||||
extend(d, #{a: 1})
|
||||
assert_equal(#{a: 1}, d)
|
||||
extend(d, {a: 1})
|
||||
assert_equal({a: 1}, d)
|
||||
|
||||
var d2: dict<number>
|
||||
d2['one'] = 1
|
||||
assert_equal(#{one: 1}, d2)
|
||||
assert_equal({one: 1}, d2)
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
var d: dict<string> = test_null_dict()
|
||||
extend(d, #{a: 'x'})
|
||||
assert_equal(#{a: 'x'}, d)
|
||||
extend(d, {a: 'x'})
|
||||
assert_equal({a: 'x'}, d)
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
extend(test_null_dict(), #{a: 'x'})
|
||||
extend(test_null_dict(), {a: 'x'})
|
||||
END
|
||||
CheckScriptFailure(lines, 'E1133:', 2)
|
||||
enddef
|
||||
@ -487,20 +487,20 @@ def Test_assignment_list_vim9script()
|
||||
enddef
|
||||
|
||||
def Test_assignment_dict()
|
||||
var dict1: dict<bool> = #{one: false, two: true}
|
||||
var dict2: dict<number> = #{one: 1, two: 2}
|
||||
var dict3: dict<string> = #{key: 'value'}
|
||||
var dict4: dict<any> = #{one: 1, two: '2'}
|
||||
var dict5: dict<blob> = #{one: 0z01, two: 0z02}
|
||||
var dict1: dict<bool> = {one: false, two: true}
|
||||
var dict2: dict<number> = {one: 1, two: 2}
|
||||
var dict3: dict<string> = {key: 'value'}
|
||||
var dict4: dict<any> = {one: 1, two: '2'}
|
||||
var dict5: dict<blob> = {one: 0z01, two: 0z02}
|
||||
|
||||
# overwrite
|
||||
dict3['key'] = 'another'
|
||||
assert_equal(dict3, #{key: 'another'})
|
||||
assert_equal(dict3, {key: 'another'})
|
||||
dict3.key = 'yet another'
|
||||
assert_equal(dict3, #{key: 'yet another'})
|
||||
assert_equal(dict3, {key: 'yet another'})
|
||||
|
||||
var lines =<< trim END
|
||||
var dd = #{one: 1}
|
||||
var dd = {one: 1}
|
||||
dd.one) = 2
|
||||
END
|
||||
CheckDefFailure(lines, 'E15:', 2)
|
||||
@ -508,10 +508,10 @@ def Test_assignment_dict()
|
||||
# empty key can be used
|
||||
var dd = {}
|
||||
dd[""] = 6
|
||||
assert_equal({'': 6}, dd)
|
||||
assert_equal({['']: 6}, dd)
|
||||
|
||||
# type becomes dict<any>
|
||||
var somedict = rand() > 0 ? #{a: 1, b: 2} : #{a: 'a', b: 'b'}
|
||||
var somedict = rand() > 0 ? {a: 1, b: 2} : {a: 'a', b: 'b'}
|
||||
|
||||
# assignment to script-local dict
|
||||
lines =<< trim END
|
||||
@ -521,7 +521,7 @@ def Test_assignment_dict()
|
||||
test['a'] = 43
|
||||
return test
|
||||
enddef
|
||||
assert_equal(#{a: 43}, FillDict())
|
||||
assert_equal({a: 43}, FillDict())
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
|
||||
@ -544,7 +544,7 @@ def Test_assignment_dict()
|
||||
g:test['a'] = 43
|
||||
return g:test
|
||||
enddef
|
||||
assert_equal(#{a: 43}, FillDict())
|
||||
assert_equal({a: 43}, FillDict())
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
|
||||
@ -556,7 +556,7 @@ def Test_assignment_dict()
|
||||
b:test['a'] = 43
|
||||
return b:test
|
||||
enddef
|
||||
assert_equal(#{a: 43}, FillDict())
|
||||
assert_equal({a: 43}, FillDict())
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
enddef
|
||||
@ -636,7 +636,7 @@ def Test_assignment_default()
|
||||
|
||||
if has('unix') && executable('cat')
|
||||
# check with non-null job and channel, types must match
|
||||
thejob = job_start("cat ", #{})
|
||||
thejob = job_start("cat ", {})
|
||||
thechannel = job_getchannel(thejob)
|
||||
job_stop(thejob, 'kill')
|
||||
endif
|
||||
@ -827,8 +827,8 @@ def Test_assignment_failure()
|
||||
CheckDefFailure(['var name: list<string> = [123]'], 'expected list<string> but got list<number>')
|
||||
CheckDefFailure(['var name: list<number> = ["xx"]'], 'expected list<number> but got list<string>')
|
||||
|
||||
CheckDefFailure(['var name: dict<string> = #{key: 123}'], 'expected dict<string> but got dict<number>')
|
||||
CheckDefFailure(['var name: dict<number> = #{key: "xx"}'], 'expected dict<number> but got dict<string>')
|
||||
CheckDefFailure(['var name: dict<string> = {key: 123}'], 'expected dict<string> but got dict<number>')
|
||||
CheckDefFailure(['var name: dict<number> = {key: "xx"}'], 'expected dict<number> but got dict<string>')
|
||||
|
||||
CheckDefFailure(['var name = feedkeys("0")'], 'E1031:')
|
||||
CheckDefFailure(['var name: number = feedkeys("0")'], 'expected number but got void')
|
||||
@ -883,17 +883,17 @@ def Test_assign_dict()
|
||||
for i in range(3)
|
||||
nrd[i] = i
|
||||
endfor
|
||||
assert_equal({'0': 0, '1': 1, '2': 2}, nrd)
|
||||
assert_equal({0: 0, 1: 1, 2: 2}, nrd)
|
||||
|
||||
CheckDefFailure(["var d: dict<number> = #{a: '', b: true}"], 'E1012: Type mismatch; expected dict<number> but got dict<any>', 1)
|
||||
CheckDefFailure(["var d: dict<dict<number>> = #{x: #{a: '', b: true}}"], 'E1012: Type mismatch; expected dict<dict<number>> but got dict<dict<any>>', 1)
|
||||
CheckDefFailure(["var d: dict<number> = {a: '', b: true}"], 'E1012: Type mismatch; expected dict<number> but got dict<any>', 1)
|
||||
CheckDefFailure(["var d: dict<dict<number>> = {x: {a: '', b: true}}"], 'E1012: Type mismatch; expected dict<dict<number>> but got dict<dict<any>>', 1)
|
||||
enddef
|
||||
|
||||
def Test_assign_dict_unknown_type()
|
||||
var lines =<< trim END
|
||||
vim9script
|
||||
var mylist = []
|
||||
mylist += [#{one: 'one'}]
|
||||
mylist += [{one: 'one'}]
|
||||
def Func()
|
||||
var dd = mylist[0]
|
||||
assert_equal('one', dd.one)
|
||||
@ -905,7 +905,7 @@ def Test_assign_dict_unknown_type()
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
var mylist = [[]]
|
||||
mylist[0] += [#{one: 'one'}]
|
||||
mylist[0] += [{one: 'one'}]
|
||||
def Func()
|
||||
var dd = mylist[0][0]
|
||||
assert_equal('one', dd.one)
|
||||
@ -1010,7 +1010,7 @@ def Test_let_declaration()
|
||||
g:other_var = other
|
||||
|
||||
# type is inferred
|
||||
s:dict = {'a': 222}
|
||||
s:dict = {['a']: 222}
|
||||
def GetDictVal(key: any)
|
||||
g:dict_val = s:dict[key]
|
||||
enddef
|
||||
|
@ -32,7 +32,7 @@ func Test_InternalFuncRetType()
|
||||
enddef
|
||||
|
||||
def RetListAny(): list<any>
|
||||
return items({'k': 'v'})
|
||||
return items({k: 'v'})
|
||||
enddef
|
||||
|
||||
def RetListString(): list<string>
|
||||
@ -197,10 +197,10 @@ def Test_extend_arg_types()
|
||||
assert_equal([1, 3, 2], extend([1, 2], [3], 1))
|
||||
assert_equal([1, 3, 2], extend([1, 2], [3], s:number_one))
|
||||
|
||||
assert_equal(#{a: 1, b: 2, c: 3}, extend(#{a: 1, b: 2}, #{c: 3}))
|
||||
assert_equal(#{a: 1, b: 4}, extend(#{a: 1, b: 2}, #{b: 4}))
|
||||
assert_equal(#{a: 1, b: 2}, extend(#{a: 1, b: 2}, #{b: 4}, 'keep'))
|
||||
assert_equal(#{a: 1, b: 2}, extend(#{a: 1, b: 2}, #{b: 4}, s:string_keep))
|
||||
assert_equal({a: 1, b: 2, c: 3}, extend({a: 1, b: 2}, {c: 3}))
|
||||
assert_equal({a: 1, b: 4}, extend({a: 1, b: 2}, {b: 4}))
|
||||
assert_equal({a: 1, b: 2}, extend({a: 1, b: 2}, {b: 4}, 'keep'))
|
||||
assert_equal({a: 1, b: 2}, extend({a: 1, b: 2}, {b: 4}, s:string_keep))
|
||||
|
||||
var res: list<dict<any>>
|
||||
extend(res, map([1, 2], {_, v -> {}}))
|
||||
@ -210,9 +210,9 @@ def Test_extend_arg_types()
|
||||
CheckDefFailure(['extend([1, 2], ["x"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>')
|
||||
CheckDefFailure(['extend([1, 2], [3], "x")'], 'E1013: Argument 3: type mismatch, expected number but got string')
|
||||
|
||||
CheckDefFailure(['extend(#{a: 1}, 42)'], 'E1013: Argument 2: type mismatch, expected dict<number> but got number')
|
||||
CheckDefFailure(['extend(#{a: 1}, #{b: "x"})'], 'E1013: Argument 2: type mismatch, expected dict<number> but got dict<string>')
|
||||
CheckDefFailure(['extend(#{a: 1}, #{b: 2}, 1)'], 'E1013: Argument 3: type mismatch, expected string but got number')
|
||||
CheckDefFailure(['extend({a: 1}, 42)'], 'E1013: Argument 2: type mismatch, expected dict<number> but got number')
|
||||
CheckDefFailure(['extend({a: 1}, {b: "x"})'], 'E1013: Argument 2: type mismatch, expected dict<number> but got dict<string>')
|
||||
CheckDefFailure(['extend({a: 1}, {b: 2}, 1)'], 'E1013: Argument 3: type mismatch, expected string but got number')
|
||||
enddef
|
||||
|
||||
def Test_extend_return_type()
|
||||
@ -254,7 +254,7 @@ def Test_getbufinfo()
|
||||
edit Xtestfile1
|
||||
hide edit Xtestfile2
|
||||
hide enew
|
||||
getbufinfo(#{bufloaded: true, buflisted: true, bufmodified: false})
|
||||
getbufinfo({bufloaded: true, buflisted: true, bufmodified: false})
|
||||
->len()->assert_equal(3)
|
||||
bwipe Xtestfile1 Xtestfile2
|
||||
enddef
|
||||
@ -297,16 +297,16 @@ def Test_getloclist_return_type()
|
||||
var l = getloclist(1)
|
||||
l->assert_equal([])
|
||||
|
||||
var d = getloclist(1, #{items: 0})
|
||||
d->assert_equal(#{items: []})
|
||||
var d = getloclist(1, {items: 0})
|
||||
d->assert_equal({items: []})
|
||||
enddef
|
||||
|
||||
def Test_getqflist_return_type()
|
||||
var l = getqflist()
|
||||
l->assert_equal([])
|
||||
|
||||
var d = getqflist(#{items: 0})
|
||||
d->assert_equal(#{items: []})
|
||||
var d = getqflist({items: 0})
|
||||
d->assert_equal({items: []})
|
||||
enddef
|
||||
|
||||
def Test_getreg()
|
||||
@ -368,7 +368,7 @@ def Test_insert()
|
||||
enddef
|
||||
|
||||
def Test_keys_return_type()
|
||||
const var: list<string> = #{a: 1, b: 2}->keys()
|
||||
const var: list<string> = {a: 1, b: 2}->keys()
|
||||
var->assert_equal(['a', 'b'])
|
||||
enddef
|
||||
|
||||
@ -388,7 +388,7 @@ enddef
|
||||
def Test_maparg()
|
||||
var lnum = str2nr(expand('<sflnum>'))
|
||||
map foo bar
|
||||
maparg('foo', '', false, true)->assert_equal(#{
|
||||
maparg('foo', '', false, true)->assert_equal({
|
||||
lnum: lnum + 1,
|
||||
script: 0,
|
||||
mode: ' ',
|
||||
@ -428,7 +428,7 @@ def Test_readdir()
|
||||
enddef
|
||||
|
||||
def Test_remove_return_type()
|
||||
var l = remove(#{one: [1, 2], two: [3, 4]}, 'one')
|
||||
var l = remove({one: [1, 2], two: [3, 4]}, 'one')
|
||||
var res = 0
|
||||
for n in l
|
||||
res += n
|
||||
@ -466,8 +466,8 @@ def Test_searchcount()
|
||||
new
|
||||
setline(1, "foo bar")
|
||||
:/foo
|
||||
searchcount(#{recompute: true})
|
||||
->assert_equal(#{
|
||||
searchcount({recompute: true})
|
||||
->assert_equal({
|
||||
exact_match: 1,
|
||||
current: 1,
|
||||
total: 1,
|
||||
@ -496,8 +496,8 @@ def Test_setbufvar()
|
||||
enddef
|
||||
|
||||
def Test_setloclist()
|
||||
var items = [#{filename: '/tmp/file', lnum: 1, valid: true}]
|
||||
var what = #{items: items}
|
||||
var items = [{filename: '/tmp/file', lnum: 1, valid: true}]
|
||||
var what = {items: items}
|
||||
setqflist([], ' ', what)
|
||||
setloclist(0, [], ' ', what)
|
||||
enddef
|
||||
@ -570,7 +570,7 @@ def Test_term_start()
|
||||
else
|
||||
botright new
|
||||
var winnr = winnr()
|
||||
term_start(&shell, #{curwin: true})
|
||||
term_start(&shell, {curwin: true})
|
||||
winnr()->assert_equal(winnr)
|
||||
bwipe!
|
||||
endif
|
||||
@ -586,7 +586,7 @@ enddef
|
||||
|
||||
def Test_win_splitmove()
|
||||
split
|
||||
win_splitmove(1, 2, #{vertical: true, rightbelow: true})
|
||||
win_splitmove(1, 2, {vertical: true, rightbelow: true})
|
||||
close
|
||||
enddef
|
||||
|
||||
|
@ -251,18 +251,18 @@ def Test_skipped_expr_linebreak()
|
||||
enddef
|
||||
|
||||
def Test_dict_member()
|
||||
var test: dict<list<number>> = {'data': [3, 1, 2]}
|
||||
var test: dict<list<number>> = {data: [3, 1, 2]}
|
||||
test.data->sort()
|
||||
assert_equal(#{data: [1, 2, 3]}, test)
|
||||
assert_equal({data: [1, 2, 3]}, test)
|
||||
test.data
|
||||
->reverse()
|
||||
assert_equal(#{data: [3, 2, 1]}, test)
|
||||
assert_equal({data: [3, 2, 1]}, test)
|
||||
|
||||
var lines =<< trim END
|
||||
vim9script
|
||||
var test: dict<list<number>> = {'data': [3, 1, 2]}
|
||||
var test: dict<list<number>> = {data: [3, 1, 2]}
|
||||
test.data->sort()
|
||||
assert_equal(#{data: [1, 2, 3]}, test)
|
||||
assert_equal({data: [1, 2, 3]}, test)
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
enddef
|
||||
@ -308,9 +308,9 @@ def Test_bar_after_command()
|
||||
enddef
|
||||
|
||||
def Test_filter_is_not_modifier()
|
||||
var tags = [{'a': 1, 'b': 2}, {'x': 3, 'y': 4}]
|
||||
var tags = [{a: 1, b: 2}, {x: 3, y: 4}]
|
||||
filter(tags, { _, v -> has_key(v, 'x') ? 1 : 0 })
|
||||
assert_equal([#{x: 3, y: 4}], tags)
|
||||
assert_equal([{x: 3, y: 4}], tags)
|
||||
enddef
|
||||
|
||||
def Test_command_modifier_filter()
|
||||
|
@ -390,7 +390,7 @@ enddef
|
||||
|
||||
def s:ScriptFuncNew()
|
||||
var ll = [1, "two", 333]
|
||||
var dd = #{one: 1, two: "val"}
|
||||
var dd = {one: 1, two: "val"}
|
||||
enddef
|
||||
|
||||
def Test_disassemble_new()
|
||||
@ -402,7 +402,7 @@ def Test_disassemble_new()
|
||||
'\d PUSHNR 333\_s*' ..
|
||||
'\d NEWLIST size 3\_s*' ..
|
||||
'\d STORE $0\_s*' ..
|
||||
'var dd = #{one: 1, two: "val"}\_s*' ..
|
||||
'var dd = {one: 1, two: "val"}\_s*' ..
|
||||
'\d PUSHS "one"\_s*' ..
|
||||
'\d PUSHNR 1\_s*' ..
|
||||
'\d PUSHS "two"\_s*' ..
|
||||
@ -1292,7 +1292,7 @@ def Test_disassemble_list_slice()
|
||||
enddef
|
||||
|
||||
def DictMember(): number
|
||||
var d = #{item: 1}
|
||||
var d = {item: 1}
|
||||
var res = d.item
|
||||
res = d["item"]
|
||||
return res
|
||||
@ -1301,7 +1301,7 @@ enddef
|
||||
def Test_disassemble_dict_member()
|
||||
var instr = execute('disassemble DictMember')
|
||||
assert_match('DictMember\_s*' ..
|
||||
'var d = #{item: 1}\_s*' ..
|
||||
'var d = {item: 1}\_s*' ..
|
||||
'\d PUSHS "item"\_s*' ..
|
||||
'\d PUSHNR 1\_s*' ..
|
||||
'\d NEWDICT size 1\_s*' ..
|
||||
@ -1473,10 +1473,10 @@ def Test_disassemble_compare()
|
||||
['[1, 2] is aList', 'COMPARELIST is'],
|
||||
['[1, 2] isnot aList', 'COMPARELIST isnot'],
|
||||
|
||||
['#{a: 1} == aDict', 'COMPAREDICT =='],
|
||||
['#{a: 1} != aDict', 'COMPAREDICT !='],
|
||||
['#{a: 1} is aDict', 'COMPAREDICT is'],
|
||||
['#{a: 1} isnot aDict', 'COMPAREDICT isnot'],
|
||||
['{a: 1} == aDict', 'COMPAREDICT =='],
|
||||
['{a: 1} != aDict', 'COMPAREDICT !='],
|
||||
['{a: 1} is aDict', 'COMPAREDICT is'],
|
||||
['{a: 1} isnot aDict', 'COMPAREDICT isnot'],
|
||||
|
||||
['{->33} == {->44}', 'COMPAREFUNC =='],
|
||||
['{->33} != {->44}', 'COMPAREFUNC !='],
|
||||
@ -1519,7 +1519,7 @@ def Test_disassemble_compare()
|
||||
' var aString = "yy"',
|
||||
' var aBlob = 0z22',
|
||||
' var aList = [3, 4]',
|
||||
' var aDict = #{x: 2}',
|
||||
' var aDict = {x: 2}',
|
||||
floatDecl,
|
||||
' if ' .. case[0],
|
||||
' echo 42'
|
||||
|
@ -27,7 +27,7 @@ def Test_expr1_trinary()
|
||||
: 'two')
|
||||
assert_equal('one', !!0z1234 ? 'one' : 'two')
|
||||
assert_equal('one', !![0] ? 'one' : 'two')
|
||||
assert_equal('one', !!#{x: 0} ? 'one' : 'two')
|
||||
assert_equal('one', !!{x: 0} ? 'one' : 'two')
|
||||
var name = 1
|
||||
assert_equal('one', name ? 'one' : 'two')
|
||||
|
||||
@ -206,7 +206,7 @@ def Test_expr1_falsy()
|
||||
assert_equal(123, 123 ?? 456)
|
||||
assert_equal('yes', 'yes' ?? 456)
|
||||
assert_equal([1], [1] ?? 456)
|
||||
assert_equal(#{one: 1}, #{one: 1} ?? 456)
|
||||
assert_equal({one: 1}, {one: 1} ?? 456)
|
||||
if has('float')
|
||||
assert_equal(0.1, 0.1 ?? 456)
|
||||
endif
|
||||
@ -553,12 +553,12 @@ def Test_expr4_equal()
|
||||
assert_equal(false, [1, 2, 3] == [])
|
||||
assert_equal(false, [1, 2, 3] == ['1', '2', '3'])
|
||||
|
||||
assert_equal(true, #{one: 1, two: 2} == #{one: 1, two: 2})
|
||||
assert_equal(false, #{one: 1, two: 2} == #{one: 2, two: 2})
|
||||
assert_equal(false, #{one: 1, two: 2} == #{two: 2})
|
||||
assert_equal(false, #{one: 1, two: 2} == #{})
|
||||
assert_equal(true, g:adict == #{bbb: 8, aaa: 2})
|
||||
assert_equal(false, #{ccc: 9, aaa: 2} == g:adict)
|
||||
assert_equal(true, {one: 1, two: 2} == {one: 1, two: 2})
|
||||
assert_equal(false, {one: 1, two: 2} == {one: 2, two: 2})
|
||||
assert_equal(false, {one: 1, two: 2} == {two: 2})
|
||||
assert_equal(false, {one: 1, two: 2} == {})
|
||||
assert_equal(true, g:adict == {bbb: 8, aaa: 2})
|
||||
assert_equal(false, {ccc: 9, aaa: 2} == g:adict)
|
||||
|
||||
assert_equal(true, function('g:Test_expr4_equal') == function('g:Test_expr4_equal'))
|
||||
assert_equal(false, function('g:Test_expr4_equal') == function('g:Test_expr4_is'))
|
||||
@ -650,12 +650,12 @@ def Test_expr4_notequal()
|
||||
assert_equal(true, [1, 2, 3] != [])
|
||||
assert_equal(true, [1, 2, 3] != ['1', '2', '3'])
|
||||
|
||||
assert_equal(false, #{one: 1, two: 2} != #{one: 1, two: 2})
|
||||
assert_equal(true, #{one: 1, two: 2} != #{one: 2, two: 2})
|
||||
assert_equal(true, #{one: 1, two: 2} != #{two: 2})
|
||||
assert_equal(true, #{one: 1, two: 2} != #{})
|
||||
assert_equal(false, g:adict != #{bbb: 8, aaa: 2})
|
||||
assert_equal(true, #{ccc: 9, aaa: 2} != g:adict)
|
||||
assert_equal(false, {one: 1, two: 2} != {one: 1, two: 2})
|
||||
assert_equal(true, {one: 1, two: 2} != {one: 2, two: 2})
|
||||
assert_equal(true, {one: 1, two: 2} != {two: 2})
|
||||
assert_equal(true, {one: 1, two: 2} != {})
|
||||
assert_equal(false, g:adict != {bbb: 8, aaa: 2})
|
||||
assert_equal(true, {ccc: 9, aaa: 2} != g:adict)
|
||||
|
||||
assert_equal(false, function('g:Test_expr4_equal') != function('g:Test_expr4_equal'))
|
||||
assert_equal(true, function('g:Test_expr4_equal') != function('g:Test_expr4_is'))
|
||||
@ -1197,7 +1197,7 @@ def Test_expr5_vim9script()
|
||||
CheckScriptFailure(lines, 'E730:', 2)
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
echo 'a' .. #{a: 1}
|
||||
echo 'a' .. {a: 1}
|
||||
END
|
||||
CheckScriptFailure(lines, 'E731:', 2)
|
||||
lines =<< trim END
|
||||
@ -1287,7 +1287,7 @@ func Test_expr5_fails()
|
||||
call CheckDefFailure(["var x = 6 + xxx"], 'E1001:', 1)
|
||||
|
||||
call CheckDefFailure(["var x = 'a' .. [1]"], 'E1105:', 1)
|
||||
call CheckDefFailure(["var x = 'a' .. #{a: 1}"], 'E1105:', 1)
|
||||
call CheckDefFailure(["var x = 'a' .. {a: 1}"], 'E1105:', 1)
|
||||
call CheckDefFailure(["var x = 'a' .. test_void()"], 'E1105:', 1)
|
||||
call CheckDefFailure(["var x = 'a' .. 0z32"], 'E1105:', 1)
|
||||
call CheckDefFailure(["var x = 'a' .. function('len')"], 'E1105:', 1)
|
||||
@ -1469,9 +1469,9 @@ func Test_expr6_fails()
|
||||
call CheckDefFailure(["var x = [1] / [2]"], 'E1036:', 1)
|
||||
call CheckDefFailure(["var x = [1] % [2]"], 'E1035:', 1)
|
||||
|
||||
call CheckDefFailure(["var x = #{one: 1} * #{two: 2}"], 'E1036:', 1)
|
||||
call CheckDefFailure(["var x = #{one: 1} / #{two: 2}"], 'E1036:', 1)
|
||||
call CheckDefFailure(["var x = #{one: 1} % #{two: 2}"], 'E1035:', 1)
|
||||
call CheckDefFailure(["var x = {one: 1} * {two: 2}"], 'E1036:', 1)
|
||||
call CheckDefFailure(["var x = {one: 1} / {two: 2}"], 'E1036:', 1)
|
||||
call CheckDefFailure(["var x = {one: 1} % {two: 2}"], 'E1035:', 1)
|
||||
|
||||
call CheckDefFailure(["var x = 0xff[1]"], 'E1107:', 1)
|
||||
if has('float')
|
||||
@ -1796,9 +1796,9 @@ def Test_expr7_lambda()
|
||||
# line continuation inside lambda with "cond ? expr : expr" works
|
||||
var ll = range(3)
|
||||
map(ll, {k, v -> v % 2 ? {
|
||||
'111': 111 } : {}
|
||||
['111']: 111 } : {}
|
||||
})
|
||||
assert_equal([{}, {'111': 111}, {}], ll)
|
||||
assert_equal([{}, {111: 111}, {}], ll)
|
||||
|
||||
ll = range(3)
|
||||
map(ll, {k, v -> v == 8 || v
|
||||
@ -1814,11 +1814,11 @@ def Test_expr7_lambda()
|
||||
})
|
||||
assert_equal([111, 222, 111], ll)
|
||||
|
||||
var dl = [{'key': 0}, {'key': 22}]->filter({ _, v -> v['key'] })
|
||||
assert_equal([{'key': 22}], dl)
|
||||
var dl = [{key: 0}, {key: 22}]->filter({ _, v -> v['key'] })
|
||||
assert_equal([{key: 22}], dl)
|
||||
|
||||
dl = [{'key': 12}, {'foo': 34}]
|
||||
assert_equal([{'key': 12}], filter(dl,
|
||||
dl = [{key: 12}, {['foo']: 34}]
|
||||
assert_equal([{key: 12}], filter(dl,
|
||||
{_, v -> has_key(v, 'key') ? v['key'] == 12 : 0}))
|
||||
|
||||
assert_equal(false, LambdaWithComments()(0))
|
||||
@ -1846,9 +1846,9 @@ def Test_expr7_lambda()
|
||||
'E1106: 2 arguments too many')
|
||||
CheckDefFailure(["echo 'asdf'->{a -> a}(x)"], 'E1001:', 1)
|
||||
|
||||
CheckDefSuccess(['var Fx = {a -> #{k1: 0,', ' k2: 1}}'])
|
||||
CheckDefFailure(['var Fx = {a -> #{k1: 0', ' k2: 1}}'], 'E722:', 2)
|
||||
CheckDefFailure(['var Fx = {a -> #{k1: 0,', ' k2 1}}'], 'E720:', 2)
|
||||
CheckDefSuccess(['var Fx = {a -> {k1: 0,', ' k2: 1}}'])
|
||||
CheckDefFailure(['var Fx = {a -> {k1: 0', ' k2: 1}}'], 'E722:', 2)
|
||||
CheckDefFailure(['var Fx = {a -> {k1: 0,', ' k2 1}}'], 'E720:', 2)
|
||||
|
||||
CheckDefSuccess(['var Fx = {a -> [0,', ' 1]}'])
|
||||
CheckDefFailure(['var Fx = {a -> [0', ' 1]}'], 'E696:', 2)
|
||||
@ -1894,59 +1894,68 @@ def Test_expr7_dict()
|
||||
var lines =<< trim END
|
||||
assert_equal(g:dict_empty, {})
|
||||
assert_equal(g:dict_empty, { })
|
||||
assert_equal(g:dict_one, {'one': 1})
|
||||
assert_equal(g:dict_one, {['one']: 1})
|
||||
var key = 'one'
|
||||
var val = 1
|
||||
assert_equal(g:dict_one, {[key]: val})
|
||||
|
||||
var numbers: dict<number> = {a: 1, b: 2, c: 3}
|
||||
numbers = #{a: 1}
|
||||
numbers = #{}
|
||||
numbers = {a: 1}
|
||||
numbers = {}
|
||||
|
||||
var strings: dict<string> = {a: 'a', b: 'b', c: 'c'}
|
||||
strings = #{a: 'x'}
|
||||
strings = #{}
|
||||
strings = {a: 'x'}
|
||||
strings = {}
|
||||
|
||||
var dash = {xx-x: 8}
|
||||
assert_equal({['xx-x']: 8}, dash)
|
||||
|
||||
var dnr = {8: 8}
|
||||
assert_equal({['8']: 8}, dnr)
|
||||
|
||||
var mixed: dict<any> = {a: 'a', b: 42}
|
||||
mixed = #{a: 'x'}
|
||||
mixed = #{a: 234}
|
||||
mixed = #{}
|
||||
mixed = {a: 'x'}
|
||||
mixed = {a: 234}
|
||||
mixed = {}
|
||||
|
||||
var dictlist: dict<list<string>> = #{absent: [], present: ['hi']}
|
||||
dictlist = #{absent: ['hi'], present: []}
|
||||
dictlist = #{absent: [], present: []}
|
||||
var dictlist: dict<list<string>> = {absent: [], present: ['hi']}
|
||||
dictlist = {absent: ['hi'], present: []}
|
||||
dictlist = {absent: [], present: []}
|
||||
|
||||
var dictdict: dict<dict<string>> = #{one: #{a: 'text'}, two: #{}}
|
||||
dictdict = #{one: #{}, two: #{a: 'text'}}
|
||||
dictdict = #{one: #{}, two: #{}}
|
||||
var dictdict: dict<dict<string>> = {one: {a: 'text'}, two: {}}
|
||||
dictdict = {one: {}, two: {a: 'text'}}
|
||||
dictdict = {one: {}, two: {}}
|
||||
|
||||
assert_equal({'': 0}, {matchstr('string', 'wont match'): 0})
|
||||
assert_equal({['']: 0}, {[matchstr('string', 'wont match')]: 0})
|
||||
|
||||
assert_equal(g:test_space_dict, {['']: 'empty', [' ']: 'space'})
|
||||
assert_equal(g:test_hash_dict, {one: 1, two: 2})
|
||||
END
|
||||
CheckDefAndScriptSuccess(lines)
|
||||
|
||||
CheckDefFailure(["var x = #{a:8}"], 'E1069:', 1)
|
||||
CheckDefFailure(["var x = #{a : 8}"], 'E1068:', 1)
|
||||
CheckDefFailure(["var x = #{a :8}"], 'E1068:', 1)
|
||||
CheckDefFailure(["var x = #{a: 8 , b: 9}"], 'E1068:', 1)
|
||||
CheckDefFailure(["var x = #{a: 1,b: 2}"], 'E1069:', 1)
|
||||
# legacy syntax doesn't work
|
||||
CheckDefFailure(["var x = #{key: 8}"], 'E1097:', 2)
|
||||
CheckDefFailure(["var x = {'key': 8}"], 'E1014:', 1)
|
||||
CheckDefFailure(["var x = 'a' .. #{a: 1}"], 'E1097:', 2)
|
||||
|
||||
CheckDefFailure(["var x = #{8: 8}"], 'E1014:', 1)
|
||||
CheckDefFailure(["var x = #{xxx}"], 'E720:', 1)
|
||||
CheckDefFailure(["var x = #{xxx: 1", "var y = 2"], 'E722:', 2)
|
||||
CheckDefFailure(["var x = #{xxx: 1,"], 'E723:', 2)
|
||||
CheckDefFailure(["var x = {'a': xxx}"], 'E1001:', 1)
|
||||
CheckDefFailure(["var x = {xx-x: 8}"], 'E1001:', 1)
|
||||
CheckDefFailure(["var x = #{a: 1, a: 2}"], 'E721:', 1)
|
||||
CheckDefFailure(["var x = {a:8}"], 'E1069:', 1)
|
||||
CheckDefFailure(["var x = {a : 8}"], 'E1059:', 1)
|
||||
CheckDefFailure(["var x = {a :8}"], 'E1059:', 1)
|
||||
CheckDefFailure(["var x = {a: 8 , b: 9}"], 'E1068:', 1)
|
||||
CheckDefFailure(["var x = {a: 1,b: 2}"], 'E1069:', 1)
|
||||
|
||||
CheckDefFailure(["var x = {xxx}"], 'E720:', 1)
|
||||
CheckDefFailure(["var x = {xxx: 1", "var y = 2"], 'E722:', 2)
|
||||
CheckDefFailure(["var x = {xxx: 1,"], 'E723:', 2)
|
||||
CheckDefFailure(["var x = {['a']: xxx}"], 'E1001:', 1)
|
||||
CheckDefFailure(["var x = {a: 1, a: 2}"], 'E721:', 1)
|
||||
CheckDefExecFailure(["var x = g:anint.member"], 'E715:', 1)
|
||||
CheckDefExecFailure(["var x = g:dict_empty.member"], 'E716:', 1)
|
||||
|
||||
CheckDefExecFailure(['var x: dict<number> = #{a: 234, b: "1"}'], 'E1012:', 1)
|
||||
CheckDefExecFailure(['var x: dict<number> = #{a: "x", b: 134}'], 'E1012:', 1)
|
||||
CheckDefExecFailure(['var x: dict<string> = #{a: 234, b: "1"}'], 'E1012:', 1)
|
||||
CheckDefExecFailure(['var x: dict<string> = #{a: "x", b: 134}'], 'E1012:', 1)
|
||||
CheckDefExecFailure(['var x: dict<number> = {a: 234, b: "1"}'], 'E1012:', 1)
|
||||
CheckDefExecFailure(['var x: dict<number> = {a: "x", b: 134}'], 'E1012:', 1)
|
||||
CheckDefExecFailure(['var x: dict<string> = {a: 234, b: "1"}'], 'E1012:', 1)
|
||||
CheckDefExecFailure(['var x: dict<string> = {a: "x", b: 134}'], 'E1012:', 1)
|
||||
|
||||
CheckDefFailure(['var x = ({'], 'E723:', 2)
|
||||
CheckDefExecFailure(['{}[getftype("")]'], 'E716: Key not present in Dictionary: ""', 1)
|
||||
@ -1956,89 +1965,89 @@ def Test_expr7_dict_vim9script()
|
||||
var lines =<< trim END
|
||||
vim9script
|
||||
var d = {
|
||||
'one':
|
||||
['one']:
|
||||
1,
|
||||
'two': 2,
|
||||
['two']: 2,
|
||||
}
|
||||
assert_equal({'one': 1, 'two': 2}, d)
|
||||
assert_equal({one: 1, two: 2}, d)
|
||||
|
||||
d = { # comment
|
||||
'one':
|
||||
['one']:
|
||||
# comment
|
||||
|
||||
1,
|
||||
# comment
|
||||
# comment
|
||||
'two': 2,
|
||||
['two']: 2,
|
||||
}
|
||||
assert_equal({'one': 1, 'two': 2}, d)
|
||||
assert_equal({one: 1, two: 2}, d)
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
var d = { "one": "one", "two": "two", }
|
||||
assert_equal({'one': 'one', 'two': 'two'}, d)
|
||||
var d = { ["one"]: "one", ["two"]: "two", }
|
||||
assert_equal({one: 'one', two: 'two'}, d)
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
var d = #{one: 1,
|
||||
var d = {one: 1,
|
||||
two: 2,
|
||||
}
|
||||
assert_equal({'one': 1, 'two': 2}, d)
|
||||
assert_equal({one: 1, two: 2}, d)
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
var d = #{one:1, two: 2}
|
||||
var d = {one:1, two: 2}
|
||||
END
|
||||
CheckScriptFailure(lines, 'E1069:', 2)
|
||||
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
var d = #{one: 1,two: 2}
|
||||
var d = {one: 1,two: 2}
|
||||
END
|
||||
CheckScriptFailure(lines, 'E1069:', 2)
|
||||
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
var d = #{one : 1}
|
||||
var d = {one : 1}
|
||||
END
|
||||
CheckScriptFailure(lines, 'E1068:', 2)
|
||||
CheckScriptFailure(lines, 'E1059:', 2)
|
||||
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
var d = #{one:1}
|
||||
var d = {one:1}
|
||||
END
|
||||
CheckScriptFailure(lines, 'E1069:', 2)
|
||||
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
var d = #{one: 1 , two: 2}
|
||||
var d = {one: 1 , two: 2}
|
||||
END
|
||||
CheckScriptFailure(lines, 'E1068:', 2)
|
||||
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
var l: dict<number> = #{a: 234, b: 'x'}
|
||||
var l: dict<number> = {a: 234, b: 'x'}
|
||||
END
|
||||
CheckScriptFailure(lines, 'E1012:', 2)
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
var l: dict<number> = #{a: 'x', b: 234}
|
||||
var l: dict<number> = {a: 'x', b: 234}
|
||||
END
|
||||
CheckScriptFailure(lines, 'E1012:', 2)
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
var l: dict<string> = #{a: 'x', b: 234}
|
||||
var l: dict<string> = {a: 'x', b: 234}
|
||||
END
|
||||
CheckScriptFailure(lines, 'E1012:', 2)
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
var l: dict<string> = #{a: 234, b: 'x'}
|
||||
var l: dict<string> = {a: 234, b: 'x'}
|
||||
END
|
||||
CheckScriptFailure(lines, 'E1012:', 2)
|
||||
|
||||
@ -2047,7 +2056,7 @@ def Test_expr7_dict_vim9script()
|
||||
def Failing()
|
||||
job_stop()
|
||||
enddef
|
||||
var dict = #{name: Failing}
|
||||
var dict = {name: Failing}
|
||||
END
|
||||
if has('channel')
|
||||
CheckScriptFailure(lines, 'E119:', 1)
|
||||
@ -2067,15 +2076,15 @@ def Test_expr_member()
|
||||
])
|
||||
assert_equal(1, d
|
||||
.one)
|
||||
d = {'1': 1, '_': 2}
|
||||
d = {1: 1, _: 2}
|
||||
assert_equal(1, d
|
||||
.1)
|
||||
assert_equal(2, d
|
||||
._)
|
||||
|
||||
# getting the one member should clear the dict after getting the item
|
||||
assert_equal('one', #{one: 'one'}.one)
|
||||
assert_equal('one', #{one: 'one'}[g:oneString])
|
||||
assert_equal('one', {one: 'one'}.one)
|
||||
assert_equal('one', {one: 'one'}[g:oneString])
|
||||
|
||||
CheckDefFailure(["var x = g:dict_one.#$!"], 'E1002:', 1)
|
||||
CheckDefExecFailure(["var d: dict<any>", "echo d['a']"], 'E716:', 2)
|
||||
@ -2141,7 +2150,7 @@ def Test_expr7_any_index_slice()
|
||||
assert_equal([], g:testlist[1:-4])
|
||||
assert_equal([], g:testlist[1:-9])
|
||||
|
||||
g:testdict = #{a: 1, b: 2}
|
||||
g:testdict = {a: 1, b: 2}
|
||||
assert_equal(1, g:testdict['a'])
|
||||
assert_equal(2, g:testdict['b'])
|
||||
END
|
||||
@ -2172,7 +2181,7 @@ enddef
|
||||
def Test_expr_member_vim9script()
|
||||
var lines =<< trim END
|
||||
vim9script
|
||||
var d = #{one:
|
||||
var d = {one:
|
||||
'one',
|
||||
two: 'two',
|
||||
1: 1,
|
||||
@ -2406,7 +2415,7 @@ def Test_expr7_not()
|
||||
|
||||
assert_equal(true, !test_null_dict())
|
||||
assert_equal(true, !{})
|
||||
assert_equal(false, !{'yes': 'no'})
|
||||
assert_equal(false, !{yes: 'no'})
|
||||
|
||||
if has('channel')
|
||||
assert_equal(true, !test_null_job())
|
||||
@ -2433,7 +2442,7 @@ func Test_expr7_fails()
|
||||
call CheckDefFailure(["var x = +'xx'"], "E1030:", 1)
|
||||
call CheckDefFailure(["var x = -0z12"], "E974:", 1)
|
||||
call CheckDefExecFailure(["var x = -[8]"], "E39:", 1)
|
||||
call CheckDefExecFailure(["var x = -{'a': 1}"], "E39:", 1)
|
||||
call CheckDefExecFailure(["var x = -{a: 1}"], "E39:", 1)
|
||||
|
||||
call CheckDefFailure(["var x = @"], "E1002:", 1)
|
||||
call CheckDefFailure(["var x = @<"], "E354:", 1)
|
||||
@ -2464,8 +2473,8 @@ func Test_expr7_fails()
|
||||
call CheckDefFailure(["'yes'->", "Echo()"], 'E488: Trailing characters: ->', 1)
|
||||
|
||||
call CheckDefExecFailure(["[1, 2->len()"], 'E697:', 2)
|
||||
call CheckDefExecFailure(["#{a: 1->len()"], 'E722:', 1)
|
||||
call CheckDefExecFailure(["{'a': 1->len()"], 'E723:', 2)
|
||||
call CheckDefExecFailure(["{a: 1->len()"], 'E451:', 1)
|
||||
call CheckDefExecFailure(["{['a']: 1->len()"], 'E723:', 2)
|
||||
endfunc
|
||||
|
||||
let g:Funcrefs = [function('add')]
|
||||
@ -2507,7 +2516,7 @@ def Test_expr7_trailing()
|
||||
assert_equal([2, 5, 8], l)
|
||||
|
||||
# dict member
|
||||
var d = #{key: 123}
|
||||
var d = {key: 123}
|
||||
assert_equal(123, d.key)
|
||||
enddef
|
||||
|
||||
@ -2594,7 +2603,7 @@ enddef
|
||||
def Test_expr7_dict_subscript()
|
||||
var lines =<< trim END
|
||||
vim9script
|
||||
var l = [#{lnum: 2}, #{lnum: 1}]
|
||||
var l = [{lnum: 2}, {lnum: 1}]
|
||||
var res = l[0].lnum > l[1].lnum
|
||||
assert_true(res)
|
||||
END
|
||||
@ -2629,7 +2638,7 @@ def Test_expr7_subscript_linebreak()
|
||||
assert_equal('1', l[
|
||||
1])
|
||||
|
||||
var d = #{one: 33}
|
||||
var d = {one: 33}
|
||||
assert_equal(33, d.
|
||||
one)
|
||||
enddef
|
||||
@ -2643,9 +2652,9 @@ def Test_expr7_method_call()
|
||||
bwipe!
|
||||
|
||||
var bufnr = bufnr()
|
||||
var loclist = [#{bufnr: bufnr, lnum: 42, col: 17, text: 'wrong'}]
|
||||
var loclist = [{bufnr: bufnr, lnum: 42, col: 17, text: 'wrong'}]
|
||||
loclist->setloclist(0)
|
||||
assert_equal([#{bufnr: bufnr,
|
||||
assert_equal([{bufnr: bufnr,
|
||||
lnum: 42,
|
||||
col: 17,
|
||||
text: 'wrong',
|
||||
@ -2657,7 +2666,7 @@ def Test_expr7_method_call()
|
||||
module: ''}
|
||||
], getloclist(0))
|
||||
|
||||
var result: bool = get(#{n: 0}, 'n', 0)
|
||||
var result: bool = get({n: 0}, 'n', 0)
|
||||
assert_equal(false, result)
|
||||
enddef
|
||||
|
||||
|
@ -30,7 +30,7 @@ def TestCompilingError()
|
||||
END
|
||||
call writefile(lines, 'XTest_compile_error')
|
||||
var buf = RunVimInTerminal('-S XTest_compile_error',
|
||||
#{rows: 10, wait_for_ruler: 0})
|
||||
{rows: 10, wait_for_ruler: 0})
|
||||
var text = ''
|
||||
for loop in range(100)
|
||||
text = ''
|
||||
@ -838,16 +838,16 @@ def Test_vim9script_call()
|
||||
def DictFunc(arg: dict<number>)
|
||||
dictvar = arg
|
||||
enddef
|
||||
{'a': 1, 'b': 2}->DictFunc()
|
||||
dictvar->assert_equal(#{a: 1, b: 2})
|
||||
{a: 1, b: 2}->DictFunc()
|
||||
dictvar->assert_equal({a: 1, b: 2})
|
||||
def CompiledDict()
|
||||
{'a': 3, 'b': 4}->DictFunc()
|
||||
{a: 3, b: 4}->DictFunc()
|
||||
enddef
|
||||
CompiledDict()
|
||||
dictvar->assert_equal(#{a: 3, b: 4})
|
||||
dictvar->assert_equal({a: 3, b: 4})
|
||||
|
||||
#{a: 3, b: 4}->DictFunc()
|
||||
dictvar->assert_equal(#{a: 3, b: 4})
|
||||
{a: 3, b: 4}->DictFunc()
|
||||
dictvar->assert_equal({a: 3, b: 4})
|
||||
|
||||
('text')->MyFunc()
|
||||
name->assert_equal('text')
|
||||
@ -1272,7 +1272,7 @@ def Test_error_reporting()
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
def Func()
|
||||
var db = #{foo: 1, bar: 2}
|
||||
var db = {foo: 1, bar: 2}
|
||||
# comment
|
||||
var x = db.asdf
|
||||
enddef
|
||||
@ -1607,7 +1607,7 @@ def Test_ignore_silent_error_in_filter()
|
||||
return popup_filter_menu(winid, key)
|
||||
enddef
|
||||
|
||||
popup_create('popup', #{filter: Filter})
|
||||
popup_create('popup', {filter: Filter})
|
||||
feedkeys("o\r", 'xnt')
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
@ -1639,7 +1639,7 @@ def Test_closure_in_map()
|
||||
writefile(['222'], 'XclosureDir/file2')
|
||||
writefile(['333'], 'XclosureDir/tdir/file3')
|
||||
|
||||
TreeWalk('XclosureDir')->assert_equal(['file1', 'file2', {'tdir': ['file3']}])
|
||||
TreeWalk('XclosureDir')->assert_equal(['file1', 'file2', {tdir: ['file3']}])
|
||||
|
||||
delete('XclosureDir', 'rf')
|
||||
enddef
|
||||
@ -1672,20 +1672,20 @@ enddef
|
||||
|
||||
def Test_partial_call()
|
||||
var Xsetlist = function('setloclist', [0])
|
||||
Xsetlist([], ' ', {'title': 'test'})
|
||||
getloclist(0, {'title': 1})->assert_equal({'title': 'test'})
|
||||
Xsetlist([], ' ', {title: 'test'})
|
||||
getloclist(0, {title: 1})->assert_equal({title: 'test'})
|
||||
|
||||
Xsetlist = function('setloclist', [0, [], ' '])
|
||||
Xsetlist({'title': 'test'})
|
||||
getloclist(0, {'title': 1})->assert_equal({'title': 'test'})
|
||||
Xsetlist({title: 'test'})
|
||||
getloclist(0, {title: 1})->assert_equal({title: 'test'})
|
||||
|
||||
Xsetlist = function('setqflist')
|
||||
Xsetlist([], ' ', {'title': 'test'})
|
||||
getqflist({'title': 1})->assert_equal({'title': 'test'})
|
||||
Xsetlist([], ' ', {title: 'test'})
|
||||
getqflist({title: 1})->assert_equal({title: 'test'})
|
||||
|
||||
Xsetlist = function('setqflist', [[], ' '])
|
||||
Xsetlist({'title': 'test'})
|
||||
getqflist({'title': 1})->assert_equal({'title': 'test'})
|
||||
Xsetlist({title: 'test'})
|
||||
getqflist({title: 1})->assert_equal({title: 'test'})
|
||||
|
||||
var Len: func: number = function('len', ['word'])
|
||||
assert_equal(4, Len())
|
||||
|
@ -177,14 +177,14 @@ def Test_const()
|
||||
cl[1] = 88
|
||||
constlist->assert_equal([1, [77, 88], 3])
|
||||
|
||||
var vardict = #{five: 5, six: 6}
|
||||
const constdict = #{one: 1, two: vardict, three: 3}
|
||||
var vardict = {five: 5, six: 6}
|
||||
const constdict = {one: 1, two: vardict, three: 3}
|
||||
vardict['five'] = 55
|
||||
# TODO: does not work yet
|
||||
# constdict['two']['six'] = 66
|
||||
var cd = constdict['two']
|
||||
cd['six'] = 66
|
||||
constdict->assert_equal(#{one: 1, two: #{five: 55, six: 66}, three: 3})
|
||||
constdict->assert_equal({one: 1, two: {five: 55, six: 66}, three: 3})
|
||||
END
|
||||
CheckDefAndScriptSuccess(lines)
|
||||
enddef
|
||||
@ -212,14 +212,14 @@ def Test_const_bang()
|
||||
CheckScriptFailure(['vim9script'] + lines, 'E684:', 3)
|
||||
|
||||
lines =<< trim END
|
||||
const dd = #{one: 1, two: 2}
|
||||
const dd = {one: 1, two: 2}
|
||||
dd["one"] = 99
|
||||
END
|
||||
CheckDefExecFailure(lines, 'E1121:', 2)
|
||||
CheckScriptFailure(['vim9script'] + lines, 'E741:', 3)
|
||||
|
||||
lines =<< trim END
|
||||
const dd = #{one: 1, two: 2}
|
||||
const dd = {one: 1, two: 2}
|
||||
dd["three"] = 99
|
||||
END
|
||||
CheckDefExecFailure(lines, 'E1120:')
|
||||
@ -385,7 +385,7 @@ def Test_try_catch()
|
||||
endtry
|
||||
assert_equal(121, n)
|
||||
|
||||
var d = #{one: 1}
|
||||
var d = {one: 1}
|
||||
try
|
||||
n = d[g:astring]
|
||||
catch /E716:/
|
||||
@ -775,7 +775,7 @@ def Test_vim9_import_export()
|
||||
g:imported_func = Exported()
|
||||
|
||||
def GetExported(): string
|
||||
var local_dict = #{ref: Exported}
|
||||
var local_dict = {ref: Exported}
|
||||
return local_dict.ref()
|
||||
enddef
|
||||
g:funcref_result = GetExported()
|
||||
@ -1133,7 +1133,7 @@ def Run_Test_import_fails_on_command_line()
|
||||
END
|
||||
writefile(export, 'XexportCmd.vim')
|
||||
|
||||
var buf = RunVimInTerminal('-c "import Foo from ''./XexportCmd.vim''"', #{
|
||||
var buf = RunVimInTerminal('-c "import Foo from ''./XexportCmd.vim''"', {
|
||||
rows: 6, wait_for_ruler: 0})
|
||||
WaitForAssert({-> assert_match('^E1094:', term_getline(buf, 5))})
|
||||
|
||||
@ -1733,7 +1733,7 @@ def Test_execute_cmd()
|
||||
execute 'echomsg' (n ? '"true"' : '"no"')
|
||||
assert_match('^true$', Screenline(&lines))
|
||||
|
||||
echomsg [1, 2, 3] #{a: 1, b: 2}
|
||||
echomsg [1, 2, 3] {a: 1, b: 2}
|
||||
assert_match('^\[1, 2, 3\] {''a'': 1, ''b'': 2}$', Screenline(&lines))
|
||||
|
||||
CheckDefFailure(['execute xxx'], 'E1001:', 1)
|
||||
@ -2024,26 +2024,26 @@ def Test_automatic_line_continuation()
|
||||
assert_equal(['one', 'two', 'three'], mylist)
|
||||
|
||||
var mydict = {
|
||||
'one': 1,
|
||||
'two': 2,
|
||||
'three':
|
||||
['one']: 1,
|
||||
['two']: 2,
|
||||
['three']:
|
||||
3,
|
||||
} # comment
|
||||
assert_equal({'one': 1, 'two': 2, 'three': 3}, mydict)
|
||||
mydict = #{
|
||||
assert_equal({one: 1, two: 2, three: 3}, mydict)
|
||||
mydict = {
|
||||
one: 1, # comment
|
||||
two: # comment
|
||||
2, # comment
|
||||
three: 3 # comment
|
||||
}
|
||||
assert_equal(#{one: 1, two: 2, three: 3}, mydict)
|
||||
mydict = #{
|
||||
assert_equal({one: 1, two: 2, three: 3}, mydict)
|
||||
mydict = {
|
||||
one: 1,
|
||||
two:
|
||||
2,
|
||||
three: 3
|
||||
}
|
||||
assert_equal(#{one: 1, two: 2, three: 3}, mydict)
|
||||
assert_equal({one: 1, two: 2, three: 3}, mydict)
|
||||
|
||||
assert_equal(
|
||||
['one', 'two', 'three'],
|
||||
@ -2864,7 +2864,7 @@ def Run_Test_define_func_at_command_line()
|
||||
END
|
||||
writefile([''], 'Xdidcmd')
|
||||
writefile(lines, 'XcallFunc')
|
||||
var buf = RunVimInTerminal('-S XcallFunc', #{rows: 6})
|
||||
var buf = RunVimInTerminal('-S XcallFunc', {rows: 6})
|
||||
# define Afunc() on the command line
|
||||
term_sendkeys(buf, ":def Afunc()\<CR>Bfunc()\<CR>enddef\<CR>")
|
||||
term_sendkeys(buf, ":call CheckAndQuit()\<CR>")
|
||||
@ -2959,7 +2959,7 @@ def Test_catch_exception_in_callback()
|
||||
g:caught = 'yes'
|
||||
endtry
|
||||
enddef
|
||||
popup_menu('popup', #{callback: Callback})
|
||||
popup_menu('popup', {callback: Callback})
|
||||
feedkeys("\r", 'xt')
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
@ -2981,7 +2981,7 @@ def Test_no_unknown_error_after_error()
|
||||
sleep 1m
|
||||
source += l
|
||||
enddef
|
||||
var myjob = job_start('echo burp', #{out_cb: Out_cb, exit_cb: Exit_cb, mode: 'raw'})
|
||||
var myjob = job_start('echo burp', {out_cb: Out_cb, exit_cb: Exit_cb, mode: 'raw'})
|
||||
sleep 100m
|
||||
END
|
||||
writefile(lines, 'Xdef')
|
||||
|
@ -750,6 +750,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
2082,
|
||||
/**/
|
||||
2081,
|
||||
/**/
|
||||
|
@ -2127,12 +2127,12 @@ free_imported(cctx_T *cctx)
|
||||
}
|
||||
|
||||
/*
|
||||
* Return TRUE if "p" points at a "#" but not at "#{".
|
||||
* Return TRUE if "p" points at a "#". Does not check for white space.
|
||||
*/
|
||||
int
|
||||
vim9_comment_start(char_u *p)
|
||||
{
|
||||
return p[0] == '#' && p[1] != '{';
|
||||
return p[0] == '#';
|
||||
}
|
||||
|
||||
/*
|
||||
@ -2840,14 +2840,6 @@ to_name_const_end(char_u *arg)
|
||||
if (eval_list(&p, &rettv, NULL, FALSE) == FAIL)
|
||||
p = arg;
|
||||
}
|
||||
else if (p == arg && *arg == '#' && arg[1] == '{')
|
||||
{
|
||||
// Can be "#{a: 1}->Func()".
|
||||
++p;
|
||||
if (eval_dict(&p, &rettv, NULL, TRUE) == FAIL)
|
||||
p = arg;
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
@ -2999,12 +2991,12 @@ compile_lambda_call(char_u **arg, cctx_T *cctx)
|
||||
}
|
||||
|
||||
/*
|
||||
* parse a dict: {'key': val} or #{key: val}
|
||||
* parse a dict: {key: val, [key]: val}
|
||||
* "*arg" points to the '{'.
|
||||
* ppconst->pp_is_const is set if all item values are a constant.
|
||||
*/
|
||||
static int
|
||||
compile_dict(char_u **arg, cctx_T *cctx, int literal, ppconst_T *ppconst)
|
||||
compile_dict(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
|
||||
{
|
||||
garray_T *instr = &cctx->ctx_instr;
|
||||
garray_T *stack = &cctx->ctx_type_stack;
|
||||
@ -3022,7 +3014,6 @@ compile_dict(char_u **arg, cctx_T *cctx, int literal, ppconst_T *ppconst)
|
||||
for (;;)
|
||||
{
|
||||
char_u *key = NULL;
|
||||
char_u *end;
|
||||
|
||||
if (may_get_next_line(whitep, arg, cctx) == FAIL)
|
||||
{
|
||||
@ -3033,14 +3024,12 @@ compile_dict(char_u **arg, cctx_T *cctx, int literal, ppconst_T *ppconst)
|
||||
if (**arg == '}')
|
||||
break;
|
||||
|
||||
// Eventually {name: value} will use "name" as a literal key and
|
||||
// {[expr]: value} for an evaluated key.
|
||||
// Temporarily: if "name" is indeed a valid key, or "[expr]" is
|
||||
// used, use the new method, like JavaScript. Otherwise fall back
|
||||
// to the old method.
|
||||
end = to_name_end(*arg, FALSE);
|
||||
if (literal || *end == ':')
|
||||
// {name: value} uses "name" as a literal key and
|
||||
// {[expr]: value} uses an evaluated key.
|
||||
if (**arg != '[')
|
||||
{
|
||||
char_u *end = skip_literal_key(*arg);
|
||||
|
||||
if (end == *arg)
|
||||
{
|
||||
semsg(_(e_invalid_key_str), *arg);
|
||||
@ -3054,10 +3043,8 @@ compile_dict(char_u **arg, cctx_T *cctx, int literal, ppconst_T *ppconst)
|
||||
else
|
||||
{
|
||||
isn_T *isn;
|
||||
int has_bracket = **arg == '[';
|
||||
|
||||
if (has_bracket)
|
||||
*arg = skipwhite(*arg + 1);
|
||||
*arg = skipwhite(*arg + 1);
|
||||
if (compile_expr0(arg, cctx) == FAIL)
|
||||
return FAIL;
|
||||
isn = ((isn_T *)instr->ga_data) + instr->ga_len - 1;
|
||||
@ -3071,16 +3058,13 @@ compile_dict(char_u **arg, cctx_T *cctx, int literal, ppconst_T *ppconst)
|
||||
FALSE, FALSE) == FAIL)
|
||||
return FAIL;
|
||||
}
|
||||
if (has_bracket)
|
||||
*arg = skipwhite(*arg);
|
||||
if (**arg != ']')
|
||||
{
|
||||
*arg = skipwhite(*arg);
|
||||
if (**arg != ']')
|
||||
{
|
||||
emsg(_(e_missing_matching_bracket_after_dict_key));
|
||||
return FAIL;
|
||||
}
|
||||
++*arg;
|
||||
emsg(_(e_missing_matching_bracket_after_dict_key));
|
||||
return FAIL;
|
||||
}
|
||||
++*arg;
|
||||
}
|
||||
|
||||
// Check for duplicate keys, if using string keys.
|
||||
@ -3766,8 +3750,7 @@ compile_subscript(
|
||||
* $VAR environment variable
|
||||
* (expression) nested expression
|
||||
* [expr, expr] List
|
||||
* {key: val, key: val} Dictionary
|
||||
* #{key: val, key: val} Dictionary with literal keys
|
||||
* {key: val, [key]: val} Dictionary
|
||||
*
|
||||
* Also handle:
|
||||
* ! in front logical NOT
|
||||
@ -3883,18 +3866,6 @@ compile_expr7(
|
||||
case '[': ret = compile_list(arg, cctx, ppconst);
|
||||
break;
|
||||
|
||||
/*
|
||||
* Dictionary: #{key: val, key: val}
|
||||
*/
|
||||
case '#': if ((*arg)[1] == '{')
|
||||
{
|
||||
++*arg;
|
||||
ret = compile_dict(arg, cctx, TRUE, ppconst);
|
||||
}
|
||||
else
|
||||
ret = NOTDONE;
|
||||
break;
|
||||
|
||||
/*
|
||||
* Lambda: {arg, arg -> expr}
|
||||
* Dictionary: {'key': val, 'key': val}
|
||||
@ -3910,7 +3881,7 @@ compile_expr7(
|
||||
if (ret != FAIL && *start == '>')
|
||||
ret = compile_lambda(arg, cctx);
|
||||
else
|
||||
ret = compile_dict(arg, cctx, FALSE, ppconst);
|
||||
ret = compile_dict(arg, cctx, ppconst);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -4200,7 +4171,7 @@ compile_expr5(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
|
||||
}
|
||||
|
||||
*arg = skipwhite(op + oplen);
|
||||
if (may_get_next_line(op + oplen, arg, cctx) == FAIL)
|
||||
if (may_get_next_line_error(op + oplen, arg, cctx) == FAIL)
|
||||
return FAIL;
|
||||
|
||||
// get the second expression
|
||||
@ -7484,13 +7455,9 @@ compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx)
|
||||
switch (*ea.cmd)
|
||||
{
|
||||
case '#':
|
||||
// "#" starts a comment, but "#{" does not.
|
||||
if (ea.cmd[1] != '{')
|
||||
{
|
||||
line = (char_u *)"";
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
// "#" starts a comment
|
||||
line = (char_u *)"";
|
||||
continue;
|
||||
|
||||
case '}':
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user