From 7ade261608ef3649be5c6ee2961e926527e2f03d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Mon, 18 Nov 2019 01:15:20 +0800 Subject: =?UTF-8?q?=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server-beta/test/type_inference/init.lua | 62 +++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 21 deletions(-) (limited to 'server-beta/test/type_inference') 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 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 = true ]] -TEST 'number' [[ +TEST 'integer' [[ local = 1 ]] +TEST 'number' [[ +local = 1.0 +]] + TEST 'string' [[ local var = '111' t. = var ]] -TEST 'string' [[ +TEST 'any' [[ local var = '111' ]] +TEST 'string' [[ +local var +var = '111' +print() +]] + TEST 'function' [[ function () end @@ -55,8 +80,8 @@ end ]] TEST 'function' [[ -local -xx = function () +local xx + = function () end ]] @@ -64,11 +89,6 @@ TEST 'table' [[ local = {} ]] -TEST 'table' [[ -local -t = {} -]] - TEST 'function' [[ () ]] -- cgit v1.2.3