Skip to content

Commit fbbae10

Browse files
committed
tests: add check_lines utility
1 parent e457d38 commit fbbae10

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

spec/util.lua

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,17 +386,18 @@ local function batch_compare(batch, category, expected, got)
386386
for i = 1, #expected do
387387
local e = expected[i] or {}
388388
local g = got[i] or {}
389+
local at = "[" .. (e.line and ("\"" .. e.line .. "\"") or i) .. "]"
389390
if e.y then
390-
batch:add(assert.same, e.y, g.y, "[" .. i .. "] Expected same y location:")
391+
batch:add(assert.same, e.y, g.y, at .. " Expected same y location:")
391392
end
392393
if e.x then
393-
batch:add(assert.same, e.x, g.x, "[" .. i .. "] Expected same x location:")
394+
batch:add(assert.same, e.x, g.x, at .. " Expected same x location:")
394395
end
395396
if e.msg then
396-
batch:add(assert.match, e.msg, g.msg or "", 1, true, "[" .. i .. "] Expected messages to match:")
397+
batch:add(assert.match, e.msg, g.msg or "", 1, true, at .. " Expected messages to match:")
397398
end
398399
if e.filename then
399-
batch:add(assert.match, e.filename, g.filename or "", 1, true, "[" .. i .. "] Expected filenames to match:")
400+
batch:add(assert.match, e.filename, g.filename or "", 1, true, at .. " Expected filenames to match:")
400401
end
401402
end
402403
if #got > #expected then
@@ -634,4 +635,21 @@ function util.run_lax_check(...)
634635
return util.lax_check(...)()
635636
end
636637

638+
function util.check_lines(prelude, testcases)
639+
local code = prelude
640+
local errs = {}
641+
local y = 0
642+
for _ in prelude:gmatch("\n") do
643+
y = y + 1
644+
end
645+
for _, testcase in ipairs(testcases) do
646+
code = code .. testcase.line .. "\n"
647+
y = y + 1
648+
if testcase.err then
649+
table.insert(errs, { y = y, line = testcase.line, msg = testcase.err })
650+
end
651+
end
652+
return util.check_type_error(code, errs)
653+
end
654+
637655
return util

0 commit comments

Comments
 (0)