robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
50c50ab119
master
1-- Test suite for testing interactions with API bindings 2local t =require ( 'test.testutil' ) 3local n =require ( 'test.functional.testnvim' )() 4 5local describe , it , before_each =t . describe , t . it , t . before_each 6local exec_lua =n . exec_lua 7local command =n . command 8local clear =n . clear 9local eq =t . eq 10 11describe ( 'vim.loader' , function () 12before_each ( clear ) 13 14it ( 'can be disabled' , function () 15exec_lua ( function () 16local orig_loader =_G . loadfile 17local orig_loaders ={ unpack ( package . loaders ) } 18vim . loader . enable () 19assert ( orig_loader ~= _G . loadfile ) 20vim . loader . enable ( false ) 21assert ( orig_loader == _G . loadfile ) 22assert ( vim . deep_equal ( orig_loaders , package . loaders )) 23end ) 24end ) 25 26it ( 'works with --luamod-dev #27413' , function () 27clear ( { args ={ '--luamod-dev' } } ) 28exec_lua ( function () 29vim . loader . enable () 30 31require ( 'vim.fs' ) 32 33-- try to load other vim submodules as well (Nvim Lua stdlib) 34for key , _ in pairs ( vim . _submodules ) do 35local modname ='vim.' .. key -- e.g. "vim.fs" 36 37local lhs =vim [ key ] 38local rhs =require ( modname ) 39assert ( 40lhs == rhs , 41( '%s != require("%s"), %s != %s' ): format ( modname , modname , tostring ( lhs ), tostring ( rhs )) 42) 43end 44end ) 45end ) 46 47it ( 'handles changing files #23027' , function () 48exec_lua ( function () 49vim . loader . enable () 50end ) 51 52local tmp =t . tmpname () 53command ( 'edit ' .. tmp ) 54 55eq ( 561 , 57exec_lua ( function () 58vim . api . nvim_buf_set_lines ( 0 , 0 , - 1 , true , { '_G.TEST=1' } ) 59vim . cmd . write () 60loadfile ( tmp )() 61return _G . TEST 62end ) 63) 64 65-- fs latency 66vim . uv . sleep ( 10 ) 67 68eq ( 692 , 70exec_lua ( function () 71vim . api . nvim_buf_set_lines ( 0 , 0 , - 1 , true , { '_G.TEST=2' } ) 72vim . cmd . write () 73loadfile ( tmp )() 74return _G . TEST 75end ) 76) 77end ) 78 79it ( 'handles % signs in modpath #24491' , function () 80exec_lua [[ 81vim.loader.enable() 82]] 83 84local tmp =t . tmpname ( false ) 85assert ( t . mkdir ( tmp )) 86assert ( t . mkdir ( tmp .. '/%' )) 87local tmp1 =tmp .. '/%/x' 88local tmp2 =tmp .. '/%%x' 89 90t . write_file ( tmp1 , 'return 1' , true ) 91t . write_file ( tmp2 , 'return 2' , true ) 92vim . uv . fs_utime ( tmp1 , 0 , 0 ) 93vim . uv . fs_utime ( tmp2 , 0 , 0 ) 94eq ( 1 , exec_lua ( 'return loadfile(...)()' , tmp1 )) 95eq ( 2 , exec_lua ( 'return loadfile(...)()' , tmp2 )) 96end ) 97 98it ( 'indents error message #29809' , function () 99local errmsg =exec_lua [[ 100vim.loader.enable() 101local _, errmsg = pcall(require, 'non_existent_module') 102return errmsg 103]] 104local errors =vim . split ( errmsg , '\n' ) 105eq ( "\tcache_loader: module 'non_existent_module' not found" , errors [ 3 ]) 106eq ( "\tcache_loader_lib: module 'non_existent_module' not found" , errors [ 4 ]) 107end ) 108end )