Mercurial > vim
comparison src/testdir/test_vim9_expr.vim @ 23106:b0c88aa0175b v8.2.2099
patch 8.2.2099: Vim9: some checks are not tested
Commit: https://github.com/vim/vim/commit/918a4249176a8ccec3a34c9c7ef7bf4163676a63
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Dec 6 14:37:08 2020 +0100
patch 8.2.2099: Vim9: some checks are not tested
Problem: Vim9: some checks are not tested.
Solution: Add a few more tests. Give better error messages.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 06 Dec 2020 14:45:04 +0100 |
parents | 285cde4b8d0e |
children | 60a0221beab0 |
comparison
equal
deleted
inserted
replaced
23105:65d66ab963c2 | 23106:b0c88aa0175b |
---|---|
186 call CheckDefFailure(["var x = 'x' ? 'one' : 'two'"], 'E1135:', 1) | 186 call CheckDefFailure(["var x = 'x' ? 'one' : 'two'"], 'E1135:', 1) |
187 call CheckDefFailure(["var x = 0z1234 ? 'one' : 'two'"], 'E974:', 1) | 187 call CheckDefFailure(["var x = 0z1234 ? 'one' : 'two'"], 'E974:', 1) |
188 call CheckDefExecFailure(["var x = [] ? 'one' : 'two'"], 'E745:', 1) | 188 call CheckDefExecFailure(["var x = [] ? 'one' : 'two'"], 'E745:', 1) |
189 call CheckDefExecFailure(["var x = {} ? 'one' : 'two'"], 'E728:', 1) | 189 call CheckDefExecFailure(["var x = {} ? 'one' : 'two'"], 'E728:', 1) |
190 | 190 |
191 call CheckDefExecFailure(["var x = false ? "], 'E1097:', 2) | |
192 call CheckDefExecFailure(["var x = false ? 'one' : "], 'E1097:', 2) | |
193 | |
194 call CheckDefExecFailure(["var x = true ? xxx : 'foo'"], 'E1001:', 1) | |
195 call CheckDefExecFailure(["var x = false ? 'foo' : xxx"], 'E1001:', 1) | |
196 | |
191 if has('float') | 197 if has('float') |
192 call CheckDefFailure(["var x = 0.1 ? 'one' : 'two'"], 'E805:', 1) | 198 call CheckDefFailure(["var x = 0.1 ? 'one' : 'two'"], 'E805:', 1) |
193 endif | 199 endif |
194 | 200 |
195 " missing argument detected even when common type is used | 201 " missing argument detected even when common type is used |
343 def Test_expr2_fails() | 349 def Test_expr2_fails() |
344 var msg = "White space required before and after '||'" | 350 var msg = "White space required before and after '||'" |
345 call CheckDefFailure(["var x = 1||2"], msg, 1) | 351 call CheckDefFailure(["var x = 1||2"], msg, 1) |
346 call CheckDefFailure(["var x = 1 ||2"], msg, 1) | 352 call CheckDefFailure(["var x = 1 ||2"], msg, 1) |
347 call CheckDefFailure(["var x = 1|| 2"], msg, 1) | 353 call CheckDefFailure(["var x = 1|| 2"], msg, 1) |
354 | |
355 call CheckDefFailure(["var x = false || "], 'E1097:', 2) | |
348 | 356 |
349 call CheckDefFailure(["var x = 1 || xxx"], 'E1001:', 1) | 357 call CheckDefFailure(["var x = 1 || xxx"], 'E1001:', 1) |
350 call CheckDefFailure(["var x = [] || false"], 'E1012:', 1) | 358 call CheckDefFailure(["var x = [] || false"], 'E1012:', 1) |
351 call CheckDefFailure(["if 'yes' || 0", 'echo 0', 'endif'], 'E1012: Type mismatch; expected bool but got string', 1) | 359 call CheckDefFailure(["if 'yes' || 0", 'echo 0', 'endif'], 'E1012: Type mismatch; expected bool but got string', 1) |
352 | 360 |
577 endif | 585 endif |
578 END | 586 END |
579 CheckDefAndScriptSuccess(lines) | 587 CheckDefAndScriptSuccess(lines) |
580 | 588 |
581 CheckDefFailure(["var x = 'a' == xxx"], 'E1001:', 1) | 589 CheckDefFailure(["var x = 'a' == xxx"], 'E1001:', 1) |
590 CheckDefFailure(["var x = 'a' == "], 'E1097:', 2) | |
591 | |
582 CheckDefExecFailure(['var items: any', 'eval 1', 'eval 2', 'if items == []', 'endif'], 'E691:', 4) | 592 CheckDefExecFailure(['var items: any', 'eval 1', 'eval 2', 'if items == []', 'endif'], 'E691:', 4) |
583 enddef | 593 enddef |
584 | 594 |
585 " test != comperator | 595 " test != comperator |
586 def Test_expr4_notequal() | 596 def Test_expr4_notequal() |
1347 endif | 1357 endif |
1348 END | 1358 END |
1349 CheckDefAndScriptSuccess(lines) | 1359 CheckDefAndScriptSuccess(lines) |
1350 | 1360 |
1351 CheckDefFailure(["var x = 6 * xxx"], 'E1001:', 1) | 1361 CheckDefFailure(["var x = 6 * xxx"], 'E1001:', 1) |
1362 CheckDefFailure(["var d = 6 * "], 'E1097:', 2) | |
1352 enddef | 1363 enddef |
1353 | 1364 |
1354 def Test_expr6_vim9script() | 1365 def Test_expr6_vim9script() |
1355 # check line continuation | 1366 # check line continuation |
1356 var lines =<< trim END | 1367 var lines =<< trim END |
1518 var ln: list<number> = [<number>g:anint, <number>g:thefour] | 1529 var ln: list<number> = [<number>g:anint, <number>g:thefour] |
1519 var nr = <number>234 | 1530 var nr = <number>234 |
1520 assert_equal(234, nr) | 1531 assert_equal(234, nr) |
1521 | 1532 |
1522 CheckDefFailure(["var x = <nr>123"], 'E1010:', 1) | 1533 CheckDefFailure(["var x = <nr>123"], 'E1010:', 1) |
1534 CheckDefFailure(["var x = <number>"], 'E1097:', 2) | |
1523 CheckDefFailure(["var x = <number >123"], 'E1068:', 1) | 1535 CheckDefFailure(["var x = <number >123"], 'E1068:', 1) |
1524 CheckDefFailure(["var x = <number 123"], 'E1104:', 1) | 1536 CheckDefFailure(["var x = <number 123"], 'E1104:', 1) |
1525 enddef | 1537 enddef |
1526 | 1538 |
1527 " test low level expression | 1539 " test low level expression |
2049 lines =<< trim END | 2061 lines =<< trim END |
2050 vim9script | 2062 vim9script |
2051 var l: dict<string> = {a: 234, b: 'x'} | 2063 var l: dict<string> = {a: 234, b: 'x'} |
2052 END | 2064 END |
2053 CheckScriptFailure(lines, 'E1012:', 2) | 2065 CheckScriptFailure(lines, 'E1012:', 2) |
2066 | |
2067 lines =<< trim END | |
2068 vim9script | |
2069 var d = {['a']: 234, ['b': 'x'} | |
2070 END | |
2071 CheckScriptFailure(lines, 'E1139:', 2) | |
2072 lines =<< trim END | |
2073 vim9script | |
2074 def Func() | |
2075 var d = {['a']: 234, ['b': 'x'} | |
2076 enddef | |
2077 defcompile | |
2078 END | |
2079 CheckScriptFailure(lines, 'E1139:', 1) | |
2080 lines =<< trim END | |
2081 vim9script | |
2082 var d = {'a': | |
2083 END | |
2084 CheckScriptFailure(lines, 'E15:', 2) | |
2085 lines =<< trim END | |
2086 vim9script | |
2087 def Func() | |
2088 var d = {'a': | |
2089 enddef | |
2090 defcompile | |
2091 END | |
2092 CheckScriptFailure(lines, 'E723:', 1) | |
2054 | 2093 |
2055 lines =<< trim END | 2094 lines =<< trim END |
2056 vim9script | 2095 vim9script |
2057 def Failing() | 2096 def Failing() |
2058 job_stop() | 2097 job_stop() |
2564 assert_equal('bçdëf', text[1:]) | 2603 assert_equal('bçdëf', text[1:]) |
2565 assert_equal('ábçdëf', text[:]) | 2604 assert_equal('ábçdëf', text[:]) |
2566 END | 2605 END |
2567 CheckDefSuccess(lines) | 2606 CheckDefSuccess(lines) |
2568 CheckScriptSuccess(['vim9script'] + lines) | 2607 CheckScriptSuccess(['vim9script'] + lines) |
2608 | |
2609 lines =<< trim END | |
2610 var d = 'asdf'[1: | |
2611 END | |
2612 CheckDefFailure(lines, 'E1097:', 2) | |
2613 lines =<< trim END | |
2614 var d = 'asdf'[1:xxx] | |
2615 END | |
2616 CheckDefFailure(lines, 'E1001:', 1) | |
2617 lines =<< trim END | |
2618 var d = 'asdf'[1:2 | |
2619 END | |
2620 CheckDefFailure(lines, 'E1097:', 2) | |
2621 lines =<< trim END | |
2622 var d = 'asdf'[1:2 | |
2623 echo d | |
2624 END | |
2625 CheckDefFailure(lines, 'E111:', 2) | |
2626 lines =<< trim END | |
2627 var d = 'asdf'['1'] | |
2628 echo d | |
2629 END | |
2630 CheckDefFailure(lines, 'E1012: Type mismatch; expected number but got string', 1) | |
2631 lines =<< trim END | |
2632 var d = 'asdf'['1':2] | |
2633 echo d | |
2634 END | |
2635 CheckDefFailure(lines, 'E1012: Type mismatch; expected number but got string', 1) | |
2636 lines =<< trim END | |
2637 var d = 'asdf'[1:'2'] | |
2638 echo d | |
2639 END | |
2640 CheckDefFailure(lines, 'E1012: Type mismatch; expected number but got string', 1) | |
2569 enddef | 2641 enddef |
2570 | 2642 |
2571 def Test_expr7_list_subscript() | 2643 def Test_expr7_list_subscript() |
2572 var lines =<< trim END | 2644 var lines =<< trim END |
2573 var list = [0, 1, 2, 3, 4] | 2645 var list = [0, 1, 2, 3, 4] |