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 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 = '111' ]] TEST 'boolean' [[ local = true ]] TEST 'number' [[ local = 1 ]] TEST 'string' [[ local var = '111' t. = var ]] TEST 'string' [[ local var = '111' ]] TEST 'function' [[ function () end ]] TEST 'function' [[ local function () end ]] TEST 'function' [[ local xx = function () end ]] TEST 'table' [[ local = {} ]] TEST 'table' [[ local t = {} ]] TEST 'function' [[ () ]] TEST 'table' [[ .x = 1 ]] TEST 'boolean' [[ = not y ]] TEST 'integer' [[ = #y ]] TEST 'number' [[ = - y ]] TEST 'integer' [[ = ~ y ]] TEST 'number' [[ local a = true local b = 1 = a and b ]] TEST 'number' [[ local a = false local b = 1 = a or b ]] TEST 'boolean' [[ = a == b ]] TEST 'integer' [[ = a << b ]] TEST 'string' [[ = a .. b ]] TEST 'number' [[ = a + b ]] TEST 'table' [[ () ]] TEST 'string' [[ = _VERSION ]] TEST 'function' [[ = _VERSION.sub ]] TEST 'table' [[ = setmetatable({}) ]] TEST 'number' [[ local function x() return 1 end = x() ]] TEST 'number' [[ local function x(a) return end x(1) ]] TEST 'table' [[ setmetatable() ]] TEST 'number' [[ local function x(a) _ = a + 1 end local b x() ]] TEST 'number' [[ local function x(a, ...) local _, , _ = ... end x(nil, 'xx', 1, true) ]] TEST 'number' [[ local function x(a, ...) return true, 'ss', ... end local _, _, _, , _ = x(nil, true, 1, 'yy') ]] TEST 'integer' [[ for in ipairs(t) do end ]] TEST 'any' [[ local = next() ]]