comparison src/testdir/test_vim9_expr.vim @ 21353:fb8c8fcb7b60 v8.2.1227

patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing Commit: https://github.com/vim/vim/commit/f5be8cdb77786f93c23237d7d8162feca92067e2 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jul 17 20:36:00 2020 +0200 patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing Problem: Vim9: allowing both quoted and # comments is confusing. Solution: Only support # comments in Vim9 script.
author Bram Moolenaar <Bram@vim.org>
date Fri, 17 Jul 2020 20:45:06 +0200
parents e641f678bdb9
children 8d58cbb07a12
comparison
equal deleted inserted replaced
21352:92c30752e9d2 21353:fb8c8fcb7b60
44 let RetThat: func = g:atrue ? RetOne : RetTwo 44 let RetThat: func = g:atrue ? RetOne : RetTwo
45 assert_equal(function('len'), RetThat) 45 assert_equal(function('len'), RetThat)
46 enddef 46 enddef
47 47
48 def Test_expr1_vimscript() 48 def Test_expr1_vimscript()
49 " only checks line continuation 49 # only checks line continuation
50 let lines =<< trim END 50 let lines =<< trim END
51 vim9script 51 vim9script
52 let var = 1 52 let var = 1
53 ? 'yes' 53 ? 'yes'
54 : 'no' 54 : 'no'
125 assert_equal(0, Record([]) || Record('') || Record(0)) 125 assert_equal(0, Record([]) || Record('') || Record(0))
126 assert_equal([[], '', 0], g:vals) 126 assert_equal([[], '', 0], g:vals)
127 enddef 127 enddef
128 128
129 def Test_expr2_vimscript() 129 def Test_expr2_vimscript()
130 " check line continuation 130 # check line continuation
131 let lines =<< trim END 131 let lines =<< trim END
132 vim9script 132 vim9script
133 let var = 0 133 let var = 0
134 || 1 134 || 1
135 assert_equal(1, var) 135 assert_equal(1, var)
152 v:false 152 v:false
153 assert_equal(v:true, var) 153 assert_equal(v:true, var)
154 END 154 END
155 CheckScriptSuccess(lines) 155 CheckScriptSuccess(lines)
156 156
157 " check keeping the value 157 # check keeping the value
158 lines =<< trim END 158 lines =<< trim END
159 vim9script 159 vim9script
160 assert_equal(2, 2 || 0) 160 assert_equal(2, 2 || 0)
161 assert_equal(7, 0 || 161 assert_equal(7, 0 ||
162 0 || 162 0 ||
229 assert_equal(0, Record([1]) && Record('z') && Record(0)) 229 assert_equal(0, Record([1]) && Record('z') && Record(0))
230 assert_equal([[1], 'z', 0], g:vals) 230 assert_equal([[1], 'z', 0], g:vals)
231 enddef 231 enddef
232 232
233 def Test_expr3_vimscript() 233 def Test_expr3_vimscript()
234 " check line continuation 234 # check line continuation
235 let lines =<< trim END 235 let lines =<< trim END
236 vim9script 236 vim9script
237 let var = 0 237 let var = 0
238 && 1 238 && 1
239 assert_equal(0, var) 239 assert_equal(0, var)
256 v:true 256 v:true
257 assert_equal(v:true, var) 257 assert_equal(v:true, var)
258 END 258 END
259 CheckScriptSuccess(lines) 259 CheckScriptSuccess(lines)
260 260
261 " check keeping the value 261 # check keeping the value
262 lines =<< trim END 262 lines =<< trim END
263 vim9script 263 vim9script
264 assert_equal(0, 2 && 0) 264 assert_equal(0, 2 && 0)
265 assert_equal(0, 0 && 265 assert_equal(0, 0 &&
266 0 && 266 0 &&
623 def RetVoid() 623 def RetVoid()
624 let x = 1 624 let x = 1
625 enddef 625 enddef
626 626
627 def Test_expr4_vimscript() 627 def Test_expr4_vimscript()
628 " check line continuation 628 # check line continuation
629 let lines =<< trim END 629 let lines =<< trim END
630 vim9script 630 vim9script
631 let var = 0 631 let var = 0
632 < 1 632 < 1
633 assert_equal(1, var) 633 assert_equal(1, var)
666 isnot 0z11 666 isnot 0z11
667 assert_equal(1, var) 667 assert_equal(1, var)
668 END 668 END
669 CheckScriptSuccess(lines) 669 CheckScriptSuccess(lines)
670 670
671 " spot check mismatching types 671 # spot check mismatching types
672 lines =<< trim END 672 lines =<< trim END
673 vim9script 673 vim9script
674 echo '' == 0 674 echo '' == 0
675 END 675 END
676 CheckScriptFailure(lines, 'E1072:') 676 CheckScriptFailure(lines, 'E1072:')
789 assert_equal(0z01ab3344, g:ablob + 0z3344) 789 assert_equal(0z01ab3344, g:ablob + 0z3344)
790 assert_equal(0z01ab01ab, g:ablob + g:ablob) 790 assert_equal(0z01ab01ab, g:ablob + g:ablob)
791 enddef 791 enddef
792 792
793 def Test_expr5_vim9script() 793 def Test_expr5_vim9script()
794 " only checks line continuation 794 # only checks line continuation
795 let lines =<< trim END 795 let lines =<< trim END
796 vim9script 796 vim9script
797 let var = 11 797 let var = 11
798 + 77 798 + 77
799 - 22 799 - 22
900 900
901 call CheckDefFailure(["let x = 6 * xxx"], 'E1001') 901 call CheckDefFailure(["let x = 6 * xxx"], 'E1001')
902 enddef 902 enddef
903 903
904 def Test_expr6_vim9script() 904 def Test_expr6_vim9script()
905 " only checks line continuation 905 # only checks line continuation
906 let lines =<< trim END 906 let lines =<< trim END
907 vim9script 907 vim9script
908 let var = 11 908 let var = 11
909 * 22 909 * 22
910 / 3 910 / 3
1022 1022
1023 let $TESTVAR = 'testvar' 1023 let $TESTVAR = 'testvar'
1024 1024
1025 " test low level expression 1025 " test low level expression
1026 def Test_expr7_number() 1026 def Test_expr7_number()
1027 " number constant 1027 # number constant
1028 assert_equal(0, 0) 1028 assert_equal(0, 0)
1029 assert_equal(654, 0654) 1029 assert_equal(654, 0654)
1030 1030
1031 assert_equal(6, 0x6) 1031 assert_equal(6, 0x6)
1032 assert_equal(15, 0xf) 1032 assert_equal(15, 0xf)
1033 assert_equal(255, 0xff) 1033 assert_equal(255, 0xff)
1034 enddef 1034 enddef
1035 1035
1036 def Test_expr7_float() 1036 def Test_expr7_float()
1037 " float constant 1037 # float constant
1038 if !has('float') 1038 if !has('float')
1039 MissingFeature 'float' 1039 MissingFeature 'float'
1040 else 1040 else
1041 assert_equal(g:float_zero, .0) 1041 assert_equal(g:float_zero, .0)
1042 assert_equal(g:float_zero, 0.0) 1042 assert_equal(g:float_zero, 0.0)
1044 assert_equal(g:float_big, 9.9e99) 1044 assert_equal(g:float_big, 9.9e99)
1045 endif 1045 endif
1046 enddef 1046 enddef
1047 1047
1048 def Test_expr7_blob() 1048 def Test_expr7_blob()
1049 " blob constant 1049 # blob constant
1050 assert_equal(g:blob_empty, 0z) 1050 assert_equal(g:blob_empty, 0z)
1051 assert_equal(g:blob_one, 0z01) 1051 assert_equal(g:blob_one, 0z01)
1052 assert_equal(g:blob_long, 0z0102.0304) 1052 assert_equal(g:blob_long, 0z0102.0304)
1053 1053
1054 call CheckDefFailure(["let x = 0z123"], 'E973:') 1054 call CheckDefFailure(["let x = 0z123"], 'E973:')
1055 enddef 1055 enddef
1056 1056
1057 def Test_expr7_string() 1057 def Test_expr7_string()
1058 " string constant 1058 # string constant
1059 assert_equal(g:string_empty, '') 1059 assert_equal(g:string_empty, '')
1060 assert_equal(g:string_empty, "") 1060 assert_equal(g:string_empty, "")
1061 assert_equal(g:string_short, 'x') 1061 assert_equal(g:string_short, 'x')
1062 assert_equal(g:string_short, "x") 1062 assert_equal(g:string_short, "x")
1063 assert_equal(g:string_long, 'abcdefghijklm') 1063 assert_equal(g:string_long, 'abcdefghijklm')
1075 call CheckDefFailure(["let old: list<number> = v:oldfiles"], 'E1013: type mismatch, expected list<number> but got list<string>') 1075 call CheckDefFailure(["let old: list<number> = v:oldfiles"], 'E1013: type mismatch, expected list<number> but got list<string>')
1076 call CheckDefFailure(["let old: dict<number> = v:completed_item"], 'E1013: type mismatch, expected dict<number> but got dict<any>') 1076 call CheckDefFailure(["let old: dict<number> = v:completed_item"], 'E1013: type mismatch, expected dict<number> but got dict<any>')
1077 enddef 1077 enddef
1078 1078
1079 def Test_expr7_special() 1079 def Test_expr7_special()
1080 " special constant 1080 # special constant
1081 assert_equal(g:special_true, true) 1081 assert_equal(g:special_true, true)
1082 assert_equal(g:special_false, false) 1082 assert_equal(g:special_false, false)
1083 assert_equal(g:special_true, v:true) 1083 assert_equal(g:special_true, v:true)
1084 assert_equal(g:special_false, v:false) 1084 assert_equal(g:special_false, v:false)
1085 assert_equal(g:special_null, v:null) 1085 assert_equal(g:special_null, v:null)
1104 END 1104 END
1105 CheckScriptSuccess(lines) 1105 CheckScriptSuccess(lines)
1106 enddef 1106 enddef
1107 1107
1108 def Test_expr7_list() 1108 def Test_expr7_list()
1109 " list 1109 # list
1110 assert_equal(g:list_empty, []) 1110 assert_equal(g:list_empty, [])
1111 assert_equal(g:list_empty, [ ]) 1111 assert_equal(g:list_empty, [ ])
1112 assert_equal(g:list_mixed, [1, 'b', false,]) 1112 assert_equal(g:list_mixed, [1, 'b', false,])
1113 assert_equal('b', g:list_mixed[1]) 1113 assert_equal('b', g:list_mixed[1])
1114 1114
1150 def Test_expr7_lambda() 1150 def Test_expr7_lambda()
1151 let La = { -> 'result'} 1151 let La = { -> 'result'}
1152 assert_equal('result', La()) 1152 assert_equal('result', La())
1153 assert_equal([1, 3, 5], [1, 2, 3]->map({key, val -> key + val})) 1153 assert_equal([1, 3, 5], [1, 2, 3]->map({key, val -> key + val}))
1154 1154
1155 " line continuation inside lambda with "cond ? expr : expr" works 1155 # line continuation inside lambda with "cond ? expr : expr" works
1156 let ll = range(3) 1156 let ll = range(3)
1157 map(ll, {k, v -> v % 2 ? { 1157 map(ll, {k, v -> v % 2 ? {
1158 '111': 111 } : {} 1158 '111': 111 } : {}
1159 }) 1159 })
1160 assert_equal([{}, {'111': 111}, {}], ll) 1160 assert_equal([{}, {'111': 111}, {}], ll)
1187 END 1187 END
1188 CheckScriptSuccess(lines) 1188 CheckScriptSuccess(lines)
1189 enddef 1189 enddef
1190 1190
1191 def Test_expr7_dict() 1191 def Test_expr7_dict()
1192 " dictionary 1192 # dictionary
1193 assert_equal(g:dict_empty, {}) 1193 assert_equal(g:dict_empty, {})
1194 assert_equal(g:dict_empty, { }) 1194 assert_equal(g:dict_empty, { })
1195 assert_equal(g:dict_one, {'one': 1}) 1195 assert_equal(g:dict_one, {'one': 1})
1196 let key = 'one' 1196 let key = 'one'
1197 let val = 1 1197 let val = 1
1314 END 1314 END
1315 CheckScriptSuccess(lines) 1315 CheckScriptSuccess(lines)
1316 enddef 1316 enddef
1317 1317
1318 def Test_expr7_option() 1318 def Test_expr7_option()
1319 " option 1319 # option
1320 set ts=11 1320 set ts=11
1321 assert_equal(11, &ts) 1321 assert_equal(11, &ts)
1322 &ts = 9 1322 &ts = 9
1323 assert_equal(9, &ts) 1323 assert_equal(9, &ts)
1324 set ts=8 1324 set ts=8
1328 assert_equal('', &grepprg) 1328 assert_equal('', &grepprg)
1329 set grepprg& 1329 set grepprg&
1330 enddef 1330 enddef
1331 1331
1332 def Test_expr7_environment() 1332 def Test_expr7_environment()
1333 " environment variable 1333 # environment variable
1334 assert_equal('testvar', $TESTVAR) 1334 assert_equal('testvar', $TESTVAR)
1335 assert_equal('', $ASDF_ASD_XXX) 1335 assert_equal('', $ASDF_ASD_XXX)
1336 1336
1337 call CheckDefFailure(["let x = $$$"], 'E1002:') 1337 call CheckDefFailure(["let x = $$$"], 'E1002:')
1338 enddef 1338 enddef
1341 @a = 'register a' 1341 @a = 'register a'
1342 assert_equal('register a', @a) 1342 assert_equal('register a', @a)
1343 enddef 1343 enddef
1344 1344
1345 def Test_expr7_parens() 1345 def Test_expr7_parens()
1346 " (expr) 1346 # (expr)
1347 assert_equal(4, (6 * 4) / 6) 1347 assert_equal(4, (6 * 4) / 6)
1348 assert_equal(0, 6 * ( 4 / 6 )) 1348 assert_equal(0, 6 * ( 4 / 6 ))
1349 1349
1350 assert_equal(6, +6) 1350 assert_equal(6, +6)
1351 assert_equal(-6, -6) 1351 assert_equal(-6, -6)
1472 func CallMe2(one, two) 1472 func CallMe2(one, two)
1473 return a:one .. a:two 1473 return a:one .. a:two
1474 endfunc 1474 endfunc
1475 1475
1476 def Test_expr7_trailing() 1476 def Test_expr7_trailing()
1477 " user function call 1477 # user function call
1478 assert_equal(123, g:CallMe(123)) 1478 assert_equal(123, g:CallMe(123))
1479 assert_equal(123, g:CallMe( 123)) 1479 assert_equal(123, g:CallMe( 123))
1480 assert_equal(123, g:CallMe(123 )) 1480 assert_equal(123, g:CallMe(123 ))
1481 assert_equal('yesno', g:CallMe2('yes', 'no')) 1481 assert_equal('yesno', g:CallMe2('yes', 'no'))
1482 assert_equal('yesno', g:CallMe2( 'yes', 'no' )) 1482 assert_equal('yesno', g:CallMe2( 'yes', 'no' ))
1483 assert_equal('nothing', g:CallMe('nothing')) 1483 assert_equal('nothing', g:CallMe('nothing'))
1484 1484
1485 " partial call 1485 # partial call
1486 let Part = function('g:CallMe') 1486 let Part = function('g:CallMe')
1487 assert_equal('yes', Part('yes')) 1487 assert_equal('yes', Part('yes'))
1488 1488
1489 " funcref call, using list index 1489 # funcref call, using list index
1490 let l = [] 1490 let l = []
1491 g:Funcrefs[0](l, 2) 1491 g:Funcrefs[0](l, 2)
1492 assert_equal([2], l) 1492 assert_equal([2], l)
1493 1493
1494 " method call 1494 # method call
1495 l = [2, 5, 6] 1495 l = [2, 5, 6]
1496 l->map({k, v -> k + v}) 1496 l->map({k, v -> k + v})
1497 assert_equal([2, 6, 8], l) 1497 assert_equal([2, 6, 8], l)
1498 1498
1499 " lambda method call 1499 # lambda method call
1500 l = [2, 5] 1500 l = [2, 5]
1501 l->{l -> add(l, 8)}() 1501 l->{l -> add(l, 8)}()
1502 assert_equal([2, 5, 8], l) 1502 assert_equal([2, 5, 8], l)
1503 1503
1504 " dict member 1504 # dict member
1505 let d = #{key: 123} 1505 let d = #{key: 123}
1506 assert_equal(123, d.key) 1506 assert_equal(123, d.key)
1507 enddef 1507 enddef
1508 1508
1509 def Test_expr7_subscript_linebreak() 1509 def Test_expr7_subscript_linebreak()