diff options
Diffstat (limited to 'server/test')
-rw-r--r-- | server/test/hover/init.lua | 65 | ||||
-rw-r--r-- | server/test/main.lua | 1 | ||||
-rw-r--r-- | server/test/type_inference/init.lua | 7 |
3 files changed, 73 insertions, 0 deletions
diff --git a/server/test/hover/init.lua b/server/test/hover/init.lua new file mode 100644 index 00000000..55931339 --- /dev/null +++ b/server/test/hover/init.lua @@ -0,0 +1,65 @@ +local parser = require 'parser' +local matcher = require 'matcher' + +rawset(_G, 'TEST', true) + +function TEST(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) + local vm = matcher.vm(ast) + assert(vm) + local result = matcher.hover(vm, pos) + assert(result) +end + +TEST [[ +local function <?x?>(a, b) +end +]] + +TEST [[ +local function x(a, b) +end +<?x?>() +]] + +TEST [[ +local mt = {} +mt.__index = mt + +function mt:init(a, b, c) + return {} +end + +local obj = setmetatable({}, mt) + +obj:<?init?>(1, '测试') +]] + +TEST [[ +local mt = {} +mt.__index = mt + +function mt:init(a, b, c) + return {} +end + +local obj = setmetatable({}, mt) + +obj:init(1, '测试') +obj.<?init?>(obj, 1, '测试') +]] + +TEST [[ +function obj.xxx() +end + +obj.<?xxx?>() +]] + +TEST [[ +obj.<?xxx?>() +]] diff --git a/server/test/main.lua b/server/test/main.lua index 67e2da0a..82828714 100644 --- a/server/test/main.lua +++ b/server/test/main.lua @@ -28,6 +28,7 @@ local function main() test 'diagnostics' test 'type_inference' test 'find_lib' + test 'hover' print('测试完成') end diff --git a/server/test/type_inference/init.lua b/server/test/type_inference/init.lua index c906fdd4..36e28aec 100644 --- a/server/test/type_inference/init.lua +++ b/server/test/type_inference/init.lua @@ -127,3 +127,10 @@ local function x() end <?y?> = x() ]] + +TEST 'number' [[ +local function x(a) + return <?a?> +end +x(1) +]] |