summaryrefslogtreecommitdiff
path: root/tests/commit_transaction_test.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tests/commit_transaction_test.lua')
-rw-r--r--tests/commit_transaction_test.lua48
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")