robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1local t =require ( 'test.testutil' ) 2local n =require ( 'test.functional.testnvim' )() 3 4local describe , it , before_each =t . describe , t . it , t . before_each 5local eq =t . eq 6local clear =n . clear 7local command =n . command 8local eval =n . eval 9local api =n . api 10local exec =n . exec 11local exec_capture =n . exec_capture 12local expect_exit =n . expect_exit 13local source =n . source 14local testprg =n . testprg 15 16before_each ( clear ) 17 18describe ( ':let' , function () 19it ( 'correctly lists variables with curly-braces' , function () 20api . nvim_set_var ( 'v' , { 0 } ) 21eq ( 'v [0]' , exec_capture ( 'let {"v"}' )) 22end ) 23 24it ( 'correctly lists variables with subscript' , function () 25api . nvim_set_var ( 'v' , { 0 } ) 26eq ( 'v[0] #0' , exec_capture ( 'let v[0]' )) 27eq ( 'g:["v"][0] #0' , exec_capture ( 'let g:["v"][0]' )) 28eq ( '{"g:"}["v"][0] #0' , exec_capture ( 'let {"g:"}["v"][0]' )) 29end ) 30 31it ( ':unlet self-referencing node in a List graph #6070' , function () 32-- :unlet-ing a self-referencing List must not allow GC on indirectly 33-- referenced in-scope Lists. Before #6070 this caused use-after-free. 34expect_exit ( 351000 , 36source , 37[=[ 38let [l1, l2] = [[], []] 39echo 'l1:' . id(l1) 40echo 'l2:' . id(l2) 41echo '' 42let [l3, l4] = [[], []] 43call add(l4, l4) 44call add(l4, l3) 45call add(l3, 1) 46call add(l2, l2) 47call add(l2, l1) 48call add(l1, 1) 49unlet l2 50unlet l4 51call garbagecollect(1) 52call feedkeys(":\e:echo l1 l3\n:echo 42\n:cq\n", "t") 53]=] 54) 55end ) 56 57it ( 'multibyte env var #8398 #9267' , function () 58command ( "let $NVIM_TEST_LET = 'AìaB'" ) 59eq ( 'AìaB' , eval ( '$NVIM_TEST_LET' )) 60command ( "let $NVIM_TEST_LET = 'AaあB'" ) 61eq ( 'AaあB' , eval ( '$NVIM_TEST_LET' )) 62local mbyte =[[\p* .ม .ม .ม .ม่ .ม่ .ม่ ֹ ֹ ֹ .ֹ .ֹ .ֹ ֹֻ ֹֻ ֹֻ 63.ֹֻ .ֹֻ .ֹֻ ֹֻ ֹֻ ֹֻ .ֹֻ .ֹֻ .ֹֻ ֹ ֹ ֹ .ֹ .ֹ .ֹ ֹ ֹ ֹ .ֹ .ֹ .ֹ ֹֻ ֹֻ 64.ֹֻ .ֹֻ .ֹֻ a a a ca ca ca à à à]] 65command ( "let $NVIM_TEST_LET = '" .. mbyte .. "'" ) 66eq ( mbyte , eval ( '$NVIM_TEST_LET' )) 67end ) 68 69it ( 'multibyte env var to child process #8398 #9267' , function () 70local cmd_get_child_env =( "let g:env_from_child = system(['%s', 'NVIM_TEST_LET'])" ): format ( 71testprg ( 'printenv-test' ) 72) 73command ( "let $NVIM_TEST_LET = 'AìaB'" ) 74command ( cmd_get_child_env ) 75eq ( eval ( '$NVIM_TEST_LET' ), eval ( 'g:env_from_child' )) 76 77command ( "let $NVIM_TEST_LET = 'AaあB'" ) 78command ( cmd_get_child_env ) 79eq ( eval ( '$NVIM_TEST_LET' ), eval ( 'g:env_from_child' )) 80 81local mbyte =[[\p* .ม .ม .ม .ม่ .ม่ .ม่ ֹ ֹ ֹ .ֹ .ֹ .ֹ ֹֻ ֹֻ ֹֻ 82.ֹֻ .ֹֻ .ֹֻ ֹֻ ֹֻ ֹֻ .ֹֻ .ֹֻ .ֹֻ ֹ ֹ ֹ .ֹ .ֹ .ֹ ֹ ֹ ֹ .ֹ .ֹ .ֹ ֹֻ ֹֻ 83.ֹֻ .ֹֻ .ֹֻ a a a ca ca ca à à à]] 84command ( "let $NVIM_TEST_LET = '" .. mbyte .. "'" ) 85command ( cmd_get_child_env ) 86eq ( eval ( '$NVIM_TEST_LET' ), eval ( 'g:env_from_child' )) 87end ) 88 89it ( 'release of list assigned to l: variable does not trigger assertion #12387, #12430' , function () 90source ( [[ 91func! s:f() 92let l:x = [1] 93let g:x = l: 94endfunc 95for _ in range(2) 96call s:f() 97endfor 98call garbagecollect() 99call feedkeys('i', 't') 100]] ) 101eq ( 1 , eval ( '1' )) 102end ) 103 104it ( 'can apply operator to boolean option' , function () 105eq ( true , api . nvim_get_option_value ( 'equalalways' , {} )) 106command ( 'let &equalalways -= 1' ) 107eq ( false , api . nvim_get_option_value ( 'equalalways' , {} )) 108command ( 'let &equalalways += 1' ) 109eq ( true , api . nvim_get_option_value ( 'equalalways' , {} )) 110command ( 'let &equalalways *= 1' ) 111eq ( true , api . nvim_get_option_value ( 'equalalways' , {} )) 112command ( 'let &equalalways /= 1' ) 113eq ( true , api . nvim_get_option_value ( 'equalalways' , {} )) 114command ( 'let &equalalways %= 1' ) 115eq ( false , api . nvim_get_option_value ( 'equalalways' , {} )) 116end ) 117 118it ( 'ignores legacy TTY assignments after validation' , function () 119for _ , name in ipairs ( { 't_xx' , 't_Co' , 'term' , 'ttytype' } ) do 120local original =eval ( '&' .. name ) 121command ( 'let &' .. name .. ' = "ignored"' ) 122eq ( original , eval ( '&' .. name )) 123command ( 'let &' .. name .. ' .= "ignored"' ) 124eq ( original , eval ( '&' .. name )) 125end 126eq ( 'Vim(let):E730: Using a List as a String' , t . pcall_err ( command , 'let &t_xx = []' )) 127eq ( 'Vim(let):E734: Wrong variable type for +=' , t . pcall_err ( command , 'let &t_xx += 1' )) 128end ) 129 130it ( 'no crash: assigning bool/special to a string option gives E928' , function () 131for _ , v in ipairs ( { 'v:true' , 'v:false' , 'v:null' } ) do 132-- Regular string option. 133eq ( 'Vim(let):E928: String required' , t . pcall_err ( command , 'let &makeprg = ' .. v )) 134-- TTY option ("t_" pseudo-option). 135eq ( 'Vim(let):E928: String required' , t . pcall_err ( command , 'let &t_Co = ' .. v )) 136end 137end ) 138 139it ( 'no crash: assigning to local value of a global-local option' , function () 140-- Unset local reads as Unset, and -1 unsets it again, so curval/newval types may differ. 141for _ , o in ipairs ( { 'autoread' , 'autocomplete' , 'fsync' } ) do 142command (( 'setglobal %s' ): format ( o )) -- global = on 143command (( 'let &l:%s = v:false' ): format ( o )) -- unset local <- bool: sets local off 144eq ( false , api . nvim_get_option_value ( o , {} )) 145command (( 'let &l:%s = -1' ): format ( o )) -- set local <- -1: unsets local, inheriting global 146eq ( true , api . nvim_get_option_value ( o , {} )) 147end 148end ) 149end ) 150 151describe ( ':let and :const' , function () 152it ( 'have the same output when called without arguments' , function () 153eq ( exec_capture ( 'let' ), exec_capture ( 'const' )) 154end ) 155 156it ( 'can be used in sandbox' , function () 157exec ( [[ 158func Func() 159let l:foo = 'foo' 160const l:bar = 'bar' 161endfunc 162sandbox call Func() 163]] ) 164end ) 165end )