diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-11-23 00:05:30 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-11-23 00:05:30 +0800 |
commit | 6da2b175e20ed3c03b0dfcfc9046de1e0e5d4444 (patch) | |
tree | fdc22d78150fd1c5edc46732c8b151ccfefb519f /test/find_lib | |
parent | d0ff66c9abe9d6abbca12fd811e0c3cb69c1033a (diff) | |
download | lua-language-server-6da2b175e20ed3c03b0dfcfc9046de1e0e5d4444.zip |
正路目录
Diffstat (limited to 'test/find_lib')
-rw-r--r-- | test/find_lib/init.lua | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/test/find_lib/init.lua b/test/find_lib/init.lua new file mode 100644 index 00000000..51f53b75 --- /dev/null +++ b/test/find_lib/init.lua @@ -0,0 +1,106 @@ +local core = require 'core' +local parser = require 'parser' +local buildVM = require 'vm' + +rawset(_G, 'TEST', true) + +function TEST(fullkey) + return function (script) + local start = script:find('<?', 1, true) + local finish = script:find('?>', 1, true) + local pos = (start + finish) // 2 + 1 + local new_script = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ') + local ast = parser:parse(new_script, 'lua', 'Lua 5.3') + assert(ast) + local vm = buildVM(ast) + assert(vm) + local source = core.findSource(vm, pos) + local _, name = core.findLib(source) + assert(name == fullkey) + end +end + +TEST 'require' [[ +<?require?> 'xxx' +]] + +TEST 'req<require>' [[ +local <?req?> = require +]] + +TEST 'req<require>' [[ +local req = require +local t = { + xx = req, +} +t[<?'xx'?>]() +]] + +TEST 'table' [[ +<?table?>.unpack() +]] + +TEST 'xx<table>' [[ +local <?xx?> = require 'table' +]] + +TEST 'xx<table>' [[ +local rq = require +local lib = 'table' +local <?xx?> = rq(lib) +]] + +TEST 'table.insert' [[ +table.<?insert?>() +]] + +TEST 'table.insert' [[ +local t = table +t.<?insert?>() +]] + +TEST 'table.insert' [[ +local insert = table.insert +<?insert?>() +]] + +TEST 'table.insert' [[ +local t = require 'table' +t.<?insert?>() +]] + +TEST 'table.insert' [[ +require 'table'.<?insert?>() +]] + +TEST '*string.sub' [[ +local str = 'xxx' +str.<?sub?>() +]] + +TEST '*string:sub' [[ +local str = 'xxx' +str:<?sub?>(1, 1) +]] + +TEST '*string.sub' [[ +('xxx').<?sub?>() +]] + +TEST 'fs<bee::filesystem>' [[ +local <?fs?> = require 'bee.filesystem' +]] + +TEST 'fs.current_path' [[ +local filesystem = require 'bee.filesystem' + +ROOT = filesystem.<?current_path?>() +]] + +TEST(nil)[[ +print(<?insert?>) +]] + +TEST '_G' [[ +local x = <?_G?> +]] |