diff options
author | Sewbacca <sebastian.kalus@kolabnow.com> | 2023-06-27 21:33:27 +0200 |
---|---|---|
committer | Sewbacca <sebastian.kalus@kolabnow.com> | 2023-06-27 21:33:27 +0200 |
commit | 62068c0709d2fd131607940852b0d938b43794b4 (patch) | |
tree | 0d0f6ff3a340334491fb73a62e4d0c0d23c81641 /test/code_action | |
parent | 82743b19dc64cc9b1859f9a81246d5b4f7a494b5 (diff) | |
download | lua-language-server-62068c0709d2fd131607940852b0d938b43794b4.zip |
Added crossfile testcase
Improved eq error message in test/code_action/init.lua
Uses core.diagnostics.undefined-global
Diffstat (limited to 'test/code_action')
-rw-r--r-- | test/code_action/init.lua | 83 |
1 files changed, 71 insertions, 12 deletions
diff --git a/test/code_action/init.lua b/test/code_action/init.lua index bef58a53..3d107edd 100644 --- a/test/code_action/init.lua +++ b/test/code_action/init.lua @@ -2,38 +2,40 @@ local core = require 'core.code-action' local files = require 'files' local lang = require 'language' local catch = require 'catch' +local furi = require 'file-uri' rawset(_G, 'TEST', true) local EXISTS = {} -local function eq(a, b) - if a == EXISTS and b ~= nil then +local function eq(expected, result) + if expected == EXISTS and result ~= nil then return true end - if b == EXISTS and a ~= nil then + if result == EXISTS and expected ~= nil then return true end - local tp1, tp2 = type(a), type(b) + local tp1, tp2 = type(expected), type(result) if tp1 ~= tp2 then - return false + return false, string.format(": expected type %s, got %s for %s", tp1, tp2) end if tp1 == 'table' then local mark = {} - for k in pairs(a) do - if not eq(a[k], b[k]) then - return false + for k in pairs(expected) do + local ok, err = eq(expected[k], result[k]) + if not ok then + return false, string.format(".%s%s", k, err) end mark[k] = true end - for k in pairs(b) do + for k in pairs(result) do if not mark[k] then - return false + return false, string.format(".%s: missing key in result", k) end end return true end - return a == b + return expected == result, string.format(": expected %s, got %s", expected, result) end function TEST(script) @@ -47,6 +49,32 @@ function TEST(script) end end +local function TEST_CROSSFILE(testfiles) + local mainscript = table.remove(testfiles, 1) + return function(expected) + for _, data in ipairs(testfiles) do + local uri = furi.encode(data.path) + files.setText(uri, data.content) + files.compileState(uri) + end + + local newScript, catched = catch(mainscript, '?') + files.setText(TESTURI, newScript) + files.compileState(TESTURI) + + local _ <close> = function () + for _, info in ipairs(testfiles) do + files.remove(furi.encode(info.path)) + end + files.remove(TESTURI) + end + + local results = core(TESTURI, catched['?'][1][1], catched['?'][1][2]) + assert(results) + assert(eq(expected, results)) + end +end + TEST [[ print(<?a?>, b, c) ]] @@ -155,4 +183,35 @@ local t = { -- }, --} --- TODO: Add some tests for ACTION_AUTOREQUIRE
\ No newline at end of file +-- TODO: Add some tests for ACTION_AUTOREQUIRE + +TEST_CROSSFILE { +[[ + <?unrequiredModule?>.myFunction() +]], + { + path = 'unrequiredModule.lua', + content = [[ + local m = {} + m.myFunction = print + return m + ]] + } +} { + { + title = lang.script('ACTION_AUTOREQUIRE', 'unrequiredModule', 'unrequiredModule'), + kind = 'refactor.rewrite', + command = { + title = 'autoRequire', + command = 'lua.autoRequire', + arguments = { + { + uri = TESTURI, + target = furi.encode 'unrequiredModule.lua', + name = 'unrequiredModule', + requireName = 'unrequiredModule' + }, + }, + } + } +}
\ No newline at end of file |