Bram Moolenaar | 4a137b4 | 2017-08-04 22:37:11 +0200 | [diff] [blame] | 1 | " Tests for the :let command. |
| 2 | |
| 3 | func Test_let() |
| 4 | " Test to not autoload when assigning. It causes internal error. |
| 5 | set runtimepath+=./sautest |
| 6 | let Test104#numvar = function('tr') |
| 7 | call assert_equal("function('tr')", string(Test104#numvar)) |
| 8 | |
| 9 | let a = 1 |
| 10 | let b = 2 |
| 11 | |
| 12 | let out = execute('let a b') |
| 13 | let s = "\na #1\nb #2" |
| 14 | call assert_equal(s, out) |
| 15 | |
| 16 | let out = execute('let {0 == 1 ? "a" : "b"}') |
| 17 | let s = "\nb #2" |
| 18 | call assert_equal(s, out) |
| 19 | |
| 20 | let out = execute('let {0 == 1 ? "a" : "b"} a') |
| 21 | let s = "\nb #2\na #1" |
| 22 | call assert_equal(s, out) |
| 23 | |
| 24 | let out = execute('let a {0 == 1 ? "a" : "b"}') |
| 25 | let s = "\na #1\nb #2" |
| 26 | call assert_equal(s, out) |
Bram Moolenaar | 8f76e6b | 2019-11-26 16:50:30 +0100 | [diff] [blame] | 27 | |
Bram Moolenaar | 8dfcce3 | 2020-03-18 19:32:26 +0100 | [diff] [blame] | 28 | " Test for displaying a string variable |
| 29 | let s = 'vim' |
| 30 | let out = execute('let s') |
| 31 | let s = "\ns vim" |
| 32 | call assert_equal(s, out) |
| 33 | |
| 34 | " Test for displaying a list variable |
| 35 | let l = [1, 2] |
| 36 | let out = execute('let l') |
| 37 | let s = "\nl [1, 2]" |
| 38 | call assert_equal(s, out) |
| 39 | |
| 40 | " Test for displaying a dict variable |
| 41 | let d = {'k' : 'v'} |
| 42 | let out = execute('let d') |
| 43 | let s = "\nd {'k': 'v'}" |
| 44 | call assert_equal(s, out) |
| 45 | |
| 46 | " Test for displaying a function reference variable |
| 47 | let F = function('min') |
| 48 | let out = execute('let F') |
| 49 | let s = "\nF *min()" |
| 50 | call assert_equal(s, out) |
| 51 | |
Bram Moolenaar | 8f76e6b | 2019-11-26 16:50:30 +0100 | [diff] [blame] | 52 | let x = 0 |
| 53 | if 0 | let x = 1 | endif |
| 54 | call assert_equal(0, x) |
Bram Moolenaar | 8dfcce3 | 2020-03-18 19:32:26 +0100 | [diff] [blame] | 55 | |
| 56 | " Display a list item using an out of range index |
| 57 | let l = [10] |
| 58 | call assert_fails('let l[1]', 'E684:') |
| 59 | |
| 60 | " List special variable dictionaries |
| 61 | let g:Test_Global_Var = 5 |
| 62 | call assert_match("\nTest_Global_Var #5", execute('let g:')) |
| 63 | unlet g:Test_Global_Var |
| 64 | |
| 65 | let b:Test_Buf_Var = 8 |
| 66 | call assert_match("\nb:Test_Buf_Var #8", execute('let b:')) |
| 67 | unlet b:Test_Buf_Var |
| 68 | |
| 69 | let w:Test_Win_Var = 'foo' |
| 70 | call assert_equal("\nw:Test_Win_Var foo", execute('let w:')) |
| 71 | unlet w:Test_Win_Var |
| 72 | |
| 73 | let t:Test_Tab_Var = 'bar' |
| 74 | call assert_equal("\nt:Test_Tab_Var bar", execute('let t:')) |
| 75 | unlet t:Test_Tab_Var |
| 76 | |
| 77 | let s:Test_Script_Var = [7] |
| 78 | call assert_match("\ns:Test_Script_Var \\[7]", execute('let s:')) |
| 79 | unlet s:Test_Script_Var |
| 80 | |
| 81 | let l:Test_Local_Var = {'k' : 5} |
| 82 | call assert_match("\nl:Test_Local_Var {'k': 5}", execute('let l:')) |
| 83 | call assert_match("v:errors []", execute('let v:')) |
Bram Moolenaar | 9d8d0b5 | 2020-04-24 22:47:31 +0200 | [diff] [blame] | 84 | |
| 85 | " Test for assigning multiple list items |
| 86 | let l = [1, 2, 3] |
| 87 | let [l[0], l[1]] = [10, 20] |
| 88 | call assert_equal([10, 20, 3], l) |
| 89 | |
| 90 | " Test for errors in conditional expression |
| 91 | call assert_fails('let val = [] ? 1 : 2', 'E745:') |
| 92 | call assert_fails('let val = 1 ? 5+ : 6', 'E121:') |
| 93 | call assert_fails('let val = 1 ? 0 : 5+', 'E15:') |
| 94 | call assert_false(exists('val')) |
| 95 | |
| 96 | " Test for errors in logical operators |
| 97 | let @a = 'if [] || 0 | let val = 2 | endif' |
| 98 | call assert_fails('exe @a', 'E745:') |
| 99 | call assert_fails('call feedkeys(":let val = 0 || []\<cr>", "xt")', 'E745:') |
| 100 | call assert_fails('exe "let val = [] && 5"', 'E745:') |
| 101 | call assert_fails('exe "let val = 6 && []"', 'E745:') |
Bram Moolenaar | 4a137b4 | 2017-08-04 22:37:11 +0200 | [diff] [blame] | 102 | endfunc |
Bram Moolenaar | 31b8160 | 2019-02-10 22:14:27 +0100 | [diff] [blame] | 103 | |
| 104 | func s:set_arg1(a) abort |
| 105 | let a:a = 1 |
| 106 | endfunction |
| 107 | |
| 108 | func s:set_arg2(a) abort |
| 109 | let a:b = 1 |
| 110 | endfunction |
| 111 | |
| 112 | func s:set_arg3(a) abort |
| 113 | let b = a: |
| 114 | let b['a'] = 1 |
| 115 | endfunction |
| 116 | |
| 117 | func s:set_arg4(a) abort |
| 118 | let b = a: |
| 119 | let b['a'] = 1 |
| 120 | endfunction |
| 121 | |
| 122 | func s:set_arg5(a) abort |
| 123 | let b = a: |
| 124 | let b['a'][0] = 1 |
| 125 | endfunction |
| 126 | |
| 127 | func s:set_arg6(a) abort |
| 128 | let a:a[0] = 1 |
| 129 | endfunction |
| 130 | |
| 131 | func s:set_arg7(a) abort |
| 132 | call extend(a:, {'a': 1}) |
| 133 | endfunction |
| 134 | |
| 135 | func s:set_arg8(a) abort |
| 136 | call extend(a:, {'b': 1}) |
| 137 | endfunction |
| 138 | |
| 139 | func s:set_arg9(a) abort |
| 140 | let a:['b'] = 1 |
| 141 | endfunction |
| 142 | |
| 143 | func s:set_arg10(a) abort |
| 144 | let b = a: |
| 145 | call extend(b, {'a': 1}) |
| 146 | endfunction |
| 147 | |
| 148 | func s:set_arg11(a) abort |
| 149 | let b = a: |
| 150 | call extend(b, {'b': 1}) |
| 151 | endfunction |
| 152 | |
| 153 | func s:set_arg12(a) abort |
| 154 | let b = a: |
| 155 | let b['b'] = 1 |
| 156 | endfunction |
| 157 | |
| 158 | func Test_let_arg_fail() |
| 159 | call assert_fails('call s:set_arg1(1)', 'E46:') |
| 160 | call assert_fails('call s:set_arg2(1)', 'E461:') |
| 161 | call assert_fails('call s:set_arg3(1)', 'E46:') |
| 162 | call assert_fails('call s:set_arg4(1)', 'E46:') |
| 163 | call assert_fails('call s:set_arg5(1)', 'E46:') |
| 164 | call s:set_arg6([0]) |
| 165 | call assert_fails('call s:set_arg7(1)', 'E742:') |
| 166 | call assert_fails('call s:set_arg8(1)', 'E742:') |
| 167 | call assert_fails('call s:set_arg9(1)', 'E461:') |
| 168 | call assert_fails('call s:set_arg10(1)', 'E742:') |
| 169 | call assert_fails('call s:set_arg11(1)', 'E742:') |
| 170 | call assert_fails('call s:set_arg12(1)', 'E461:') |
| 171 | endfunction |
| 172 | |
| 173 | func s:set_varg1(...) abort |
| 174 | let a:000 = [] |
| 175 | endfunction |
| 176 | |
| 177 | func s:set_varg2(...) abort |
| 178 | let a:000[0] = 1 |
| 179 | endfunction |
| 180 | |
| 181 | func s:set_varg3(...) abort |
| 182 | let a:000 += [1] |
| 183 | endfunction |
| 184 | |
| 185 | func s:set_varg4(...) abort |
| 186 | call add(a:000, 1) |
| 187 | endfunction |
| 188 | |
| 189 | func s:set_varg5(...) abort |
| 190 | let a:000[0][0] = 1 |
| 191 | endfunction |
| 192 | |
| 193 | func s:set_varg6(...) abort |
| 194 | let b = a:000 |
| 195 | let b[0] = 1 |
| 196 | endfunction |
| 197 | |
| 198 | func s:set_varg7(...) abort |
| 199 | let b = a:000 |
| 200 | let b += [1] |
| 201 | endfunction |
| 202 | |
| 203 | func s:set_varg8(...) abort |
| 204 | let b = a:000 |
| 205 | call add(b, 1) |
| 206 | endfunction |
| 207 | |
| 208 | func s:set_varg9(...) abort |
| 209 | let b = a:000 |
| 210 | let b[0][0] = 1 |
| 211 | endfunction |
| 212 | |
| 213 | func Test_let_varg_fail() |
| 214 | call assert_fails('call s:set_varg1(1)', 'E46:') |
| 215 | call assert_fails('call s:set_varg2(1)', 'E742:') |
| 216 | call assert_fails('call s:set_varg3(1)', 'E46:') |
| 217 | call assert_fails('call s:set_varg4(1)', 'E742:') |
| 218 | call s:set_varg5([0]) |
| 219 | call assert_fails('call s:set_varg6(1)', 'E742:') |
Bram Moolenaar | 05c00c0 | 2019-02-11 22:00:11 +0100 | [diff] [blame] | 220 | call assert_fails('call s:set_varg7(1)', 'E742:') |
Bram Moolenaar | 31b8160 | 2019-02-10 22:14:27 +0100 | [diff] [blame] | 221 | call assert_fails('call s:set_varg8(1)', 'E742:') |
| 222 | call s:set_varg9([0]) |
| 223 | endfunction |
Bram Moolenaar | f0908e6 | 2019-03-30 20:11:50 +0100 | [diff] [blame] | 224 | |
| 225 | func Test_let_utf8_environment() |
| 226 | let $a = 'ĀĒĪŌŪあいうえお' |
| 227 | call assert_equal('ĀĒĪŌŪあいうえお', $a) |
| 228 | endfunc |
Bram Moolenaar | f5842c5 | 2019-05-19 18:41:26 +0200 | [diff] [blame] | 229 | |
Bram Moolenaar | fcf8a87 | 2019-11-06 15:22:00 +0100 | [diff] [blame] | 230 | func Test_let_no_type_checking() |
| 231 | let v = 1 |
| 232 | let v = [1,2,3] |
| 233 | let v = {'a': 1, 'b': 2} |
| 234 | let v = 3.4 |
| 235 | let v = 'hello' |
| 236 | endfunc |
| 237 | |
| 238 | func Test_let_termcap() |
| 239 | " Terminal code |
| 240 | let old_t_te = &t_te |
| 241 | let &t_te = "\<Esc>[yes;" |
| 242 | call assert_match('t_te.*^[[yes;', execute("set termcap")) |
| 243 | let &t_te = old_t_te |
| 244 | |
| 245 | if exists("+t_k1") |
| 246 | " Key code |
| 247 | let old_t_k1 = &t_k1 |
| 248 | let &t_k1 = "that" |
| 249 | call assert_match('t_k1.*that', execute("set termcap")) |
| 250 | let &t_k1 = old_t_k1 |
| 251 | endif |
| 252 | |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 253 | call assert_fails('let x = &t_xx', 'E113:') |
Bram Moolenaar | fcf8a87 | 2019-11-06 15:22:00 +0100 | [diff] [blame] | 254 | let &t_xx = "yes" |
| 255 | call assert_equal("yes", &t_xx) |
| 256 | let &t_xx = "" |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 257 | call assert_fails('let x = &t_xx', 'E113:') |
Bram Moolenaar | fcf8a87 | 2019-11-06 15:22:00 +0100 | [diff] [blame] | 258 | endfunc |
| 259 | |
| 260 | func Test_let_option_error() |
| 261 | let _w = &tw |
| 262 | let &tw = 80 |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 263 | call assert_fails('let &tw .= 1', 'E734:') |
Bram Moolenaar | fcf8a87 | 2019-11-06 15:22:00 +0100 | [diff] [blame] | 264 | call assert_equal(80, &tw) |
| 265 | let &tw = _w |
| 266 | |
| 267 | let _w = &fillchars |
| 268 | let &fillchars = "vert:|" |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 269 | call assert_fails('let &fillchars += "diff:-"', 'E734:') |
Bram Moolenaar | fcf8a87 | 2019-11-06 15:22:00 +0100 | [diff] [blame] | 270 | call assert_equal("vert:|", &fillchars) |
| 271 | let &fillchars = _w |
| 272 | endfunc |
| 273 | |
Bram Moolenaar | 8dfcce3 | 2020-03-18 19:32:26 +0100 | [diff] [blame] | 274 | " Errors with the :let statement |
Bram Moolenaar | fcf8a87 | 2019-11-06 15:22:00 +0100 | [diff] [blame] | 275 | func Test_let_errors() |
| 276 | let s = 'abcd' |
| 277 | call assert_fails('let s[1] = 5', 'E689:') |
| 278 | |
| 279 | let l = [1, 2, 3] |
| 280 | call assert_fails('let l[:] = 5', 'E709:') |
Bram Moolenaar | 8dfcce3 | 2020-03-18 19:32:26 +0100 | [diff] [blame] | 281 | |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 282 | call assert_fails('let x:lnum=5', ['E121:', 'E488:']) |
Bram Moolenaar | 8dfcce3 | 2020-03-18 19:32:26 +0100 | [diff] [blame] | 283 | call assert_fails('let v:=5', 'E461:') |
| 284 | call assert_fails('let [a]', 'E474:') |
| 285 | call assert_fails('let [a, b] = [', 'E697:') |
| 286 | call assert_fails('let [a, b] = [10, 20', 'E696:') |
| 287 | call assert_fails('let [a, b] = 10', 'E714:') |
| 288 | call assert_fails('let [a, , b] = [10, 20]', 'E475:') |
| 289 | call assert_fails('let [a, b&] = [10, 20]', 'E475:') |
| 290 | call assert_fails('let $ = 10', 'E475:') |
| 291 | call assert_fails('let $FOO[1] = "abc"', 'E18:') |
| 292 | call assert_fails('let &buftype[1] = "nofile"', 'E18:') |
| 293 | let s = "var" |
| 294 | let var = 1 |
Bram Moolenaar | ea04a6e | 2020-04-23 13:38:02 +0200 | [diff] [blame] | 295 | call assert_fails('let var += [1,2]', 'E734:') |
Bram Moolenaar | b13ab99 | 2020-07-27 21:43:28 +0200 | [diff] [blame] | 296 | call assert_fails('let {s}.1 = 2', 'E18:') |
Bram Moolenaar | 8b63313 | 2020-03-20 18:20:51 +0100 | [diff] [blame] | 297 | call assert_fails('let a[1] = 5', 'E121:') |
| 298 | let l = [[1,2]] |
| 299 | call assert_fails('let l[:][0] = [5]', 'E708:') |
| 300 | let d = {'k' : 4} |
Bram Moolenaar | 63be3d4 | 2020-07-23 13:11:37 +0200 | [diff] [blame] | 301 | call assert_fails('let d.# = 5', 'E488:') |
Bram Moolenaar | 58fb7c3 | 2021-04-05 20:59:41 +0200 | [diff] [blame] | 302 | call assert_fails('let d.m += 5', 'E716:') |
Bram Moolenaar | 9d8d0b5 | 2020-04-24 22:47:31 +0200 | [diff] [blame] | 303 | call assert_fails('let m = d[{]', 'E15:') |
Bram Moolenaar | 8b63313 | 2020-03-20 18:20:51 +0100 | [diff] [blame] | 304 | let l = [1, 2] |
| 305 | call assert_fails('let l[2] = 0', 'E684:') |
| 306 | call assert_fails('let l[0:1] = [1, 2, 3]', 'E710:') |
| 307 | call assert_fails('let l[-2:-3] = [3, 4]', 'E684:') |
| 308 | call assert_fails('let l[0:4] = [5, 6]', 'E711:') |
Bram Moolenaar | 9d8d0b5 | 2020-04-24 22:47:31 +0200 | [diff] [blame] | 309 | call assert_fails('let l -= 2', 'E734:') |
| 310 | call assert_fails('let l += 2', 'E734:') |
Bram Moolenaar | ea04a6e | 2020-04-23 13:38:02 +0200 | [diff] [blame] | 311 | call assert_fails('let g:["a;b"] = 10', 'E461:') |
| 312 | call assert_fails('let g:.min = function("max")', 'E704:') |
Bram Moolenaar | 9d8d0b5 | 2020-04-24 22:47:31 +0200 | [diff] [blame] | 313 | if has('channel') |
| 314 | let ch = test_null_channel() |
| 315 | call assert_fails('let ch += 1', 'E734:') |
| 316 | endif |
Bram Moolenaar | fae55a9 | 2021-06-17 22:08:30 +0200 | [diff] [blame] | 317 | call assert_fails('let name = "a" .. "b",', 'E488: Trailing characters: ,') |
Bram Moolenaar | 8dfcce3 | 2020-03-18 19:32:26 +0100 | [diff] [blame] | 318 | |
| 319 | " This test works only when the language is English |
| 320 | if v:lang == "C" || v:lang =~ '^[Ee]n' |
| 321 | call assert_fails('let [a ; b;] = [10, 20]', |
| 322 | \ 'Double ; in list of variables') |
| 323 | endif |
Bram Moolenaar | fcf8a87 | 2019-11-06 15:22:00 +0100 | [diff] [blame] | 324 | endfunc |
| 325 | |
Bram Moolenaar | 8471e57 | 2019-05-19 21:37:18 +0200 | [diff] [blame] | 326 | func Test_let_heredoc_fails() |
| 327 | call assert_fails('let v =<< marker', 'E991:') |
Bram Moolenaar | 8dfcce3 | 2020-03-18 19:32:26 +0100 | [diff] [blame] | 328 | try |
| 329 | exe "let v =<< TEXT | abc | TEXT" |
| 330 | call assert_report('No exception thrown') |
| 331 | catch /E488:/ |
| 332 | catch |
| 333 | call assert_report("Caught exception: " .. v:exception) |
| 334 | endtry |
Bram Moolenaar | 8471e57 | 2019-05-19 21:37:18 +0200 | [diff] [blame] | 335 | |
| 336 | let text =<< trim END |
| 337 | func WrongSyntax() |
| 338 | let v =<< that there |
| 339 | endfunc |
| 340 | END |
| 341 | call writefile(text, 'XheredocFail') |
Bram Moolenaar | b5b9480 | 2020-12-13 17:50:20 +0100 | [diff] [blame] | 342 | call assert_fails('source XheredocFail', 'E1145:') |
Bram Moolenaar | 8471e57 | 2019-05-19 21:37:18 +0200 | [diff] [blame] | 343 | call delete('XheredocFail') |
| 344 | |
Bram Moolenaar | 2458200 | 2019-07-21 14:14:26 +0200 | [diff] [blame] | 345 | let text =<< trim CodeEnd |
Bram Moolenaar | 8471e57 | 2019-05-19 21:37:18 +0200 | [diff] [blame] | 346 | func MissingEnd() |
| 347 | let v =<< END |
| 348 | endfunc |
Bram Moolenaar | 2458200 | 2019-07-21 14:14:26 +0200 | [diff] [blame] | 349 | CodeEnd |
Bram Moolenaar | 8471e57 | 2019-05-19 21:37:18 +0200 | [diff] [blame] | 350 | call writefile(text, 'XheredocWrong') |
Bram Moolenaar | b5b9480 | 2020-12-13 17:50:20 +0100 | [diff] [blame] | 351 | call assert_fails('source XheredocWrong', 'E1145:') |
Bram Moolenaar | 8471e57 | 2019-05-19 21:37:18 +0200 | [diff] [blame] | 352 | call delete('XheredocWrong') |
Bram Moolenaar | 2458200 | 2019-07-21 14:14:26 +0200 | [diff] [blame] | 353 | |
| 354 | let text =<< trim TEXTend |
| 355 | let v =<< " comment |
| 356 | TEXTend |
| 357 | call writefile(text, 'XheredocNoMarker') |
| 358 | call assert_fails('source XheredocNoMarker', 'E172:') |
| 359 | call delete('XheredocNoMarker') |
| 360 | |
| 361 | let text =<< trim TEXTend |
| 362 | let v =<< text |
| 363 | TEXTend |
| 364 | call writefile(text, 'XheredocBadMarker') |
| 365 | call assert_fails('source XheredocBadMarker', 'E221:') |
| 366 | call delete('XheredocBadMarker') |
Bram Moolenaar | 8dfcce3 | 2020-03-18 19:32:26 +0100 | [diff] [blame] | 367 | |
| 368 | call writefile(['let v =<< TEXT', 'abc'], 'XheredocMissingMarker') |
| 369 | call assert_fails('source XheredocMissingMarker', 'E990:') |
| 370 | call delete('XheredocMissingMarker') |
Bram Moolenaar | 8471e57 | 2019-05-19 21:37:18 +0200 | [diff] [blame] | 371 | endfunc |
| 372 | |
Bram Moolenaar | ecaa75b | 2019-07-21 23:04:21 +0200 | [diff] [blame] | 373 | func Test_let_heredoc_trim_no_indent_marker() |
| 374 | let text =<< trim END |
| 375 | Text |
| 376 | with |
| 377 | indent |
| 378 | END |
| 379 | call assert_equal(['Text', 'with', 'indent'], text) |
| 380 | endfunc |
| 381 | |
Bram Moolenaar | f5842c5 | 2019-05-19 18:41:26 +0200 | [diff] [blame] | 382 | " Test for the setting a variable using the heredoc syntax |
| 383 | func Test_let_heredoc() |
| 384 | let var1 =<< END |
| 385 | Some sample text |
| 386 | Text with indent |
| 387 | !@#$%^&*()-+_={}|[]\~`:";'<>?,./ |
| 388 | END |
| 389 | |
| 390 | call assert_equal(["Some sample text", "\tText with indent", " !@#$%^&*()-+_={}|[]\\~`:\";'<>?,./"], var1) |
| 391 | |
Bram Moolenaar | 2458200 | 2019-07-21 14:14:26 +0200 | [diff] [blame] | 392 | let var2 =<< XXX |
Bram Moolenaar | f5842c5 | 2019-05-19 18:41:26 +0200 | [diff] [blame] | 393 | Editor |
Bram Moolenaar | 2458200 | 2019-07-21 14:14:26 +0200 | [diff] [blame] | 394 | XXX |
Bram Moolenaar | f5842c5 | 2019-05-19 18:41:26 +0200 | [diff] [blame] | 395 | call assert_equal(['Editor'], var2) |
| 396 | |
| 397 | let var3 =<<END |
| 398 | END |
| 399 | call assert_equal([], var3) |
| 400 | |
| 401 | let var3 =<<END |
| 402 | vim |
| 403 | |
| 404 | end |
| 405 | END |
| 406 | END |
| 407 | END |
| 408 | call assert_equal(['vim', '', 'end', ' END', 'END '], var3) |
| 409 | |
| 410 | let var1 =<< trim END |
| 411 | Line1 |
| 412 | Line2 |
| 413 | Line3 |
| 414 | END |
| 415 | END |
| 416 | call assert_equal(['Line1', ' Line2', "\tLine3", ' END'], var1) |
| 417 | |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 418 | let var1 =<< trim !!! |
| 419 | Line1 |
| 420 | line2 |
| 421 | Line3 |
| 422 | !!! |
| 423 | !!! |
| 424 | call assert_equal(['Line1', ' line2', "\tLine3", '!!!',], var1) |
| 425 | |
Bram Moolenaar | 2458200 | 2019-07-21 14:14:26 +0200 | [diff] [blame] | 426 | let var1 =<< trim XX |
Bram Moolenaar | f5842c5 | 2019-05-19 18:41:26 +0200 | [diff] [blame] | 427 | Line1 |
Bram Moolenaar | 2458200 | 2019-07-21 14:14:26 +0200 | [diff] [blame] | 428 | XX |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 429 | call assert_equal(['Line1'], var1) |
Bram Moolenaar | f5842c5 | 2019-05-19 18:41:26 +0200 | [diff] [blame] | 430 | |
Bram Moolenaar | 8471e57 | 2019-05-19 21:37:18 +0200 | [diff] [blame] | 431 | " ignore "endfunc" |
| 432 | let var1 =<< END |
| 433 | something |
Bram Moolenaar | f5842c5 | 2019-05-19 18:41:26 +0200 | [diff] [blame] | 434 | endfunc |
Bram Moolenaar | 8471e57 | 2019-05-19 21:37:18 +0200 | [diff] [blame] | 435 | END |
| 436 | call assert_equal(['something', 'endfunc'], var1) |
Bram Moolenaar | f5842c5 | 2019-05-19 18:41:26 +0200 | [diff] [blame] | 437 | |
Bram Moolenaar | 8471e57 | 2019-05-19 21:37:18 +0200 | [diff] [blame] | 438 | " ignore "endfunc" with trim |
| 439 | let var1 =<< trim END |
| 440 | something |
| 441 | endfunc |
| 442 | END |
| 443 | call assert_equal(['something', 'endfunc'], var1) |
Bram Moolenaar | f5842c5 | 2019-05-19 18:41:26 +0200 | [diff] [blame] | 444 | |
Bram Moolenaar | e96a249 | 2019-06-25 04:12:16 +0200 | [diff] [blame] | 445 | " not concatenate lines |
| 446 | let var1 =<< END |
| 447 | some |
| 448 | \thing |
| 449 | \ else |
| 450 | END |
| 451 | call assert_equal(['some', ' \thing', ' \ else'], var1) |
| 452 | |
Bram Moolenaar | 8471e57 | 2019-05-19 21:37:18 +0200 | [diff] [blame] | 453 | " ignore "python << xx" |
| 454 | let var1 =<<END |
| 455 | something |
| 456 | python << xx |
| 457 | END |
| 458 | call assert_equal(['something', 'python << xx'], var1) |
| 459 | |
| 460 | " ignore "python << xx" with trim |
| 461 | let var1 =<< trim END |
| 462 | something |
| 463 | python << xx |
| 464 | END |
| 465 | call assert_equal(['something', 'python << xx'], var1) |
| 466 | |
| 467 | " ignore "append" |
Bram Moolenaar | 2458200 | 2019-07-21 14:14:26 +0200 | [diff] [blame] | 468 | let var1 =<< E |
Bram Moolenaar | 8471e57 | 2019-05-19 21:37:18 +0200 | [diff] [blame] | 469 | something |
| 470 | app |
Bram Moolenaar | 2458200 | 2019-07-21 14:14:26 +0200 | [diff] [blame] | 471 | E |
Bram Moolenaar | 8471e57 | 2019-05-19 21:37:18 +0200 | [diff] [blame] | 472 | call assert_equal(['something', 'app'], var1) |
| 473 | |
| 474 | " ignore "append" with trim |
Bram Moolenaar | 2458200 | 2019-07-21 14:14:26 +0200 | [diff] [blame] | 475 | let var1 =<< trim END |
Bram Moolenaar | 8471e57 | 2019-05-19 21:37:18 +0200 | [diff] [blame] | 476 | something |
| 477 | app |
Bram Moolenaar | 2458200 | 2019-07-21 14:14:26 +0200 | [diff] [blame] | 478 | END |
Bram Moolenaar | 8471e57 | 2019-05-19 21:37:18 +0200 | [diff] [blame] | 479 | call assert_equal(['something', 'app'], var1) |
Bram Moolenaar | b1ba9ab | 2019-10-16 23:34:42 +0200 | [diff] [blame] | 480 | |
| 481 | let check = [] |
| 482 | if 0 |
| 483 | let check =<< trim END |
| 484 | from heredoc |
| 485 | END |
| 486 | endif |
| 487 | call assert_equal([], check) |
Bram Moolenaar | 1e673b9 | 2019-11-06 15:02:50 +0100 | [diff] [blame] | 488 | |
| 489 | " unpack assignment |
| 490 | let [a, b, c] =<< END |
| 491 | x |
| 492 | \y |
| 493 | z |
| 494 | END |
| 495 | call assert_equal([' x', ' \y', ' z'], [a, b, c]) |
Bram Moolenaar | f5842c5 | 2019-05-19 18:41:26 +0200 | [diff] [blame] | 496 | endfunc |
Bram Moolenaar | 8dfcce3 | 2020-03-18 19:32:26 +0100 | [diff] [blame] | 497 | |
| 498 | " vim: shiftwidth=2 sts=2 expandtab |