Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased
<!-- Add all new changes here. They will be moved under a version at release -->
* `CHG` Modified the `ResolveRequire` function to pass the source URI as a third argument.
* `CHG` Improved the output of test failures during development

## 3.17.1
`2026-01-20`
Expand Down
49 changes: 10 additions & 39 deletions test/code_action/init.lua
Original file line number Diff line number Diff line change
@@ -1,50 +1,21 @@
local core = require 'core.code-action'
local files = require 'files'
local lang = require 'language'
local catch = require 'catch'
local furi = require 'file-uri'
local core = require 'core.code-action'
local files = require 'files'
local lang = require 'language'
local catch = require 'catch'
local furi = require 'file-uri'
local compare = require 'compare'

rawset(_G, 'TEST', true)

local EXISTS = {}
local EXISTS = compare.EXISTS

local function eq(expected, result)
if expected == EXISTS and result ~= nil then
return true
end
if result == EXISTS and expected ~= nil then
return true
end
local tp1, tp2 = type(expected), type(result)
if tp1 ~= tp2 then
return false, string.format(": expected type %s, got %s", tp1, tp2)
end
if tp1 == 'table' then
local mark = {}
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(result) do
if not mark[k] then
return false, string.format(".%s: missing key in result", k)
end
end
return true
end
return expected == result, string.format(": expected %s, got %s", expected, result)
end

function TEST(script)
local function TEST(script)
return function (expect)
local newScript, catched = catch(script, '?')
files.setText(TESTURI, newScript)
local results = core(TESTURI, catched['?'][1][1], catched['?'][1][2])
assert(results)
assert(eq(expect, results))
assert(compare.eq(expect, results))
files.remove(TESTURI)
end
end
Expand Down Expand Up @@ -72,7 +43,7 @@ local function TEST_CROSSFILE(testfiles)

local results = core(TESTURI, catched['?'][1][1], catched['?'][1][2])
assert(results)
assert(eq(expected, results))
assert(compare.eq(expected, results))
end
end

Expand Down
47 changes: 47 additions & 0 deletions test/compare.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

local export = {}
local EXISTS = {}

export.EXISTS = EXISTS

local divider = "\n=================\n"
local header1 = ("%stest failed. got:%s"):format(divider, divider)
local header2 = ("%sexpected:%s"):format(divider, divider)
local template = header1 .. "%s" .. header2 .. "%s" .. divider

function export.eq(a, b)
if a == EXISTS and b ~= nil then
return true
end
if b == EXISTS and a ~= nil then
return true
end
local tp1, tp2 = type(a), type(b)
if tp1 ~= tp2 then
return false, template:format("type is: " .. tp1, "type is: " .. tp2)
end
if tp1 == 'table' then
local mark = {}
for k in pairs(a) do
local ok, err = export.eq(a[k], b[k])
if not ok then
return false, string.format(".%s%s", k, err)
end
mark[k] = true
end
for k in pairs(b) do
if not mark[k] then
return false, string.format(".%s: unexpected key in result", k)
end
end
return true
end

if a == b then
return true
end

return false, template:format(tostring(a), tostring(b))
end

return export
43 changes: 9 additions & 34 deletions test/completion/init.lua
Original file line number Diff line number Diff line change
@@ -1,35 +1,10 @@
local core = require 'core.completion'
local files = require 'files'
local catch = require 'catch'
local guide = require 'parser.guide'
local core = require 'core.completion'
local files = require 'files'
local catch = require 'catch'
local guide = require 'parser.guide'
local compare = require 'compare'

EXISTS = {'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
EXISTS = compare.EXISTS

local function include(a, b)
if a == EXISTS and b ~= nil then
Expand All @@ -46,7 +21,7 @@ local function include(a, b)
for _, v1 in ipairs(a) do
local ok = false
for _, v2 in ipairs(b) do
if eq(v1, v2) then
if compare.eq(v1, v2) then
ok = true
break
end
Expand All @@ -57,7 +32,7 @@ local function include(a, b)
end
return true
end
return a == b
return compare.eq(a, b)
end

rawset(_G, 'TEST', true)
Expand Down Expand Up @@ -138,7 +113,7 @@ function TEST(script)
expect.include = nil
assert(include(expect, result))
else
assert(eq(expect, result))
assert(compare.eq(expect, result))
end
end
files.remove(TESTURI)
Expand Down
35 changes: 5 additions & 30 deletions test/crossfile/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,14 @@ local util = require 'utility'
local config = require 'config'
local catch = require 'catch'
local define = require 'proto.define'
local compare = require 'compare'

rawset(_G, 'TEST', true)

local CompletionItemKind = define.CompletionItemKind
local NeedRemoveMeta = false

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
local EXISTS = compare.EXISTS

local Cared = {
['label'] = true,
Expand All @@ -57,7 +32,7 @@ local function removeMetas(results)
end

---@diagnostic disable: await-in-sync
function TEST(data)
local function TEST(data)
local mainUri
local pos
for _, info in ipairs(data) do
Expand Down Expand Up @@ -115,7 +90,7 @@ function TEST(data)
end
end
assert(result)
assert(eq(expect, result))
assert(compare.eq(expect, result))
end

local function WITH_CONFIG(cfg, f)
Expand All @@ -139,7 +114,7 @@ TEST {
---@class A
---@field f1 integer
---@field f2 boolean

---@type A[]
X = {}
]],
Expand Down
6 changes: 3 additions & 3 deletions test/crossfile/definition.lua
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ TEST {

function mt:<!add!>(a, b)
end

return function ()
return setmetatable({}, mt)
end
Expand Down Expand Up @@ -650,10 +650,10 @@ TEST {
function lib:fn1()
return self
end

function lib:<!fn2!>()
end

return lib:fn1()
]]
},
Expand Down
45 changes: 7 additions & 38 deletions test/crossfile/hover.lua
Original file line number Diff line number Diff line change
@@ -1,44 +1,13 @@
local files = require 'files'
local furi = require 'file-uri'
local core = require 'core.hover'
local config = require 'config'
local catch = require 'catch'
local files = require 'files'
local furi = require 'file-uri'
local core = require 'core.hover'
local catch = require 'catch'
local compare = require 'compare'

rawset(_G, 'TEST', true)

local EXISTS = {}

local function eq(a, b)
if a == EXISTS and b ~= nil then
return true
end
if b == EXISTS and a ~= 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

---@diagnostic disable: await-in-sync
function TEST(expect)
local function TEST(expect)
local sourcePos, sourceUri
for _, file in ipairs(expect) do
local script, list = catch(file.content, '?')
Expand All @@ -60,7 +29,7 @@ function TEST(expect)
local hover = core.byUri(sourceUri, sourcePos, 1)
assert(hover)
local content = tostring(hover):gsub('\r\n', '\n')
assert(eq(content, expect.hover))
assert(compare.eq(content, expect.hover))
end

TEST {
Expand Down
Loading
Loading