local parser = require 'parser' local matcher = require 'matcher' rawset(_G, 'TEST', true) function TEST(script) return function (expect) local start = 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, source = matcher.findResult(vm, pos) local hover = matcher.hover(result, source) assert(hover) expect = expect:gsub('^[\r\n]*(.-)[\r\n]*$', '%1'):gsub('\r\n', '\n') local label = hover.label:gsub('^[\r\n]*(.-)[\r\n]*$', '%1'):gsub('\r\n', '\n') assert(expect == label) end end TEST [[ local function (a, b) end ]] "function x(a: any, b: any)" TEST [[ local function x(a, b) end () ]] "function x(a: any, b: any)" TEST [[ local mt = {} mt.__index = mt function mt:init(a, b, c) return {} end local obj = setmetatable({}, mt) obj:(1, '测试') ]] [[ function mt:init(a: number, b: string, c: any) -> table ]] TEST [[ local mt = {} mt.__index = mt function mt:init(a, b, c) return {} end local obj = setmetatable({}, mt) obj:init(1, '测试') obj.(obj, 1, '测试') ]] [[ function mt.init(self: table, a: number, b: string, c: any) -> table ]] TEST [[ function obj.xxx() end obj.() ]] "function obj.xxx()" TEST [[ obj.() ]] "function obj.xxx()" TEST [[ local = 1 ]] "number x = 1" TEST [[ = 1 ]] "number x = 1" TEST [[ local t = {} t. = 1 ]] "number t.x = 1" TEST [[ t = {} t. = 1 ]] "number t.x = 1" TEST [[ local mt = {} mt.__name = 'class' local = setmetatable({}, mt) ]] "*class obj" TEST [[ local mt = {} mt.name = 'class' mt.__index = mt local = setmetatable({}, mt) ]] "*class obj" TEST [[ local mt = {} mt.TYPE = 'class' mt.__index = mt local = setmetatable({}, mt) ]] "*class obj" TEST [[ local mt = {} mt.Class = 'class' mt.__index = mt local = setmetatable({}, mt) ]] "*class obj" TEST[[ local fs = require 'bee.filesystem' local = fs.current_path() ]] "*bee::filesystem root" TEST[[ ('xx'):() ]] "function *string:yy()" TEST [[ local = collectgarbage() ]] "any v" TEST [[ local type w2l:get_default()[] ]] "any type" TEST [[ () ]] [=[ function load(chunk: string/function [, chunkname: string [, mode: string [, env: table]]]) -> function, error_message: string ]=] TEST [[ string.() ]] [[ function string.lower(string) -> string ]] TEST [[ local function x(a, ...) end (1, 2, 3, 4, 5, 6, 7) ]] [[ function x(a: number, ...) ]] TEST [[ local function x() return y() end () ]] [[ function x() -> any ]] TEST [[ local mt = {} mt.__index = mt function mt:add(a, b) end local function init() return setmetatable({}, mt) end local t = init() t:() ]] [[ function mt:add(a: any, b: any) ]] TEST [[ local = - 1000 ]] [[number t = -1000]] TEST [[ for in io.lines() do end ]] [[string c]]