simplify. remove tick

This commit is contained in:
2026-01-22 22:22:19 -05:00
parent 8cb4c82daa
commit 8c7cb24171
9 changed files with 133 additions and 88 deletions
+36 -14
View File
@@ -12,24 +12,46 @@
(testing "quit command is correct vector"
(is (= [:quit] tui/quit))))
(deftest tick-command-test
(testing "tick creates correct command"
(is (= [:tick 100] (tui/tick 100)))
(is (= [:tick 1000] (tui/tick 1000)))))
(deftest after-command-test
(testing "after creates a function command"
(let [cmd (tui/after 0 :my-tick)]
(is (fn? cmd))
(is (= :my-tick (cmd)))))
(testing "after can send any message type"
(is (= [:timer-tick {:id 1}] ((tui/after 0 [:timer-tick {:id 1}]))))
(is (= :simple-msg ((tui/after 0 :simple-msg)))))
(testing "after with non-zero delay creates function"
;; Don't invoke - these would sleep
(is (fn? (tui/after 100 :tick)))
(is (fn? (tui/after 1000 :tick)))))
(deftest batch-command-test
(testing "batch combines commands"
(is (= [:batch [:tick 100] [:quit]] (tui/batch (tui/tick 100) tui/quit))))
(let [cmd (tui/batch (tui/send-msg :msg1) tui/quit)]
(is (vector? cmd))
(is (= :batch (first cmd)))
(is (= 3 (count cmd))) ; [:batch fn [:quit]]
(is (= [:quit] (last cmd)))))
(testing "batch filters nil commands"
(is (= [:batch [:tick 100]] (tui/batch nil (tui/tick 100) nil)))))
(let [cmd (tui/batch nil (tui/send-msg :msg1) nil)]
(is (= :batch (first cmd)))
(is (= 2 (count cmd))))))
(deftest sequentially-command-test
(testing "sequentially creates seq command"
(is (= [:seq [:tick 100] [:quit]] (tui/sequentially (tui/tick 100) tui/quit))))
(let [cmd (tui/sequentially (tui/send-msg :msg1) tui/quit)]
(is (vector? cmd))
(is (= :seq (first cmd)))
(is (= 3 (count cmd)))
(is (= [:quit] (last cmd)))))
(testing "sequentially filters nil commands"
(is (= [:seq [:tick 100]] (tui/sequentially nil (tui/tick 100) nil)))))
(let [cmd (tui/sequentially nil (tui/send-msg :msg1) nil)]
(is (= :seq (first cmd)))
(is (= 2 (count cmd))))))
(deftest send-msg-command-test
(testing "send-msg creates function that returns message"
@@ -102,10 +124,11 @@
(is (= [:quit] result)))
(close! msg-chan))))
(deftest execute-tick-command-test
(testing "tick command sends :tick message after delay"
(let [msg-chan (chan 1)]
(#'tui/execute-cmd! [:tick 50] msg-chan)
(deftest execute-after-command-test
(testing "after command sends message after delay"
(let [msg-chan (chan 1)
cmd (tui/after 50 :delayed-msg)]
(#'tui/execute-cmd! cmd msg-chan)
;; Should not receive immediately
(let [immediate (alt!!
msg-chan ([v] v)
@@ -115,8 +138,7 @@
(let [delayed (alt!!
msg-chan ([v] v)
(timeout 200) :timeout)]
(is (vector? delayed))
(is (= :tick (first delayed))))
(is (= :delayed-msg delayed)))
(close! msg-chan))))
(deftest execute-function-command-test