diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-12-02 17:36:54 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-12-02 17:36:54 +0100 |
commit | e0de171ecd2ff7acd56deda2cf81f0d13a69c803 (patch) | |
tree | 87667e0ae5a5517461d7f4e59514d9495170a05a /src | |
parent | 7f76494aac512b1d603d9be4132184241f43872c (diff) |
patch 8.2.2082: Vim9: can still use the depricated #{} dict syntaxv8.2.2082
Problem: Vim9: can still use the depricated #{} dict syntax.
Solution: Remove support for #{} in Vim9 script. (closes #7406, closes #7405)
Diffstat (limited to 'src')
-rw-r--r-- | src/dict.c | 27 | ||||
-rw-r--r-- | src/eval.c | 2 | ||||
-rw-r--r-- | src/proto/dict.pro | 1 | ||||
-rw-r--r-- | src/testdir/test_popupwin.vim | 4 | ||||
-rw-r--r-- | src/testdir/test_textprop.vim | 12 | ||||
-rw-r--r-- | src/testdir/test_vim9_assign.vim | 56 | ||||
-rw-r--r-- | src/testdir/test_vim9_builtin.vim | 44 | ||||
-rw-r--r-- | src/testdir/test_vim9_cmd.vim | 14 | ||||
-rw-r--r-- | src/testdir/test_vim9_disassemble.vim | 18 | ||||
-rw-r--r-- | src/testdir/test_vim9_expr.vim | 201 | ||||
-rw-r--r-- | src/testdir/test_vim9_func.vim | 36 | ||||
-rw-r--r-- | src/testdir/test_vim9_script.vim | 40 | ||||
-rw-r--r-- | src/version.c | 2 | ||||
-rw-r--r-- | src/vim9compile.c | 75 |
14 files changed, 260 insertions, 272 deletions
diff --git a/src/dict.c b/src/dict.c index 3b965d0ac2..819f5fa0ba 100644 --- a/src/dict.c +++ b/src/dict.c @@ -783,19 +783,30 @@ dict2string(typval_T *tv, int copyID, int restore_copyID) } /* + * 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. */ 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! diff --git a/src/eval.c b/src/eval.c index 199dc9c0a6..223251090d 100644 --- a/src/eval.c +++ b/src/eval.c @@ -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); diff --git a/src/proto/dict.pro b/src/proto/dict.pro index 3b6638440d..0ba83657d9 100644 --- a/src/proto/dict.pro +++ b/src/proto/dict.pro @@ -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); diff --git a/src/testdir/test_popupwin.vim b/src/testdir/test_popupwin.vim index 42542a35c3..50d4715e7b 100644 --- a/src/testdir/test_popupwin.vim +++ b/src/testdir/test_popupwin.vim @@ -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) diff --git a/src/testdir/test_textprop.vim b/src/testdir/test_textprop.vim index b459413bd3..0720567590 100644 --- a/src/testdir/test_textprop.vim +++ b/src/testdir/test_textprop.vim @@ -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 diff --git a/src/testdir/test_vim9_assign.vim b/src/testdir/test_vim9_assign.vim index 1d8a86f115..635b4be5a4 100644 --- a/src/testdir/test_vim9_assign.vim +++ b/src/testdir/test_vim9_assign.vim @@ -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 diff --git a/src/testdir/test_vim9_builtin.vim b/src/testdir/test_vim9_builtin.vim index 312973435a..301b270e69 100644 --- a/src/testdir/test_vim9_builtin.vim +++ b/src/testdir/test_vim9_builtin.vim @@ -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 diff --git a/src/testdir/test_vim9_cmd.vim b/src/testdir/test_vim9_cmd.vim index d0f9872caa..162d79508d 100644 --- a/src/testdir/test_vim9_cmd.vim +++ b/src/testdir/test_vim9_cmd.vim @@ -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() diff --git a/src/testdir/test_vim9_disassemble.vim b/src/testdir/test_vim9_disassemble.vim index ba230a2a57..e7445d3860 100644 --- a/src/testdir/test_vim9_disassemble.vim +++ b/src/testdir/test_vim9_disassemble.vim @@ -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' diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim index d93751e623..4d0535130d 100644 --- a/src/testdir/test_vim9_expr.vim +++ b/src/testdir/test_vim9_expr.vim @@ -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) - - 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) + # 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 = {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 CheckScriptFa |