summaryrefslogtreecommitdiff
path: root/server-beta/test/type_inference
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-11-18 01:15:20 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-11-18 01:15:20 +0800
commit7ade261608ef3649be5c6ee2961e926527e2f03d (patch)
tree4cb3991079061384962de3bf1905c9b5374d65bf /server-beta/test/type_inference
parente9fcf13480ed98af15201911cad542fe6e84dc1e (diff)
downloadlua-language-server-7ade261608ef3649be5c6ee2961e926527e2f03d.zip
暂存
Diffstat (limited to 'server-beta/test/type_inference')
-rw-r--r--server-beta/test/type_inference/init.lua62
1 files changed, 41 insertions, 21 deletions
diff --git a/server-beta/test/type_inference/init.lua b/server-beta/test/type_inference/init.lua
index 59d853eb..4a9f30aa 100644
--- a/server-beta/test/type_inference/init.lua
+++ b/server-beta/test/type_inference/init.lua
@@ -1,22 +1,37 @@
-local parser = require 'parser'
-local core = require 'core'
-local buildVM = require 'vm'
-local config = require 'config'
+local files = require 'files'
+local config = require 'config'
+local searcher = require 'searcher'
+local guide = require 'parser.guide'
rawset(_G, 'TEST', true)
-function TEST(res)
+local function getSource(pos)
+ local ast = files.getAst('')
+ return guide.eachSourceContain(ast.ast, pos, function (source)
+ if source.type == 'local'
+ or source.type == 'getlocal'
+ or source.type == 'setlocal'
+ or source.type == 'setglobal'
+ or source.type == 'getglobal'
+ or source.type == 'field'
+ or source.type == 'method' then
+ return source
+ end
+ end)
+end
+
+function TEST(wanted)
return function (script)
+ files.removeAll()
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')
- local vm = buildVM(ast)
- assert(vm)
- local result = core.findSource(vm, pos)
- assert(result)
- assert(res == result:bindValue():getType())
+ local newScript = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ')
+ files.setText('', newScript)
+ local source = getSource(pos)
+ assert(source)
+ local result = searcher.typeInference(source) or 'any'
+ assert(wanted == result)
end
end
@@ -30,20 +45,30 @@ TEST 'boolean' [[
local <?var?> = true
]]
-TEST 'number' [[
+TEST 'integer' [[
local <?var?> = 1
]]
+TEST 'number' [[
+local <?var?> = 1.0
+]]
+
TEST 'string' [[
local var = '111'
t.<?x?> = var
]]
-TEST 'string' [[
+TEST 'any' [[
local <?var?>
var = '111'
]]
+TEST 'string' [[
+local var
+var = '111'
+print(<?var?>)
+]]
+
TEST 'function' [[
function <?xx?>()
end
@@ -55,8 +80,8 @@ end
]]
TEST 'function' [[
-local <?xx?>
-xx = function ()
+local xx
+<?xx?> = function ()
end
]]
@@ -64,11 +89,6 @@ TEST 'table' [[
local <?t?> = {}
]]
-TEST 'table' [[
-local <?t?>
-t = {}
-]]
-
TEST 'function' [[
<?x?>()
]]