robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1-- Test suite for testing luaeval() function 2local t =require ( 'test.testutil' ) 3local n =require ( 'test.functional.testnvim' )() 4local Screen =require ( 'test.functional.ui.screen' ) 5 6local describe , it , before_each =t . describe , t . it , t . before_each 7local pcall_err =t . pcall_err 8local remove_trace =t . remove_trace 9local exec_lua =n . exec_lua 10local command =n . command 11local api =n . api 12local fn =n . fn 13local clear =n . clear 14local eval =n . eval 15local feed =n . feed 16local assert_alive =n . assert_alive 17local NIL =vim . NIL 18local eq =t . eq 19local matches =t . matches 20 21before_each ( clear ) 22 23local function startswith ( expected , actual ) 24eq ( expected , actual : sub ( 1 , # expected )) 25end 26 27describe ( 'luaeval()' , function () 28local nested_by_level ={} 29local nested ={} 30local nested_s ='{}' 31for i =1 , 100 do 32if i % 2 == 0 then 33nested ={ nested } 34nested_s ='{' .. nested_s .. '}' 35else 36nested ={ nested =nested } 37nested_s ='{nested=' .. nested_s .. '}' 38end 39nested_by_level [ i ] ={ o =nested , s =nested_s } 40end 41 42describe ( 'second argument' , function () 43it ( 'is successfully received' , function () 44local q ={ 45t =true , 46f =false , --[[n=NIL,]] 47d ={ l ={ 'string' , 42 , 0.42 } } , 48} 49eq ( q , fn . luaeval ( '_A' , q )) 50-- Not tested: nil, funcrefs, returned object identity: behaviour will 51-- most likely change. 52end ) 53end ) 54describe ( 'lua values' , function () 55it ( 'are successfully transformed' , function () 56eq ( 57{ n =1 , f =1.5 , s ='string' , l ={ 4 , 2 } } , 58fn . luaeval ( '{n=1, f=1.5, s="string", l={4, 2}}' ) 59) 60-- Not tested: nil inside containers: behaviour will most likely change. 61eq ( NIL , fn . luaeval ( 'nil' )) 62eq ( { [ '' ] =1 } , fn . luaeval ( '{[""]=1}' )) 63end ) 64end ) 65describe ( 'recursive lua values' , function () 66it ( 'are successfully transformed' , function () 67command ( 'lua rawset(_G, "d", {})' ) 68command ( 'lua rawset(d, "d", d)' ) 69eq ( "\n{'d': {...@0}}" , fn . execute ( 'echo luaeval("d")' )) 70 71command ( 'lua rawset(_G, "l", {})' ) 72command ( 'lua table.insert(l, l)' ) 73eq ( '\n[[...@0]]' , fn . execute ( 'echo luaeval("l")' )) 74end ) 75end ) 76describe ( 'strings with NULs' , function () 77it ( 'are successfully converted to blobs' , function () 78command ( [[let s = luaeval('"\0"')]] ) 79eq ( '\000' , api . nvim_get_var ( 's' )) 80end ) 81it ( 'are successfully converted to special dictionaries in table keys' , function () 82command ( [[let d = luaeval('{["\0"]=1}')]] ) 83eq ( { _TYPE ={} , _VAL ={ { '\000' , 1 } } } , api . nvim_get_var ( 'd' )) 84eq ( 1 , fn . eval ( 'd._TYPE is v:msgpack_types.map' )) 85eq ( eval ( 'v:t_blob' ), fn . eval ( 'type(d._VAL[0][0])' )) 86end ) 87it ( 'are successfully converted to blobs from a list' , function () 88command ( [[let l = luaeval('{"abc", "a\0b", "c\0d", "def"}')]] ) 89eq ( { 'abc' , 'a\000b' , 'c\000d' , 'def' } , api . nvim_get_var ( 'l' )) 90end ) 91end ) 92 93-- Not checked: funcrefs converted to NIL. To be altered to something more 94-- meaningful later. 95 96it ( 'scalars' , function () 97-- Also test method call (->) syntax 98eq ( 1 , fn . luaeval ( '1' )) 99eq ( 0 , eval ( '"1"->luaeval()->type()' )) 100 101eq ( 1.5 , fn . luaeval ( '1.5' )) 102eq ( 5 , eval ( '"1.5"->luaeval()->type()' )) 103 104eq ( 'test' , fn . luaeval ( '"test"' )) 105eq ( 1 , eval ( '"\'test\'"->luaeval()->type()' )) 106 107eq ( '' , fn . luaeval ( '""' )) 108eq ( '\000' , fn . luaeval ( [['\0']] )) 109eq ( '\000\n\000' , fn . luaeval ( [['\0\n\0']] )) 110eq ( 10 , eval ( [[type(luaeval("'\\0\\n\\0'"))]] )) 111 112eq ( true , fn . luaeval ( 'true' )) 113eq ( false , fn . luaeval ( 'false' )) 114eq ( NIL , fn . luaeval ( 'nil' )) 115end ) 116 117it ( 'containers' , function () 118eq ( {} , fn . luaeval ( '{}' )) 119eq ( 3 , eval ( 'type(luaeval("{}"))' )) 120 121eq ( { test =1 , foo =2 } , fn . luaeval ( '{test=1, foo=2}' )) 122eq ( 4 , eval ( 'type(luaeval("{test=1, foo=2}"))' )) 123 124eq ( { 4 , 2 } , fn . luaeval ( '{4, 2}' )) 125eq ( 3 , eval ( 'type(luaeval("{4, 2}"))' )) 126 127eq ( { NIL , 20 } , fn . luaeval ( '{[2] = 20}' )) 128eq ( 3 , eval ( 'type(luaeval("{[2] = 20}"))' )) 129 130eq ( { 10 , NIL , 30 } , fn . luaeval ( '{[1] = 10, [3] = 30}' )) 131eq ( 3 , eval ( 'type(luaeval("{[1] = 10, [3] = 30}"))' )) 132 133local level =30 134eq ( nested_by_level [ level ]. o , fn . luaeval ( nested_by_level [ level ]. s )) 135 136eq ( 137{ _TYPE ={} , _VAL ={ { '\000\n\000' , '\000\n\000\000' } } } , 138fn . luaeval ( [[{['\0\n\0']='\0\n\0\0'}]] ) 139) 140eq ( 1 , eval ( [[luaeval('{["\0\n\0"]="\0\n\0\0"}')._TYPE is v:msgpack_types.map]] )) 141eq ( eval ( 'v:t_blob' ), eval ( [[type(luaeval('{["\0\n\0"]="\0\n\0\0"}')._VAL[0][0])]] )) 142eq ( 143{ nested ={ { _TYPE ={} , _VAL ={ { '\000\n\000' , '\000\n\000\000' } } } } } , 144fn . luaeval ( [[{nested={{['\0\n\0']='\0\n\0\0'}}}]] ) 145) 146end ) 147 148it ( 'passes scalars as argument' , function () 149eq ( 1 , fn . luaeval ( '_A' , 1 )) 150eq ( 1.5 , fn . luaeval ( '_A' , 1.5 )) 151eq ( '' , fn . luaeval ( '_A' , '' )) 152eq ( 'test' , fn . luaeval ( '_A' , 'test' )) 153eq ( NIL , fn . luaeval ( '_A' , NIL )) 154eq ( true , fn . luaeval ( '_A' , true )) 155eq ( false , fn . luaeval ( '_A' , false )) 156end ) 157 158it ( 'passes containers as argument' , function () 159eq ( {} , fn . luaeval ( '_A' , {} )) 160eq ( { test =1 } , fn . luaeval ( '_A' , { test =1 } )) 161eq ( { 4 , 2 } , fn . luaeval ( '_A' , { 4 , 2 } )) 162local level =28 163eq ( nested_by_level [ level ]. o , fn . luaeval ( '_A' , nested_by_level [ level ]. o )) 164end ) 165 166local function sp ( typ , val ) 167return ( '{"_TYPE": v:msgpack_types.%s, "_VAL": %s}' ): format ( typ , val ) 168end 169local function mapsp ( ... ) 170local val ='' 171for i =1 , ( select ( '#' , ... ) / 2 ) do 172val =( '%s[%s,%s],' ): format ( val , select ( i * 2 - 1 , ... ), select ( i * 2 , ... )) 173end 174return sp ( 'map' , '[' .. val .. ']' ) 175end 176local function luaevalarg ( argexpr , expr ) 177return eval ((( [=[ 178[ 179extend(g:, {'_ret': luaeval(%s, %s)})._ret, 180type(g:_ret)==type({})&&has_key(g:_ret, '_TYPE') 181? [ 182get(keys(filter(copy(v:msgpack_types), 'v:val is g:_ret._TYPE')), 0, 183g:_ret._TYPE), 184get(g:_ret, '_VAL', g:_ret) 185] 186: [0, g:_ret]][1] 187]=] ): format ( expr or '"_A"' , argexpr ): gsub ( '\n' , '' ))) 188end 189 190it ( 'passes special dictionaries' , function () 191eq ( { 0 , '\000\n\000' } , luaevalarg ( sp ( 'string' , '["\\n", "\\n"]' ))) 192eq ( { 0 , true } , luaevalarg ( sp ( 'boolean' , 1 ))) 193eq ( { 0 , false } , luaevalarg ( sp ( 'boolean' , 0 ))) 194eq ( { 0 , NIL } , luaevalarg ( sp ( 'nil' , 0 ))) 195eq ( { 0 , { [ '' ] ='' } } , luaevalarg ( mapsp ( sp ( 'string' , '[""]' ), '""' ))) 196end ) 197 198it ( 'failure modes' , function () 199eq ( 200'Vim(call):E5100: Cannot convert given Lua table: table should contain either only integer keys or only string keys' , 201pcall_err ( command , 'call luaeval("{1, foo=2}")' ) 202) 203 204startswith ( 205'Vim(call):E5107: Lua: [string "luaeval()"]:' , 206pcall_err ( command , 'call luaeval("1, 2, 3")' ) 207) 208startswith ( 209'Vim(call):E5108: Lua: [string "luaeval()"]:' , 210pcall_err ( command , 'call luaeval("(nil)()")' ) 211) 212end ) 213 214it ( 'handles sending lua functions to viml' , function () 215eq ( 216true , 217exec_lua [[ 218can_pass_lua_callback_to_vim_from_lua_result = nil 219 220vim.fn.call(function() 221can_pass_lua_callback_to_vim_from_lua_result = true 222end, {}) 223 224return can_pass_lua_callback_to_vim_from_lua_result 225]] 226) 227end ) 228 229it ( 'run functions even in timers' , function () 230eq ( 231true , 232exec_lua [[ 233can_pass_lua_callback_to_vim_from_lua_result = nil 234 235vim.fn.timer_start(50, function() 236can_pass_lua_callback_to_vim_from_lua_result = true 237end) 238 239vim.wait(1000, function() 240return can_pass_lua_callback_to_vim_from_lua_result 241end) 242 243return can_pass_lua_callback_to_vim_from_lua_result 244]] 245) 246end ) 247 248it ( 'can run named functions more than once' , function () 249eq ( 2505 , 251exec_lua [[ 252count_of_vals = 0 253 254vim.fn.timer_start(5, function() 255count_of_vals = count_of_vals + 1 256end, {['repeat'] = 5}) 257 258vim.fn.wait(1000, function() 259return count_of_vals >= 5 260end) 261 262return count_of_vals 263]] 264) 265end ) 266 267it ( 'can handle clashing names' , function () 268eq ( 2691 , 270exec_lua [[ 271local f_loc = function() return 1 end 272 273local result = nil 274vim.fn.timer_start(100, function() 275result = f_loc() 276end) 277 278local f_loc = function() return 2 end 279vim.wait(1000, function() return result ~= nil end) 280 281return result 282]] 283) 284end ) 285 286it ( 'can handle functions with errors' , function () 287eq ( 288true , 289exec_lua [[ 290vim.fn.timer_start(10, function() 291error("dead function") 292end) 293 294vim.wait(1000, function() return false end) 295 296return true 297]] 298) 299-- v:errmsg is set properly #35554 300matches ( ': dead function\n' , api . nvim_get_vvar ( 'errmsg' )) 301end ) 302 303it ( 'can pass functions around' , function () 304command [[ 305function VimCanCallLuaCallbacks(Concat, Cb) 306let message = a:Concat("Hello Vim", "I'm Lua") 307call a:Cb(message) 308endfunction 309]] 310 311eq ( 312"Hello Vim I'm Lua" , 313exec_lua [[ 314can_pass_lua_callback_to_vim_from_lua_result = "" 315 316vim.fn.VimCanCallLuaCallbacks( 317function(greeting, message) return greeting .. " " .. message end, 318function(message) can_pass_lua_callback_to_vim_from_lua_result = message end 319) 320 321return can_pass_lua_callback_to_vim_from_lua_result 322]] 323) 324end ) 325 326it ( 'handles funcrefs' , function () 327command [[ 328function VimCanCallLuaCallbacks(Concat, Cb) 329let message = a:Concat("Hello Vim", "I'm Lua") 330call a:Cb(message) 331endfunction 332]] 333 334eq ( 335"Hello Vim I'm Lua" , 336exec_lua [[ 337can_pass_lua_callback_to_vim_from_lua_result = "" 338 339vim.funcref('VimCanCallLuaCallbacks')( 340function(greeting, message) return greeting .. " " .. message end, 341function(message) can_pass_lua_callback_to_vim_from_lua_result = message end 342) 343 344return can_pass_lua_callback_to_vim_from_lua_result 345]] 346) 347end ) 348 349it ( 'works with metatables using __call' , function () 350eq ( 3511 , 352exec_lua [[ 353local this_is_local_variable = false 354local callable_table = setmetatable({x = 1}, { 355__call = function(t, ...) 356this_is_local_variable = t.x 357end 358}) 359 360vim.fn.timer_start(5, callable_table) 361 362vim.wait(1000, function() 363return this_is_local_variable 364end) 365 366return this_is_local_variable 367]] 368) 369end ) 370 371it ( 'handles being called from a timer once.' , function () 372eq ( 3733 , 374exec_lua [[ 375local this_is_local_variable = false 376local callable_table = setmetatable({5, 4, 3, 2, 1}, { 377__call = function(t, ...) this_is_local_variable = t[3] end 378}) 379 380vim.fn.timer_start(5, callable_table) 381vim.wait(1000, function() 382return this_is_local_variable 383end) 384 385return this_is_local_variable 386]] 387) 388end ) 389 390it ( 'calls functions once with __call metamethod' , function () 391eq ( 392true , 393exec_lua [[ 394local this_is_local_variable = false 395local callable_table = setmetatable({a = true, b = false}, { 396__call = function(t, ...) this_is_local_variable = t.a end 397}) 398 399assert(getmetatable(callable_table).__call) 400vim.fn.call(callable_table, {}) 401 402return this_is_local_variable 403]] 404) 405end ) 406 407it ( 'works with lists using __call' , function () 408eq ( 4093 , 410exec_lua [[ 411local this_is_local_variable = false 412local mt = { 413__call = function(t, ...) 414this_is_local_variable = t[3] 415end 416} 417local callable_table = setmetatable({5, 4, 3, 2, 1}, mt) 418 419-- Call it once... 420vim.fn.timer_start(5, callable_table) 421vim.wait(1000, function() 422return this_is_local_variable 423end) 424 425assert(this_is_local_variable) 426this_is_local_variable = false 427 428vim.fn.timer_start(5, callable_table) 429vim.wait(1000, function() 430return this_is_local_variable 431end) 432 433return this_is_local_variable 434]] 435) 436end ) 437 438it ( 'fails with tables not using __call' , function () 439eq ( 440{ false , 'Vim:E921: Invalid callback argument' } , 441exec_lua [[ 442local this_is_local_variable = false 443local callable_table = setmetatable({x = 1}, {}) 444 445return {pcall(function() vim.fn.timer_start(5, callable_table) end)} 446]] 447) 448end ) 449 450it ( 'converts containers with type_idx' , function () 451eq ( 5 , eval ( 'type(luaeval("{[vim.type_idx]=vim.types.float, [vim.val_idx]=0}"))' )) 452eq ( 4 , eval ( [[type(luaeval('{[vim.type_idx]=vim.types.dictionary}'))]] )) 453eq ( 3 , eval ( [[type(luaeval('{[vim.type_idx]=vim.types.array}'))]] )) 454 455eq ( {} , fn . luaeval ( '{[vim.type_idx]=vim.types.array}' )) 456 457-- Presence of type_idx makes Vim ignore some keys 458eq ( 459{ 42 } , 460fn . luaeval ( '{[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}' ) 461) 462eq ( 463{ foo =2 } , 464fn . luaeval ( '{[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}' ) 465) 466eq ( 10 , fn . luaeval ( '{[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}' )) 467 468-- The following should not crash 469eq ( {} , fn . luaeval ( '{[vim.type_idx]=vim.types.dictionary}' )) 470end ) 471 472it ( 'converts self-containing containers' , function () 473api . nvim_set_var ( 'l' , {} ) 474eval ( 'add(l, l)' ) 475eq ( true , eval ( 'luaeval("_A == _A[1]", l)' )) 476eq ( true , eval ( 'luaeval("_A[1] == _A[1][1]", [l])' )) 477eq ( true , eval ( 'luaeval("_A.d == _A.d[1]", {"d": l})' )) 478eq ( true , eval ( 'luaeval("_A ~= _A[1]", [l])' )) 479 480api . nvim_set_var ( 'd' , { foo =42 } ) 481eval ( 'extend(d, {"d": d})' ) 482eq ( true , eval ( 'luaeval("_A == _A.d", d)' )) 483eq ( true , eval ( 'luaeval("_A[1] == _A[1].d", [d])' )) 484eq ( true , eval ( 'luaeval("_A.d == _A.d.d", {"d": d})' )) 485eq ( true , eval ( 'luaeval("_A ~= _A.d", {"d": d})' )) 486end ) 487 488it ( 'fails when doing incorrect things in lua' , function () 489-- Conversion errors 490eq ( 491'Vim(call):E5108: Lua: [string "luaeval()"]:0: attempt to call field \'xxx_nonexistent_key_xxx\' (a nil value)' , 492remove_trace ( pcall_err ( command , [[call luaeval("vim.xxx_nonexistent_key_xxx()")]] )) 493) 494eq ( 495'Vim(call):E5108: Lua: [string "luaeval()"]:0: ERROR' , 496remove_trace ( pcall_err ( command , [[call luaeval("error('ERROR')")]] )) 497) 498eq ( 499'Vim(call):E5108: Lua: nil' , 500remove_trace ( pcall_err ( command , [[call luaeval("error(nil)")]] )) 501) 502end ) 503 504it ( 'does not leak memory when called with too long line' , function () 505local s =( 'x' ): rep ( 65536 ) 506eq ( 507'Vim(call):E5107: Lua: [string "luaeval()"]:0: unexpected symbol near \')\'' , 508pcall_err ( command , [[call luaeval("(']] .. s .. [[' + )")]] ) 509) 510eq ( s , fn . luaeval ( '"' .. s .. '"' )) 511end ) 512end ) 513 514describe ( 'v:lua' , function () 515before_each ( function () 516exec_lua ( [[ 517function _G.foo(a,b,n) 518_G.val = n 519return a+b 520end 521mymod = {} 522function mymod.noisy(name) 523vim.api.nvim_set_current_line("hey "..name) 524end 525function mymod.crashy() 526nonexistent() 527end 528function mymod.whatis(value) 529return type(value) .. ": " .. tostring(value) 530end 531function mymod.omni(findstart, base) 532if findstart == 1 then 533return 5 534else 535if base == 'st' then 536return {'stuff', 'steam', 'strange things'} 537end 538end 539end 540]] ) 541end ) 542 543it ( 'in expressions' , function () 544eq ( 7 , eval ( 'v:lua.foo(3,4,v:null)' )) 545eq ( true , exec_lua ( [[return _G.val == vim.NIL]] )) 546eq ( NIL , eval ( 'v:lua.mymod.noisy("eval")' )) 547eq ( 'hey eval' , api . nvim_get_current_line ()) 548eq ( 'string: abc' , eval ( 'v:lua.mymod.whatis(0z616263)' )) 549eq ( 'string: ' , eval ( 'v:lua.mymod.whatis(v:_null_blob)' )) 550 551eq ( 552'Vim:E5108: Lua: [string "<nvim>"]:0: attempt to call global \'nonexistent\' (a nil value)' , 553pcall_err ( eval , 'v:lua.mymod.crashy()' ) 554) 555end ) 556 557it ( 'when called as a method' , function () 558eq ( 123 , eval ( '110->v:lua.foo(13)' )) 559eq ( true , exec_lua ( [[return _G.val == nil]] )) 560 561eq ( 321 , eval ( '300->v:lua.foo(21, "boop")' )) 562eq ( 'boop' , exec_lua ( [[return _G.val]] )) 563 564eq ( NIL , eval ( '"there"->v:lua.mymod.noisy()' )) 565eq ( 'hey there' , api . nvim_get_current_line ()) 566eq ( { 5 , 10 , 15 , 20 } , eval ( '[[1], [2, 3], [4]]->v:lua.vim.tbl_flatten()->map({_, v -> v * 5})' )) 567 568eq ( 569'Vim:E5108: Lua: [string "<nvim>"]:0: attempt to call global \'nonexistent\' (a nil value)' , 570pcall_err ( eval , '"huh?"->v:lua.mymod.crashy()' ) 571) 572end ) 573 574it ( 'in :call' , function () 575command ( ":call v:lua.mymod.noisy('command')" ) 576eq ( 'hey command' , api . nvim_get_current_line ()) 577eq ( 578'Vim(call):E5108: Lua: [string "<nvim>"]:0: attempt to call global \'nonexistent\' (a nil value)' , 579pcall_err ( command , 'call v:lua.mymod.crashy()' ) 580) 581end ) 582 583it ( 'in func options' , function () 584local screen =Screen . new ( 60 , 8 ) 585api . nvim_set_option_value ( 'omnifunc' , 'v:lua.mymod.omni' , {} ) 586feed ( 'isome st<c-x><c-o>' ) 587screen : expect { 588grid =[[ 589some stuff^ | 590{1:~ }{12: stuff }{1: }| 591{1:~ }{4: steam }{1: }| 592{1:~ }{4: strange things }{1: }| 593{1:~ }|*3 594{5:-- Omni completion (^O^N^P) }{6:match 1 of 3} | 595]] , 596} 597api . nvim_set_option_value ( 'operatorfunc' , 'v:lua.mymod.noisy' , {} ) 598feed ( '<Esc>g@g@' ) 599eq ( 'hey line' , api . nvim_get_current_line ()) 600end ) 601 602it ( 'supports packages' , function () 603command ( 'set pp+=test/functional/fixtures' ) 604eq ( '\tbadval' , eval ( "v:lua.require'leftpad'('badval')" )) 605eq ( 9003 , eval ( "v:lua.require'bar'.doit()" )) 606eq ( 9004 , eval ( "v:lua.require'baz-quux'.doit()" )) 607eq ( 9003 , eval ( "1 ? v:lua.require'bar'.doit() : v:lua.require'baz-quux'.doit()" )) 608eq ( 9004 , eval ( "0 ? v:lua.require'bar'.doit() : v:lua.require'baz-quux'.doit()" )) 609end ) 610 611it ( 'fails for invalid usage' , function () 612eq ( 613[[Vim(let):E15: Invalid expression: "v:lua.func"]] , 614pcall_err ( command , 'let g:Func = v:lua.func' ) 615) 616eq ( [[Vim(let):E15: Invalid expression: "v:lua"]] , pcall_err ( command , 'let g:Func = v:lua' )) 617eq ( 618[[Vim(let):E15: Invalid expression: "v:['lua']"]] , 619pcall_err ( command , "let g:Func = v:['lua']" ) 620) 621 622eq ( [[Vim:E15: Invalid expression: "v:['lua'].foo()"]] , pcall_err ( eval , "v:['lua'].foo()" )) 623eq ( 624"Vim(call):E461: Illegal variable name: v:['lua']" , 625pcall_err ( command , "call v:['lua'].baar()" ) 626) 627eq ( 'Vim:E1085: Not a callable type: v:lua' , pcall_err ( eval , 'v:lua()' )) 628 629eq ( 630'Vim(let):E46: Cannot change read-only variable "v:[\'lua\']"' , 631pcall_err ( command , "let v:['lua'] = 'xx'" ) 632) 633eq ( 634'Vim(let):E46: Cannot change read-only variable "v:lua"' , 635pcall_err ( command , "let v:lua = 'xx'" ) 636) 637 638eq ( 'Vim:E107: Missing parentheses: v:lua.func' , pcall_err ( eval , "'bad'->v:lua.func" )) 639eq ( 640'Vim:E274: No white space allowed before parenthesis' , 641pcall_err ( eval , "'bad'->v:lua.func ()" ) 642) 643eq ( 'Vim:E107: Missing parentheses: v:lua' , pcall_err ( eval , "'bad'->v:lua" )) 644eq ( 'Vim:E1085: Not a callable type: v:lua' , pcall_err ( eval , "'bad'->v:lua()" )) 645eq ( [[Vim:E15: Invalid expression: "v:lua.()"]] , pcall_err ( eval , "'bad'->v:lua.()" )) 646 647eq ( 'Vim:E1085: Not a callable type: v:lua' , pcall_err ( eval , 'v:lua()' )) 648eq ( [[Vim:E15: Invalid expression: "v:lua.()"]] , pcall_err ( eval , 'v:lua.()' )) 649end ) 650 651describe ( 'invalid usage in fold text' , function () 652before_each ( function () 653feed ( 'ifoo<CR>bar<Esc>' ) 654command ( '1,2fold' ) 655end ) 656 657it ( 'with missing function name when used as simple function' , function () 658api . nvim_set_option_value ( 'debug' , 'throw' , {} ) 659eq ( 660[[Vim(eval):E15: Invalid expression: "v:lua.()"]] , 661pcall_err ( command , 'set foldtext=v:lua.() | eval foldtextresult(1)' ) 662) 663end ) 664 665it ( 'with missing function name when used in expression' , function () 666api . nvim_set_option_value ( 'debug' , 'throw' , {} ) 667eq ( 668[[Vim(eval):E15: Invalid expression: "+v:lua.()"]] , 669pcall_err ( command , 'set foldtext=+v:lua.() | eval foldtextresult(1)' ) 670) 671end ) 672 673it ( 'with non-existent function when used as simple function' , function () 674command ( 'set foldtext=v:lua.NoSuchFunc() | eval foldtextresult(1)' ) 675assert_alive () 676end ) 677 678it ( 'with non-existent function when used in expression' , function () 679command ( 'set foldtext=+v:lua.NoSuchFunc() | eval foldtextresult(1)' ) 680assert_alive () 681end ) 682end ) 683end )