diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-12-07 11:57:21 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-12-07 11:57:21 +0800 |
commit | 0414a4e0179c158dc66d46e22d2c7cb2c3b3608e (patch) | |
tree | d167eece4e4229ae6aeb1192632fc3623fd3b737 /server/test | |
parent | 6b3920292359646f0f24f8770d83e8db755ef896 (diff) | |
download | lua-language-server-0414a4e0179c158dc66d46e22d2c7cb2c3b3608e.zip |
一些测试
Diffstat (limited to 'server/test')
-rw-r--r-- | server/test/find_lib/init.lua | 51 | ||||
-rw-r--r-- | server/test/main.lua | 1 |
2 files changed, 52 insertions, 0 deletions
diff --git a/server/test/find_lib/init.lua b/server/test/find_lib/init.lua new file mode 100644 index 00000000..29297bcf --- /dev/null +++ b/server/test/find_lib/init.lua @@ -0,0 +1,51 @@ +local matcher = require 'matcher' +local parser = require 'parser' +local findResult = require 'matcher.find_result' +local findLib = require 'matcher.find_lib' + +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:ast(new_script) + assert(ast) + local results = matcher.compile(ast) + assert(results) + local result = findResult(results, pos) + assert(result) + assert(result.type == 'var') + local var = result.var + assert(var) + local _, name = findLib(var) + assert(name) + assert(name == fullkey) + end +end + +TEST 'require' [[ +<?require?> 'xxx' +]] + +TEST 'require' [[ +local <?req?> = require +]] + +TEST 'require' [[ +local req = require +local t = { + xx = req, +} +t[<?'xx'?>]() +]] + +TEST 'table' [[ +<?table?>.unpack() +]] + +TEST 'table' [[ +local <?xx?> = require 'table' +]] diff --git a/server/test/main.lua b/server/test/main.lua index 58394989..9b6e2c02 100644 --- a/server/test/main.lua +++ b/server/test/main.lua @@ -21,6 +21,7 @@ local function main() end test 'definition' + test 'find_lib' print('测试完成') end |