Mercurial > vim
comparison src/testdir/test_vim9_assign.vim @ 27762:3196066c5795 v8.2.4407
patch 8.2.4407: Vim9: some code not covered by tests
Commit: https://github.com/vim/vim/commit/e08be09a08485e8c919f46c05223c1ccfdaf175d
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Feb 17 13:08:26 2022 +0000
patch 8.2.4407: Vim9: some code not covered by tests
Problem: Vim9: some code not covered by tests.
Solution: Add more tests. Avoid giving two errors. Remove dead code.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 17 Feb 2022 14:15:04 +0100 |
parents | d754ac2f5ac5 |
children | 1662d2d2e27b |
comparison
equal
deleted
inserted
replaced
27761:a5c8bf8758c7 | 27762:3196066c5795 |
---|---|
541 d3.one = {} | 541 d3.one = {} |
542 d3.one.two = {} | 542 d3.one.two = {} |
543 d3.one.two.three = 123 | 543 d3.one.two.three = 123 |
544 assert_equal({one: {two: {three: 123}}}, d3) | 544 assert_equal({one: {two: {three: 123}}}, d3) |
545 | 545 |
546 # blob | |
547 var bl: blob = 0z11223344 | |
548 bl[0] = 0x77 | |
549 assert_equal(0z77223344, bl) | |
550 bl[-2] = 0x66 | |
551 assert_equal(0z77226644, bl) | |
552 | |
546 # should not read the next line when generating "a.b" | 553 # should not read the next line when generating "a.b" |
547 var a = {} | 554 var a = {} |
548 a.b = {} | 555 a.b = {} |
549 a.b.c = {} | 556 a.b.c = {} |
550 ->copy() | 557 ->copy() |
589 lines =<< trim END | 596 lines =<< trim END |
590 var dl: dict<list<number>> | 597 var dl: dict<list<number>> |
591 dl.one = {} | 598 dl.one = {} |
592 END | 599 END |
593 v9.CheckDefFailure(lines, 'E1012: Type mismatch; expected list<number> but got dict<unknown>', 2) | 600 v9.CheckDefFailure(lines, 'E1012: Type mismatch; expected list<number> but got dict<unknown>', 2) |
601 | |
602 lines =<< trim END | |
603 g:l = [1, 2] | |
604 g:l['x'] = 3 | |
605 END | |
606 v9.CheckDefExecAndScriptFailure(lines, ['E39:', 'E1030:'], 2) | |
607 | |
608 lines =<< trim END | |
609 var bl: blob = test_null_blob() | |
610 bl[1] = 8 | |
611 END | |
612 v9.CheckDefExecAndScriptFailure(lines, ['E1184:', 'E979:'], 2) | |
594 enddef | 613 enddef |
595 | 614 |
596 def Test_init_in_for_loop() | 615 def Test_init_in_for_loop() |
597 var lines =<< trim END | 616 var lines =<< trim END |
598 var l: list<number> = [] | 617 var l: list<number> = [] |
1199 | 1218 |
1200 var nr = 1234 | nr = 5678 | 1219 var nr = 1234 | nr = 5678 |
1201 assert_equal(5678, nr) | 1220 assert_equal(5678, nr) |
1202 enddef | 1221 enddef |
1203 | 1222 |
1223 def Test_script_var_default() | |
1224 var lines =<< trim END | |
1225 vim9script | |
1226 var l: list<number> | |
1227 var bl: blob | |
1228 var d: dict<number> | |
1229 def Echo() | |
1230 assert_equal([], l) | |
1231 assert_equal(0z, bl) | |
1232 assert_equal({}, d) | |
1233 enddef | |
1234 END | |
1235 v9.CheckScriptSuccess(lines) | |
1236 enddef | |
1237 | |
1204 let s:scriptvar = 'init' | 1238 let s:scriptvar = 'init' |
1205 | 1239 |
1206 def Test_assignment_var_list() | 1240 def Test_assignment_var_list() |
1207 var lines =<< trim END | 1241 var lines =<< trim END |
1208 var v1: string | 1242 var v1: string |
2080 ], 'E1004:', 2) | 2114 ], 'E1004:', 2) |
2081 v9.CheckDefFailure([ | 2115 v9.CheckDefFailure([ |
2082 'var ll = [1, 2]', | 2116 'var ll = [1, 2]', |
2083 'unlet ll[0: 1]', | 2117 'unlet ll[0: 1]', |
2084 ], 'E1004:', 2) | 2118 ], 'E1004:', 2) |
2119 | |
2120 v9.CheckDefExecFailure([ | |
2121 'g:ll = [1, 2]', | |
2122 'g:idx = "x"', | |
2123 'unlet g:ll[g:idx]', | |
2124 ], 'E1029: Expected number but got string', 3) | |
2125 | |
2126 v9.CheckDefExecFailure([ | |
2127 'g:ll = [1, 2, 3]', | |
2128 'g:idx = "x"', | |
2129 'unlet g:ll[g:idx : 2]', | |
2130 ], 'E1029: Expected number but got string', 3) | |
2131 | |
2132 v9.CheckDefExecFailure([ | |
2133 'g:ll = [1, 2, 3]', | |
2134 'g:idx = "x"', | |
2135 'unlet g:ll[0 : g:idx]', | |
2136 ], 'E1029: Expected number but got string', 3) | |
2137 | |
2085 # command recognized as assignment when skipping, should not give an error | 2138 # command recognized as assignment when skipping, should not give an error |
2086 v9.CheckScriptSuccess([ | 2139 v9.CheckScriptSuccess([ |
2087 'vim9script', | 2140 'vim9script', |
2088 'for i in []', | 2141 'for i in []', |
2089 " put =''", | 2142 " put =''", |