diff options
| author | Jackson Moore <jacksonmoore@tuta.io> | 2026-09-05 14:51:53 +0200 |
|---|---|---|
| committer | Jackson Moore <jacksonmoore@tuta.io> | 2026-09-05 14:51:53 +0200 |
| commit | 44d333c65a7fa2d221a8ab7bd0452b11a1a795e6 (patch) | |
| tree | 6e4a90d46ab7835d3e5aa09a54a5beac4f386a84 /tests/commit_transaction_test.lua | |
| parent | 805e86604c3546271147300815e10006e6eec66d (diff) | |
Add commit dispatch tests
Diffstat (limited to 'tests/commit_transaction_test.lua')
| -rw-r--r-- | tests/commit_transaction_test.lua | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/tests/commit_transaction_test.lua b/tests/commit_transaction_test.lua index 5e06445..0fce738 100644 --- a/tests/commit_transaction_test.lua +++ b/tests/commit_transaction_test.lua @@ -96,4 +96,50 @@ run_guard_case("missing highlights", { }, "query") assert_equal(unmatched_cha_reads, 0, "type reads before highlight proof") -print("commit guard checks passed") +local function run_dispatch_case(label, mode, is_dir, expected_count, expected_action) + local order = {} + local target = setmetatable({ + highlights = function() + order[#order + 1] = "highlights" + return { 1 } + end, + }, { + __index = function(_, key) + assert(key == "cha", label .. " read an unexpected target field") + order[#order + 1] = "is-dir" + return { is_dir = is_dir } + end, + }) + active = { + finder = setmetatable({}, { __tostring = function() return "query" end }), + current = { hovered = target }, + } + + local emit_count = #emits + assert_equal(commit(nil, mode, "query"), expected_count, label .. " dispatch count") + assert_equal(#emits - emit_count, expected_count, label .. " emitted action count") + assert_equal(order[1], "highlights", label .. " first guarded target access") + assert_equal(order[2], "is-dir", label .. " deferred type access") + assert_equal(order[3], nil, label .. " target access count") + + if expected_count == 1 then + local emitted = emits[#emits] + assert_equal(emitted.action, expected_action, label .. " action") + assert(type(emitted.args) == "table", label .. " action arguments must be a table") + if expected_action == "open" then + assert_equal(emitted.args.hovered, true, label .. " hovered argument") + assert_equal(next(emitted.args, "hovered"), nil, label .. " open argument shape") + else + assert_equal(next(emitted.args), nil, label .. " enter argument shape") + end + end +end + +run_dispatch_case("directory mode directory", "directory", true, 1, "enter") +run_dispatch_case("directory mode file", "directory", false, 0, nil) +run_dispatch_case("file mode directory", "file", true, 0, nil) +run_dispatch_case("file mode file", "file", false, 1, "open") +run_dispatch_case("either mode directory", "either", true, 1, "enter") +run_dispatch_case("either mode file", "either", false, 1, "open") + +print("commit transaction checks passed") |