diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-01-02 09:49:18 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-01-02 09:49:18 +0800 |
commit | df91fc4fe96436ea1ca7de5af214e5eade23762f (patch) | |
tree | cfaebda6ceaffb86460219199a0baa4877f73e26 | |
parent | f5f051c3fb1272c990c2074443877e55d3f6122e (diff) | |
download | lua-language-server-df91fc4fe96436ea1ca7de5af214e5eade23762f.zip |
加个测试
-rw-r--r-- | server/test/crossfile/document_symbol.lua | 117 | ||||
-rw-r--r-- | server/test/crossfile/init.lua | 1 |
2 files changed, 118 insertions, 0 deletions
diff --git a/server/test/crossfile/document_symbol.lua b/server/test/crossfile/document_symbol.lua new file mode 100644 index 00000000..32d8364b --- /dev/null +++ b/server/test/crossfile/document_symbol.lua @@ -0,0 +1,117 @@ +local service = require 'service' +local workspace = require 'workspace' +local fs = require 'bee.filesystem' +local core = require 'core' + +local SymbolKind = { + File = 1, + Module = 2, + Namespace = 3, + Package = 4, + Class = 5, + Method = 6, + Property = 7, + Field = 8, + Constructor = 9, + Enum = 10, + Interface = 11, + Function = 12, + Variable = 13, + Constant = 14, + String = 15, + Number = 16, + Boolean = 17, + Array = 18, + Object = 19, + Key = 20, + Null = 21, + EnumMember = 22, + Struct = 23, + Event = 24, + Operator = 25, + TypeParameter = 26, +} + +local EXISTS = {} + +local function eq(a, b) + if a == EXISTS and b ~= nil then + return true + end + local tp1, tp2 = type(a), type(b) + if tp1 ~= tp2 then + return false + end + if tp1 == 'table' then + local mark = {} + for k in pairs(a) do + if not eq(a[k], b[k]) then + return false + end + mark[k] = true + end + for k in pairs(b) do + if not mark[k] then + return false + end + end + return true + end + return a == b +end + +rawset(_G, 'TEST', true) + +function TEST(data) + local lsp = service() + local ws = workspace(lsp, 'test') + lsp.workspace = ws + + local targetUri = ws:uriEncode(fs.path(data[1].path)) + local sourceUri = ws:uriEncode(fs.path(data[2].path)) + + lsp:saveText(sourceUri, 1, data[2].content) + ws:addFile(sourceUri) + lsp:saveText(targetUri, 1, data[1].content) + ws:addFile(targetUri) + lsp:compileAll() + lsp:compileAll() + + local sourceVM = lsp:getVM(sourceUri) + assert(sourceVM) + local result = core.documentSymbol(sourceVM) + assert(eq(data.symbol, result)) +end + +TEST { + { + path = 'a.lua', + content = '', + }, + { + path = 'b.lua', + content = [[ +local t = { + x = require 'a', +} + ]], + }, + symbol = { + [1] = { + name = 't', + detail = EXISTS, + kind = SymbolKind.Variable, + range = {7, 34}, + selectionRange = {7, 7}, + children = { + [1] = { + name = 'x', + detail = EXISTS, + kind = SymbolKind.Class, + range = {17, 17}, + selectionRange = {17, 17}, + }, + } + } + } +} diff --git a/server/test/crossfile/init.lua b/server/test/crossfile/init.lua index b74514af..30bf23df 100644 --- a/server/test/crossfile/init.lua +++ b/server/test/crossfile/init.lua @@ -1,3 +1,4 @@ require 'crossfile.definition' require 'crossfile.hover' require 'crossfile.completion' +require 'crossfile.document_symbol' |