diff options
| author | Jackson Moore <jacksonmoore@tuta.io> | 2026-09-04 17:46:24 +0200 |
|---|---|---|
| committer | Jackson Moore <jacksonmoore@tuta.io> | 2026-09-04 17:46:24 +0200 |
| commit | ae503e9498553d50cc145d26f4b3457276fc14ba (patch) | |
| tree | ee8793df7baa4503dcfa13ee342a4e875e65d0d9 /tests/run.lua | |
| parent | 3ef0616d516d8c8059380566a29852474d95e801 (diff) | |
Share test assertion helpers
Diffstat (limited to 'tests/run.lua')
| -rw-r--r-- | tests/run.lua | 44 |
1 files changed, 7 insertions, 37 deletions
diff --git a/tests/run.lua b/tests/run.lua index 03aa725..131086f 100644 --- a/tests/run.lua +++ b/tests/run.lua @@ -28,6 +28,13 @@ local text_topology = require("clever_f.text_topology") local target_plan = require("clever_f.target_plan") local MemoryHost = require("clever_f.testing.memory_host") +local assertions = dofile(root .. "/tests/assertions.lua") +local same = assertions.same +local truthy = assertions.truthy +local falsy = assertions.falsy +local fails = assertions.fails +local list_same = assertions.list_same + local tests = {} local passed = 0 @@ -35,43 +42,6 @@ local function test(name, body) tests[#tests + 1] = { name = name, body = body } end -local function same(expected, actual, message) - if expected ~= actual then - error((message or "values differ") - .. ": expected " .. tostring(expected) - .. ", got " .. tostring(actual), 2) - end -end - -local function truthy(value, message) - if not value then - error(message or "value must be true", 2) - end -end - -local function falsy(value, message) - if value then - error(message or "value must be false", 2) - end -end - -local function fails(body, expected_text) - local ok, failure = pcall(body) - if ok then - error("operation must fail", 2) - end - if expected_text and not tostring(failure):find(expected_text, 1, true) then - error("failure does not contain '" .. expected_text .. "': " .. tostring(failure), 2) - end -end - -local function list_same(expected, actual) - same(#expected, #actual, "list lengths differ") - for index = 1, #expected do - same(expected[index], actual[index], "list item " .. tostring(index) .. " differs") - end -end - test("Position validates one-based byte coordinates", function() local position = domain.Position.new(1, 1) same(1, position.line) |
