robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1-- Test for various eval features. 2 3local t =require ( 'test.testutil' ) 4local n =require ( 'test.functional.testnvim' )() 5 6local describe , it , before_each , setup , teardown = 7t . describe , t . it , t . before_each , t . setup , t . teardown 8local assert_alive =n . assert_alive 9local feed , insert , source =n . feed , n . insert , n . source 10local clear , command , expect =n . clear , n . command , n . expect 11local eq , eval , write_file =t . eq , n . eval , t . write_file 12local poke_eventloop =n . poke_eventloop 13local dedent =t . dedent 14local pcall_err =t . pcall_err 15 16describe ( 'eval' , function () 17setup ( function () 18write_file ( 19'test_eval_setup.vim' , 20[[ 21set noswapfile 22lang C 23 24fun AppendRegContents(reg) 25call AppendRegParts(a:reg, getregtype(a:reg), getreg(a:reg), string(getreg(a:reg, 0, 1)), getreg(a:reg, 1), string(getreg(a:reg, 1, 1))) 26endfun 27 28fun AppendRegParts(reg, type, cont, strcont, cont1, strcont1) 29call append('$', printf('%s: type %s; value: %s (%s), expr: %s (%s)', a:reg, a:type, a:cont, a:strcont, a:cont1, a:strcont1)) 30endfun 31 32command -nargs=? AR :call AppendRegContents(<q-args>) 33 34fun SetReg(...) 35call call('setreg', a:000) 36call append('$', printf('{{{2 setreg(%s)', string(a:000)[1:-2])) 37call AppendRegContents(a:1) 38if a:1 isnot# '=' 39execute "silent normal! Go==\n==\e\"".a:1."P" 40endif 41endfun 42]] 43) 44end ) 45before_each ( clear ) 46teardown ( function () 47os . remove ( 'test_eval_setup.vim' ) 48end ) 49 50it ( ':let' , function () 51command ( 'so test_eval_setup.vim' ) 52command ( [[let @" = 'abc']] ) 53command ( 'AR "' ) 54command ( [[let @" = "abc\n"]] ) 55source ( 'AR "' ) 56command ( [[let @" = "abc\<C-m>"]] ) 57command ( 'AR "' ) 58command ( [[let @= = '"abc"']] ) 59command ( 'AR =' ) 60expect ( [[ 61 62": type v; value: abc (['abc']), expr: abc (['abc']) 63": type V; value: abc]] .. "\000 (['abc']), expr: abc\000" .. [[ (['abc']) 64": type V; value: abc]] .. "\r\000 (['abc\r']), expr: abc\r\000 (['abc\r" .. [[']) 65=: type v; value: abc (['abc']), expr: "abc" (['"abc"'])]] ) 66end ) 67 68it ( 'basic setreg() tests' , function () 69command ( 'so test_eval_setup.vim' ) 70insert ( '{{{1 Basic setreg tests' ) 71command ( [[call SetReg('a', 'abcA', 'c')]] ) 72command ( [[call SetReg('b', 'abcB', 'v')]] ) 73command ( [[call SetReg('c', 'abcC', 'l')]] ) 74command ( [[call SetReg('d', 'abcD', 'V')]] ) 75command ( [[call SetReg('e', 'abcE', 'b')]] ) 76command ( [[call SetReg('f', 'abcF', "\<C-v>")]] ) 77command ( [[call SetReg('g', 'abcG', 'b10')]] ) 78command ( [[call SetReg('h', 'abcH', "\<C-v>10")]] ) 79command ( [[call SetReg('I', 'abcI')]] ) 80 81feed ( 'Go{{{1 Appending single lines with setreg()<esc>' ) 82poke_eventloop () 83command ( [[call SetReg('A', 'abcAc', 'c')]] ) 84command ( [[call SetReg('A', 'abcAl', 'l')]] ) 85command ( [[call SetReg('A', 'abcAc2','c')]] ) 86command ( [[call SetReg('b', 'abcBc', 'ca')]] ) 87command ( [[call SetReg('b', 'abcBb', 'ba')]] ) 88command ( [[call SetReg('b', 'abcBc2','ca')]] ) 89command ( [[call SetReg('b', 'abcBb2','b50a')]] ) 90command ( [[call SetReg('C', 'abcCl', 'l')]] ) 91command ( [[call SetReg('C', 'abcCc', 'c')]] ) 92command ( [[call SetReg('D', 'abcDb', 'b')]] ) 93command ( [[call SetReg('E', 'abcEb', 'b')]] ) 94command ( [[call SetReg('E', 'abcEl', 'l')]] ) 95command ( [[call SetReg('F', 'abcFc', 'c')]] ) 96expect ( [[ 97{{{1 Basic setreg tests 98{{{2 setreg('a', 'abcA', 'c') 99a: type v; value: abcA (['abcA']), expr: abcA (['abcA']) 100== 101=abcA= 102{{{2 setreg('b', 'abcB', 'v') 103b: type v; value: abcB (['abcB']), expr: abcB (['abcB']) 104== 105=abcB= 106{{{2 setreg('c', 'abcC', 'l') 107c: type V; value: abcC]] .. "\000 (['abcC']), expr: abcC\000" .. [[ (['abcC']) 108== 109abcC 110== 111{{{2 setreg('d', 'abcD', 'V') 112d: type V; value: abcD]] .. "\000 (['abcD']), expr: abcD\000" .. [[ (['abcD']) 113== 114abcD 115== 116{{{2 setreg('e', 'abcE', 'b') 117e: type ]] .. '\022' .. [[4; value: abcE (['abcE']), expr: abcE (['abcE']) 118== 119=abcE= 120{{{2 setreg('f', 'abcF', ']] .. '\022' .. [[') 121f: type ]] .. '\022' .. [[4; value: abcF (['abcF']), expr: abcF (['abcF']) 122== 123=abcF= 124{{{2 setreg('g', 'abcG', 'b10') 125g: type ]] .. '\022' .. [[10; value: abcG (['abcG']), expr: abcG (['abcG']) 126== 127=abcG = 128{{{2 setreg('h', 'abcH', ']] .. '\022' .. [[10') 129h: type ]] .. '\022' .. [[10; value: abcH (['abcH']), expr: abcH (['abcH']) 130== 131=abcH = 132{{{2 setreg('I', 'abcI') 133I: type v; value: abcI (['abcI']), expr: abcI (['abcI']) 134== 135=abcI= 136{{{1 Appending single lines with setreg() 137{{{2 setreg('A', 'abcAc', 'c') 138A: type v; value: abcAabcAc (['abcAabcAc']), expr: abcAabcAc (['abcAabcAc']) 139== 140=abcAabcAc= 141{{{2 setreg('A', 'abcAl', 'l') 142A: type V; value: abcAabcAcabcAl]] .. "\000 (['abcAabcAcabcAl']), expr: abcAabcAcabcAl\000" .. [[ (['abcAabcAcabcAl']) 143== 144abcAabcAcabcAl 145== 146{{{2 setreg('A', 'abcAc2', 'c') 147A: type v; value: abcAabcAcabcAl]] .. "\000abcAc2 (['abcAabcAcabcAl', 'abcAc2']), expr: abcAabcAcabcAl\000" .. [[abcAc2 (['abcAabcAcabcAl', 'abcAc2']) 148== 149=abcAabcAcabcAl 150abcAc2= 151{{{2 setreg('b', 'abcBc', 'ca') 152b: type v; value: abcBabcBc (['abcBabcBc']), expr: abcBabcBc (['abcBabcBc']) 153== 154=abcBabcBc= 155{{{2 setreg('b', 'abcBb', 'ba') 156b: type ]] .. '\022' .. [[5; value: abcBabcBcabcBb (['abcBabcBcabcBb']), expr: abcBabcBcabcBb (['abcBabcBcabcBb']) 157== 158=abcBabcBcabcBb= 159{{{2 setreg('b', 'abcBc2', 'ca') 160b: type v; value: abcBabcBcabcBb]] .. "\000abcBc2 (['abcBabcBcabcBb', 'abcBc2']), expr: abcBabcBcabcBb\000" .. [[abcBc2 (['abcBabcBcabcBb', 'abcBc2']) 161== 162=abcBabcBcabcBb 163abcBc2= 164{{{2 setreg('b', 'abcBb2', 'b50a') 165b: type ]] .. "\02250; value: abcBabcBcabcBb\000abcBc2abcBb2 (['abcBabcBcabcBb', 'abcBc2abcBb2']), expr: abcBabcBcabcBb\000" .. [[abcBc2abcBb2 (['abcBabcBcabcBb', 'abcBc2abcBb2']) 166== 167=abcBabcBcabcBb = 168abcBc2abcBb2 169{{{2 setreg('C', 'abcCl', 'l') 170C: type V; value: abcC]] .. "\000abcCl\000 (['abcC', 'abcCl']), expr: abcC\000abcCl\000" .. [[ (['abcC', 'abcCl']) 171== 172abcC 173abcCl 174== 175{{{2 setreg('C', 'abcCc', 'c') 176C: type v; value: abcC]] .. "\000abcCl\000abcCc (['abcC', 'abcCl', 'abcCc']), expr: abcC\000abcCl\000" .. [[abcCc (['abcC', 'abcCl', 'abcCc']) 177== 178=abcC 179abcCl 180abcCc= 181{{{2 setreg('D', 'abcDb', 'b') 182D: type ]] .. "\0225; value: abcD\000abcDb (['abcD', 'abcDb']), expr: abcD\000" .. [[abcDb (['abcD', 'abcDb']) 183== 184=abcD = 185abcDb 186{{{2 setreg('E', 'abcEb', 'b') 187E: type ]] .. "\0225; value: abcE\000abcEb (['abcE', 'abcEb']), expr: abcE\000" .. [[abcEb (['abcE', 'abcEb']) 188== 189=abcE = 190abcEb 191{{{2 setreg('E', 'abcEl', 'l') 192E: type V; value: abcE]] .. "\000abcEb\000abcEl\000 (['abcE', 'abcEb', 'abcEl']), expr: abcE\000abcEb\000abcEl\000" .. [[ (['abcE', 'abcEb', 'abcEl']) 193== 194abcE 195abcEb 196abcEl 197== 198{{{2 setreg('F', 'abcFc', 'c') 199F: type v; value: abcF]] .. "\000abcFc (['abcF', 'abcFc']), expr: abcF\000" .. [[abcFc (['abcF', 'abcFc']) 200== 201=abcF 202abcFc=]] ) 203end ) 204 205-- luacheck: ignore 611 (Line contains only whitespace) 206it ( 'appending NL with setreg()' , function () 207command ( 'so test_eval_setup.vim' ) 208 209command ( [[call setreg('a', 'abcA2', 'c')]] ) 210command ( [[call setreg('b', 'abcB2', 'v')]] ) 211command ( [[call setreg('c', 'abcC2', 'l')]] ) 212command ( [[call setreg('d', 'abcD2', 'V')]] ) 213command ( [[call setreg('e', 'abcE2', 'b')]] ) 214command ( [[call setreg('f', 'abcF2', "\<C-v>")]] ) 215-- These registers where set like this in the old test_eval.in but never 216-- copied to the output buffer with SetReg(). They do not appear in 217-- test_eval.ok. Therefore they are commented out. 218--execute([[call setreg('g', 'abcG2', 'b10')]]) 219--execute([[call setreg('h', 'abcH2', "\<C-v>10")]]) 220--execute([[call setreg('I', 'abcI2')]]) 221 222command ( [[call SetReg('A', "\n")]] ) 223command ( [[call SetReg('B', "\n", 'c')]] ) 224command ( [[call SetReg('C', "\n")]] ) 225command ( [[call SetReg('D', "\n", 'l')]] ) 226command ( [[call SetReg('E', "\n")]] ) 227command ( [[call SetReg('F', "\n", 'b')]] ) 228command ( "$put ='.'" ) 229expect ( [[ 230 231{{{2 setreg('A', ']] .. '\000' .. [[') 232A: type V; value: abcA2]] .. "\000 (['abcA2']), expr: abcA2\000" .. [[ (['abcA2']) 233== 234abcA2 235== 236{{{2 setreg('B', ']] .. '\000' .. [[', 'c') 237B: type v; value: abcB2]] .. "\000 (['abcB2', '']), expr: abcB2\000" .. [[ (['abcB2', '']) 238== 239=abcB2 240= 241{{{2 setreg('C', ']] .. '\000' .. [[') 242C: type V; value: abcC2]] .. "\000\000 (['abcC2', '']), expr: abcC2\000\000" .. [[ (['abcC2', '']) 243== 244abcC2 245 246== 247{{{2 setreg('D', ']] .. '\000' .. [[', 'l') 248D: type V; value: abcD2]] .. "\000\000 (['abcD2', '']), expr: abcD2\000\000" .. [[ (['abcD2', '']) 249== 250abcD2 251 252== 253{{{2 setreg('E', ']] .. '\000' .. [[') 254E: type V; value: abcE2]] .. "\000\000 (['abcE2', '']), expr: abcE2\000\000" .. [[ (['abcE2', '']) 255== 256abcE2 257 258== 259{{{2 setreg('F', ']] .. '\000' .. [[', 'b') 260F: type ]] .. "\0220; value: abcF2\000 (['abcF2', '']), expr: abcF2\000" .. [[ (['abcF2', '']) 261== 262=abcF2= 263264 .]] ) 265end ) 266 267it ( 'setting and appending list with setreg()' , function () 268command ( 'so test_eval_setup.vim' ) 269 270command ( [[$put ='{{{1 Setting lists with setreg()']] ) 271command ( [=[call SetReg('a', ['abcA3'], 'c')]=] ) 272command ( [=[call SetReg('b', ['abcB3'], 'l')]=] ) 273command ( [=[call SetReg('c', ['abcC3'], 'b')]=] ) 274command ( [=[call SetReg('d', ['abcD3'])]=] ) 275command ( [=[call SetReg('e', [1, 2, 'abc', 3])]=] ) 276command ( [=[call SetReg('f', [1, 2, 3])]=] ) 277 278command ( [[$put ='{{{1 Appending lists with setreg()']] ) 279command ( [=[call SetReg('A', ['abcA3c'], 'c')]=] ) 280command ( [=[call SetReg('b', ['abcB3l'], 'la')]=] ) 281command ( [=[call SetReg('C', ['abcC3b'], 'lb')]=] ) 282command ( [=[call SetReg('D', ['abcD32'])]=] ) 283command ( [=[call SetReg('A', ['abcA32'])]=] ) 284command ( [=[call SetReg('B', ['abcB3c'], 'c')]=] ) 285command ( [=[call SetReg('C', ['abcC3l'], 'l')]=] ) 286command ( [=[call SetReg('D', ['abcD3b'], 'b')]=] ) 287expect ( [[ 288 289{{{1 Setting lists with setreg() 290{{{2 setreg('a', ['abcA3'], 'c') 291a: type v; value: abcA3 (['abcA3']), expr: abcA3 (['abcA3']) 292== 293=abcA3= 294{{{2 setreg('b', ['abcB3'], 'l') 295b: type V; value: abcB3]] .. "\000 (['abcB3']), expr: abcB3\000" .. [[ (['abcB3']) 296== 297abcB3 298== 299{{{2 setreg('c', ['abcC3'], 'b') 300c: type ]] .. '\022' .. [[5; value: abcC3 (['abcC3']), expr: abcC3 (['abcC3']) 301== 302=abcC3= 303{{{2 setreg('d', ['abcD3']) 304d: type V; value: abcD3]] .. "\000 (['abcD3']), expr: abcD3\000" .. [[ (['abcD3']) 305== 306abcD3 307== 308{{{2 setreg('e', [1, 2, 'abc', 3]) 309e: type V; value: 1]] .. "\0002\000abc\0003\000 (['1', '2', 'abc', '3']), expr: 1\0002\000abc\0003\000" .. [[ (['1', '2', 'abc', '3']) 310== 3111 3122 313abc 3143 315== 316{{{2 setreg('f', [1, 2, 3]) 317f: type V; value: 1]] .. "\0002\0003\000 (['1', '2', '3']), expr: 1\0002\0003\000" .. [[ (['1', '2', '3']) 318== 3191 3202 3213 322== 323{{{1 Appending lists with setreg() 324{{{2 setreg('A', ['abcA3c'], 'c') 325A: type v; value: abcA3]] .. "\000abcA3c (['abcA3', 'abcA3c']), expr: abcA3\000" .. [[abcA3c (['abcA3', 'abcA3c']) 326== 327=abcA3 328abcA3c= 329{{{2 setreg('b', ['abcB3l'], 'la') 330b: type V; value: abcB3]] .. "\000abcB3l\000 (['abcB3', 'abcB3l']), expr: abcB3\000abcB3l\000" .. [[ (['abcB3', 'abcB3l']) 331== 332abcB3 333abcB3l 334== 335{{{2 setreg('C', ['abcC3b'], 'lb') 336C: type ]] .. "\0226; value: abcC3\000abcC3b (['abcC3', 'abcC3b']), expr: abcC3\000" .. [[abcC3b (['abcC3', 'abcC3b']) 337== 338=abcC3 = 339abcC3b 340{{{2 setreg('D', ['abcD32']) 341D: type V; value: abcD3]] .. "\000abcD32\000 (['abcD3', 'abcD32']), expr: abcD3\000abcD32\000" .. [[ (['abcD3', 'abcD32']) 342== 343abcD3 344abcD32 345== 346{{{2 setreg('A', ['abcA32']) 347A: type V; value: abcA3]] .. "\000abcA3c\000abcA32\000 (['abcA3', 'abcA3c', 'abcA32']), expr: abcA3\000abcA3c\000abcA32\000" .. [[ (['abcA3', 'abcA3c', 'abcA32']) 348== 349abcA3 350abcA3c 351abcA32 352== 353{{{2 setreg('B', ['abcB3c'], 'c') 354B: type v; value: abcB3]] .. "\000abcB3l\000abcB3c (['abcB3', 'abcB3l', 'abcB3c']), expr: abcB3\000abcB3l\000" .. [[abcB3c (['abcB3', 'abcB3l', 'abcB3c']) 355== 356=abcB3 357abcB3l 358abcB3c= 359{{{2 setreg('C', ['abcC3l'], 'l') 360C: type V; value: abcC3]] .. "\000abcC3b\000abcC3l\000 (['abcC3', 'abcC3b', 'abcC3l']), expr: abcC3\000abcC3b\000abcC3l\000" .. [[ (['abcC3', 'abcC3b', 'abcC3l']) 361== 362abcC3 363abcC3b 364abcC3l 365== 366{{{2 setreg('D', ['abcD3b'], 'b') 367D: type ]] .. "\0226; value: abcD3\000abcD32\000abcD3b (['abcD3', 'abcD32', 'abcD3b']), expr: abcD3\000abcD32\000" .. [[abcD3b (['abcD3', 'abcD32', 'abcD3b']) 368== 369=abcD3 = 370abcD32 371abcD3b]] ) 372 373-- From now on we delete the buffer contents after each expect() to make 374-- the next expect() easier to write. This is necessary because null 375-- bytes on a line by itself don't play well together with the dedent 376-- function used in expect(). 377command ( '%delete' ) 378command ( [[$put ='{{{1 Appending lists with NL with setreg()']] ) 379command ( [=[call SetReg('A', ["\n", 'abcA3l2'], 'l')]=] ) 380expect ( 381'\n' 382.. '{{{1 Appending lists with NL with setreg()\n' 383.. "{{{2 setreg('A', ['\000', 'abcA3l2'], 'l')\n" 384.. "A: type V; value: abcA3\000abcA3c\000abcA32\000\000\000abcA3l2\000 (['abcA3', 'abcA3c', 'abcA32', '\000', 'abcA3l2']), expr: abcA3\000abcA3c\000abcA32\000\000\000abcA3l2\000 (['abcA3', 'abcA3c', 'abcA32', '\000', 'abcA3l2'])\n" 385.. '==\n' 386.. 'abcA3\n' 387.. 'abcA3c\n' 388.. 'abcA32\n' 389.. '\000\n' 390.. 'abcA3l2\n' 391.. '==' 392) 393command ( '%delete' ) 394command ( [=[call SetReg('B', ["\n", 'abcB3c2'], 'c')]=] ) 395expect ( 396'\n' 397.. "{{{2 setreg('B', ['\000', 'abcB3c2'], 'c')\n" 398.. "B: type v; value: abcB3\000abcB3l\000abcB3c\000\000\000abcB3c2 (['abcB3', 'abcB3l', 'abcB3c', '\000', 'abcB3c2']), expr: abcB3\000abcB3l\000abcB3c\000\000\000abcB3c2 (['abcB3', 'abcB3l', 'abcB3c', '\000', 'abcB3c2'])\n" 399.. '==\n' 400.. '=abcB3\n' 401.. 'abcB3l\n' 402.. 'abcB3c\n' 403.. '\000\n' 404.. 'abcB3c2=' 405) 406command ( '%delete' ) 407command ( [=[call SetReg('C', ["\n", 'abcC3b2'], 'b')]=] ) 408expect ( 409'\n' 410.. "{{{2 setreg('C', ['\000', 'abcC3b2'], 'b')\n" 411.. "C: type \0227; value: abcC3\000abcC3b\000abcC3l\000\000\000abcC3b2 (['abcC3', 'abcC3b', 'abcC3l', '\000', 'abcC3b2']), expr: abcC3\000abcC3b\000abcC3l\000\000\000abcC3b2 (['abcC3', 'abcC3b', 'abcC3l', '\000', 'abcC3b2'])\n" 412.. '==\n' 413.. '=abcC3 =\n' 414.. ' abcC3b\n' 415.. ' abcC3l\n' 416.. ' \000\n' 417.. ' abcC3b2' 418) 419command ( '%delete' ) 420command ( [=[call SetReg('D', ["\n", 'abcD3b50'],'b50')]=] ) 421expect ( 422'\n' 423.. "{{{2 setreg('D', ['\000', 'abcD3b50'], 'b50')\n" 424.. "D: type \02250; value: abcD3\000abcD32\000abcD3b\000\000\000abcD3b50 (['abcD3', 'abcD32', 'abcD3b', '\000', 'abcD3b50']), expr: abcD3\000abcD32\000abcD3b\000\000\000abcD3b50 (['abcD3', 'abcD32', 'abcD3b', '\000', 'abcD3b50'])\n" 425.. '==\n' 426.. '=abcD3 =\n' 427.. ' abcD32\n' 428.. ' abcD3b\n' 429.. ' \000\n' 430.. ' abcD3b50' 431) 432end ) 433 434-- The tests for setting lists with NLs are split into separate it() blocks 435-- to make the expect() calls easier to write. Otherwise the null byte can 436-- make trouble on a line on its own. 437it ( 'setting lists with NLs with setreg(), part 1' , function () 438command ( 'so test_eval_setup.vim' ) 439command ( 440[=[call SetReg('a', ['abcA4-0', "\n", "abcA4-2\n", "\nabcA4-3", "abcA4-4\nabcA4-4-2"])]=] 441) 442expect ( 443'\n' 444.. "{{{2 setreg('a', ['abcA4-0', '\000', 'abcA4-2\000', '\000abcA4-3', 'abcA4-4\000abcA4-4-2'])\n" 445.. "a: type V; value: abcA4-0\000\000\000abcA4-2\000\000\000abcA4-3\000abcA4-4\000abcA4-4-2\000 (['abcA4-0', '\000', 'abcA4-2\000', '\000abcA4-3', 'abcA4-4\000abcA4-4-2']), expr: abcA4-0\000\000\000abcA4-2\000\000\000abcA4-3\000abcA4-4\000abcA4-4-2\000 (['abcA4-0', '\000', 'abcA4-2\000', '\000abcA4-3', 'abcA4-4\000abcA4-4-2'])\n" 446.. '==\n' 447.. 'abcA4-0\n' 448.. '\000\n' 449.. 'abcA4-2\000\n' 450.. '\000abcA4-3\n' 451.. 'abcA4-4\000abcA4-4-2\n' 452.. '==' 453) 454end ) 455 456it ( 'setting lists with NLs with setreg(), part 2' , function () 457command ( 'so test_eval_setup.vim' ) 458command ( 459[=[call SetReg('b', ['abcB4c-0', "\n", "abcB4c-2\n", "\nabcB4c-3", "abcB4c-4\nabcB4c-4-2"], 'c')]=] 460) 461expect ( 462'\n' 463.. "{{{2 setreg('b', ['abcB4c-0', '\000', 'abcB4c-2\000', '\000abcB4c-3', 'abcB4c-4\000abcB4c-4-2'], 'c')\n" 464.. "b: type v; value: abcB4c-0\000\000\000abcB4c-2\000\000\000abcB4c-3\000abcB4c-4\000abcB4c-4-2 (['abcB4c-0', '\000', 'abcB4c-2\000', '\000abcB4c-3', 'abcB4c-4\000abcB4c-4-2']), expr: abcB4c-0\000\000\000abcB4c-2\000\000\000abcB4c-3\000abcB4c-4\000abcB4c-4-2 (['abcB4c-0', '\000', 'abcB4c-2\000', '\000abcB4c-3', 'abcB4c-4\000abcB4c-4-2'])\n" 465.. '==\n' 466.. '=abcB4c-0\n' 467.. '\000\n' 468.. 'abcB4c-2\000\n' 469.. '\000abcB4c-3\n' 470.. 'abcB4c-4\000abcB4c-4-2=' 471) 472end ) 473 474it ( 'setting lists with NLs with setreg(), part 3' , function () 475command ( 'so test_eval_setup.vim' ) 476command ( 477[=[call SetReg('c', ['abcC4l-0', "\n", "abcC4l-2\n", "\nabcC4l-3", "abcC4l-4\nabcC4l-4-2"], 'l')]=] 478) 479expect ( 480'\n' 481.. "{{{2 setreg('c', ['abcC4l-0', '\000', 'abcC4l-2\000', '\000abcC4l-3', 'abcC4l-4\000abcC4l-4-2'], 'l')\n" 482.. "c: type V; value: abcC4l-0\000\000\000abcC4l-2\000\000\000abcC4l-3\000abcC4l-4\000abcC4l-4-2\000 (['abcC4l-0', '\000', 'abcC4l-2\000', '\000abcC4l-3', 'abcC4l-4\000abcC4l-4-2']), expr: abcC4l-0\000\000\000abcC4l-2\000\000\000abcC4l-3\000abcC4l-4\000abcC4l-4-2\000 (['abcC4l-0', '\000', 'abcC4l-2\000', '\000abcC4l-3', 'abcC4l-4\000abcC4l-4-2'])\n" 483.. '==\n' 484.. 'abcC4l-0\n' 485.. '\000\n' 486.. 'abcC4l-2\000\n' 487.. '\000abcC4l-3\n' 488.. 'abcC4l-4\000abcC4l-4-2\n' 489.. '==' 490) 491end ) 492it ( 'setting lists with NLs with setreg(), part 4' , function () 493command ( 'so test_eval_setup.vim' ) 494command ( 495[=[call SetReg('d', ['abcD4b-0', "\n", "abcD4b-2\n", "\nabcD4b-3", "abcD4b-4\nabcD4b-4-2"], 'b')]=] 496) 497expect ( 498'\n' 499.. "{{{2 setreg('d', ['abcD4b-0', '\000', 'abcD4b-2\000', '\000abcD4b-3', 'abcD4b-4\000abcD4b-4-2'], 'b')\n" 500.. "d: type \02219; value: abcD4b-0\000\000\000abcD4b-2\000\000\000abcD4b-3\000abcD4b-4\000abcD4b-4-2 (['abcD4b-0', '\000', 'abcD4b-2\000', '\000abcD4b-3', 'abcD4b-4\000abcD4b-4-2']), expr: abcD4b-0\000\000\000abcD4b-2\000\000\000abcD4b-3\000abcD4b-4\000abcD4b-4-2 (['abcD4b-0', '\000', 'abcD4b-2\000', '\000abcD4b-3', 'abcD4b-4\000abcD4b-4-2'])\n" 501.. '==\n' 502.. '=abcD4b-0 =\n' 503.. ' \000\n' 504.. ' abcD4b-2\000\n' 505.. ' \000abcD4b-3\n' 506.. ' abcD4b-4\000abcD4b-4-2' 507) 508end ) 509it ( 'setting lists with NLs with setreg(), part 5' , function () 510command ( 'so test_eval_setup.vim' ) 511command ( 512[=[call SetReg('e', ['abcE4b10-0', "\n", "abcE4b10-2\n", "\nabcE4b10-3", "abcE4b10-4\nabcE4b10-4-2"], 'b10')]=] 513) 514expect ( 515'\n' 516.. "{{{2 setreg('e', ['abcE4b10-0', '\000', 'abcE4b10-2\000', '\000abcE4b10-3', 'abcE4b10-4\000abcE4b10-4-2'], 'b10')\n" 517.. "e: type \02210; value: abcE4b10-0\000\000\000abcE4b10-2\000\000\000abcE4b10-3\000abcE4b10-4\000abcE4b10-4-2 (['abcE4b10-0', '\000', 'abcE4b10-2\000', '\000abcE4b10-3', 'abcE4b10-4\000abcE4b10-4-2']), expr: abcE4b10-0\000\000\000abcE4b10-2\000\000\000abcE4b10-3\000abcE4b10-4\000abcE4b10-4-2 (['abcE4b10-0', '\000', 'abcE4b10-2\000', '\000abcE4b10-3', 'abcE4b10-4\000abcE4b10-4-2'])\n" 518.. '==\n' 519.. '=abcE4b10-0=\n' 520.. ' \000\n' 521.. ' abcE4b10-2\000\n' 522.. ' \000abcE4b10-3\n' 523.. ' abcE4b10-4\000abcE4b10-4-2' 524) 525end ) 526 527it ( 'setting register with grahpeme clusters in block mode' , function () 528command ( "call setreg('a', ['🇧🇷'], 'b')" ) 529eq ( '\0222' , eval ( "getregtype('a')" )) 530 531command ( "call setreg('b', '🇧🇷', 'b')" ) 532eq ( '\0222' , eval ( "getregtype('b')" )) 533end ) 534 535it ( 'getreg("a",1,1) returns a valid list when "a is unset' , function () 536-- Precondition: "a is actually unset and "0 is nonempty 537eq ( '' , eval ( "getregtype('a')" )) 538eq ( '' , eval ( "getreg('a')" )) 539command ( "call setreg('0','text')" ) 540 541-- This used to return a NULL list 542-- which setreg didn't handle 543command ( "let x = getreg('a',1,1)" ) 544command ( "call setreg('0',x)" ) 545 546-- nvim didn't crash and "0 was emptied 547assert_alive () 548eq ( {} , eval ( "getreg('0',1,1)" )) 549 550-- x is a mutable list 551command ( 'let y = x' ) 552eq ( {} , eval ( 'y' )) 553command ( "call add(x, 'item')" ) 554eq ( { 'item' } , eval ( 'y' )) 555end ) 556 557it ( 'sets the unnamed register when the "u" option is passed to setreg' , function () 558command ( "call setreg('a','a reg', 'cu')" ) 559eq ( 'a reg' , eval ( '@"' )) 560command ( "call setreg('b','b reg', 'cu')" ) 561eq ( 'b reg' , eval ( '@"' )) 562command ( "call setreg('c','c reg', 'c')" ) 563eq ( 'b reg' , eval ( '@"' )) 564end ) 565 566it ( 'search and expressions' , function () 567command ( 'so test_eval_setup.vim' ) 568command ( [=[call SetReg('/', ['abc/'])]=] ) 569command ( [=[call SetReg('/', ["abc/\n"])]=] ) 570command ( [=[call SetReg('=', ['"abc/"'])]=] ) 571command ( [=[call SetReg('=', ["\"abc/\n\""])]=] ) 572expect ( 573[[ 574 575{{{2 setreg('/', ['abc/']) 576/: type v; value: abc/ (['abc/']), expr: abc/ (['abc/']) 577== 578=abc/= 579{{{2 setreg('/', ['abc/]] 580.. '\000' 581.. [[']) 582/: type v; value: abc/]] 583.. "\000 (['abc/\000']), expr: abc/\000 (['abc/\000" 584.. [[']) 585== 586=abc/]] 587.. '\000' 588.. [[= 589{{{2 setreg('=', ['"abc/"']) 590=: type v; value: abc/ (['abc/']), expr: "abc/" (['"abc/"']) 591{{{2 setreg('=', ['"abc/]] 592.. '\000' 593.. [["']) 594=: type v; value: abc/]] 595.. "\000 (['abc/\000" 596.. [[']), expr: "abc/]] 597.. '\000' 598.. [[" (['"abc/]] 599.. '\000' 600.. [["'])]] 601) 602end ) 603 604describe ( 'system clipboard' , function () 605before_each ( function () 606command ( 'let &runtimepath = "test/functional/fixtures,".&runtimepath' ) 607command ( 'call getreg("*")' ) -- force load of provider 608end ) 609 610it ( 'works' , function () 611insert ( [[ 612Some first line (this text was at the top of the old test_eval.in). 613 614Note: system clipboard is saved, changed and restored. 615 616clipboard contents 617something else]] ) 618command ( 'so test_eval_setup.vim' ) 619-- Save and restore system clipboard. 620command ( "let _clipreg = ['*', getreg('*'), getregtype('*')]" ) 621command ( 'let _clipopt = &cb' ) 622command ( "let &cb='unnamed'" ) 623command ( '5y' ) 624command ( 'AR *' ) 625command ( 'tabdo :windo :echo "hi"' ) 626command ( '6y' ) 627command ( 'AR *' ) 628command ( 'let &cb=_clipopt' ) 629command ( "call call('setreg', _clipreg)" ) 630expect ( 631[[ 632Some first line (this text was at the top of the old test_eval.in). 633 634Note: system clipboard is saved, changed and restored. 635 636clipboard contents 637something else 638*: type V; value: clipboard contents]] 639.. '\00' 640.. [[ (['clipboard contents']), expr: clipboard contents]] 641.. '\00' 642.. [[ (['clipboard contents']) 643*: type V; value: something else]] 644.. '\00' 645.. [[ (['something else']), expr: something else]] 646.. '\00' 647.. [[ (['something else'])]] 648) 649end ) 650end ) 651 652it ( 'errors' , function () 653source ( [[ 654fun ErrExe(str) 655call append('$', 'Executing '.a:str) 656try 657execute a:str 658catch 659$put =v:exception 660endtry 661endfun]] ) 662command ( [[call ErrExe('call setreg()')]] ) 663command ( [[call ErrExe('call setreg(1)')]] ) 664command ( [[call ErrExe('call setreg(1, 2, 3, 4)')]] ) 665command ( [=[call ErrExe('call setreg([], 2)')]=] ) 666command ( [=[call ErrExe('call setreg(1, 2, [])')]=] ) 667command ( [=[call ErrExe('call setreg("/", ["1", "2"])')]=] ) 668command ( [=[call ErrExe('call setreg("=", ["1", "2"])')]=] ) 669command ( [=[call ErrExe('call setreg(1, ["", "", [], ""])')]=] ) 670expect ( [[ 671 672Executing call setreg() 673Vim(call):E119: Not enough arguments for function: setreg 674Executing call setreg(1) 675Vim(call):E119: Not enough arguments for function: setreg 676Executing call setreg(1, 2, 3, 4) 677Vim(call):E118: Too many arguments for function: setreg 678Executing call setreg([], 2) 679Vim(call):E730: Using a List as a String 680Executing call setreg(1, 2, []) 681Vim(call):E730: Using a List as a String 682Executing call setreg("/", ["1", "2"]) 683Vim(call):E883: Register '/' cannot contain multiple lines 684Executing call setreg("=", ["1", "2"]) 685Vim(call):E883: Register '=' cannot contain multiple lines 686Executing call setreg(1, ["", "", [], ""]) 687Vim(call):E730: Using a List as a String]] ) 688end ) 689 690it ( 'function name not starting with a capital' , function () 691eq ( 692'Vim(function):E128: Function name must start with a capital or "s:": g:test()\nendfunction' , 693t . pcall_err ( 694command , 695dedent ( [[ 696function! g:test() 697endfunction]] ) 698) 699) 700end ) 701 702it ( 'Function name followed by #' , function () 703eq ( 704'Vim(function):E128: Function name must start with a capital or "s:": test2() "#\nendfunction' , 705t . pcall_err ( 706command , 707dedent ( [[ 708function! test2() "# 709endfunction]] ) 710) 711) 712end ) 713 714it ( 'function name includes a colon' , function () 715eq ( 716'Vim(function):E884: Function name cannot contain a colon: b:test()\nendfunction' , 717t . pcall_err ( 718command , 719dedent ( [[ 720function! b:test() 721endfunction]] ) 722) 723) 724end ) 725 726it ( 'function name starting with/without "g:", buffer-local funcref' , function () 727command ( [[ 728function! g:Foo(n) 729$put ='called Foo(' . a:n . ')' 730endfunction 731]] ) 732command ( "let b:my_func = function('Foo')" ) 733command ( 'call b:my_func(1)' ) 734command ( 'echo g:Foo(2)' ) 735command ( 'echo Foo(3)' ) 736expect ( [[ 737 738called Foo(1) 739called Foo(2) 740called Foo(3)]] ) 741end ) 742 743it ( 'script-local function used in Funcref must exist' , function () 744source ( [[ 745" Vim script used in test_eval.in. Needed for script-local function. 746 747func s:Testje() 748return "foo" 749endfunc 750 751let Bar = function('s:Testje') 752 753$put ='s:Testje exists: ' . exists('s:Testje') 754$put ='func s:Testje exists: ' . exists('*s:Testje') 755$put ='Bar exists: ' . exists('Bar') 756$put ='func Bar exists: ' . exists('*Bar') 757]] ) 758expect ( [[ 759 760s:Testje exists: 0 761func s:Testje exists: 1 762Bar exists: 1 763func Bar exists: 1]] ) 764end ) 765 766it ( "using $ instead of '$' must give an error" , function () 767eq ( 768'Vim(call):E116: Invalid arguments for function append' , 769t . pcall_err ( command , 'call append($, "foobar")' ) 770) 771end ) 772 773it ( 'getcurpos/setpos' , function () 774insert ( [[ 775012345678 776012345678 777 778start:]] ) 779command ( '/^012345678' ) 780feed ( '6l' ) 781poke_eventloop () 782command ( 'let sp = getcurpos()' ) 783feed ( '0' ) 784poke_eventloop () 785command ( "call setpos('.', sp)" ) 786feed ( 'jyl' ) 787poke_eventloop () 788command ( '$put' ) 789expect ( [[ 790012345678 791012345678 792 793start: 7946]] ) 795end ) 796 797it ( 'substring and variable name' , function () 798command ( "let str = 'abcdef'" ) 799command ( 'let n = 3' ) 800eq ( 'def' , eval ( 'str[n:]' )) 801eq ( 'abcd' , eval ( 'str[:n]' )) 802eq ( 'd' , eval ( 'str[n:n]' )) 803command ( 'unlet n' ) 804command ( 'let nn = 3' ) 805eq ( 'def' , eval ( 'str[nn:]' )) 806eq ( 'abcd' , eval ( 'str[:nn]' )) 807eq ( 'd' , eval ( 'str[nn:nn]' )) 808command ( 'unlet nn' ) 809command ( 'let b:nn = 4' ) 810eq ( 'ef' , eval ( 'str[b:nn:]' )) 811eq ( 'abcde' , eval ( 'str[:b:nn]' )) 812eq ( 'e' , eval ( 'str[b:nn:b:nn]' )) 813end ) 814end )