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/type_inference/init.lua | |
parent | d0ff66c9abe9d6abbca12fd811e0c3cb69c1033a (diff) | |
download | lua-language-server-6da2b175e20ed3c03b0dfcfc9046de1e0e5d4444.zip |
正路目录
Diffstat (limited to 'test/type_inference/init.lua')
-rw-r--r-- | test/type_inference/init.lua | 187 |
1 files changed, 187 insertions, 0 deletions
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua new file mode 100644 index 00000000..59d853eb --- /dev/null +++ b/test/type_inference/init.lua @@ -0,0 +1,187 @@ +local parser = require 'parser' +local core = require 'core' +local buildVM = require 'vm' +local config = require 'config' + +rawset(_G, 'TEST', true) + +function TEST(res) + 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') + local vm = buildVM(ast) + assert(vm) + local result = core.findSource(vm, pos) + assert(result) + assert(res == result:bindValue():getType()) + end +end + +config.config.runtime.version = 'Lua 5.4' + +TEST 'string' [[ +local <?var?> = '111' +]] + +TEST 'boolean' [[ +local <?var?> = true +]] + +TEST 'number' [[ +local <?var?> = 1 +]] + +TEST 'string' [[ +local var = '111' +t.<?x?> = var +]] + +TEST 'string' [[ +local <?var?> +var = '111' +]] + +TEST 'function' [[ +function <?xx?>() +end +]] + +TEST 'function' [[ +local function <?xx?>() +end +]] + +TEST 'function' [[ +local <?xx?> +xx = function () +end +]] + +TEST 'table' [[ +local <?t?> = {} +]] + +TEST 'table' [[ +local <?t?> +t = {} +]] + +TEST 'function' [[ +<?x?>() +]] + +TEST 'table' [[ +<?t?>.x = 1 +]] + +TEST 'boolean' [[ +<?x?> = not y +]] + +TEST 'integer' [[ +<?x?> = #y +]] + +TEST 'number' [[ +<?x?> = - y +]] + +TEST 'integer' [[ +<?x?> = ~ y +]] + +TEST 'number' [[ +local a = true +local b = 1 +<?x?> = a and b +]] + +TEST 'number' [[ +local a = false +local b = 1 +<?x?> = a or b +]] + +TEST 'boolean' [[ +<?x?> = a == b +]] + +TEST 'integer' [[ +<?x?> = a << b +]] + +TEST 'string' [[ +<?x?> = a .. b +]] + +TEST 'number' [[ +<?x?> = a + b +]] + +TEST 'table' [[ +<?table?>() +]] + +TEST 'string' [[ +<?x?> = _VERSION +]] + +TEST 'function' [[ +<?x?> = _VERSION.sub +]] + +TEST 'table' [[ +<?x?> = setmetatable({}) +]] + +TEST 'number' [[ +local function x() + return 1 +end +<?y?> = x() +]] + +TEST 'number' [[ +local function x(a) + return <?a?> +end +x(1) +]] + +TEST 'table' [[ +setmetatable(<?b?>) +]] + +TEST 'number' [[ +local function x(a) + _ = a + 1 +end +local b +x(<?b?>) +]] + +TEST 'number' [[ +local function x(a, ...) + local _, <?b?>, _ = ... +end +x(nil, 'xx', 1, true) +]] + +TEST 'number' [[ +local function x(a, ...) + return true, 'ss', ... +end +local _, _, _, <?b?>, _ = x(nil, true, 1, 'yy') +]] + +TEST 'integer' [[ +for <?i?> in ipairs(t) do +end +]] + +TEST 'any' [[ +local <?x?> = next() +]] |