From 5ba68582b43d70a8d0be4f0d462d75fc521c35aa Mon Sep 17 00:00:00 2001 From: Arnout Roemers Date: Sun, 11 Feb 2024 22:14:29 +0100 Subject: [PATCH] Test watchpoint notifications --- test/redelay/core_test.clj | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/test/redelay/core_test.clj b/test/redelay/core_test.clj index c208685..63d6f96 100644 --- a/test/redelay/core_test.clj +++ b/test/redelay/core_test.clj @@ -1,5 +1,5 @@ (ns redelay.core-test - (:require [redelay.core :refer [state status stop state? defstate state* close!]] + (:require [redelay.core :refer [state status stop state? defstate state* close! watchpoint]] [clojure.test :as test :refer [deftest is]])) (defn ensure-stop [f] @@ -74,3 +74,24 @@ (is (thrown? Exception (stop))) (close! buggy-stop) (is (= () (stop))))) + +(deftest watchpoint-test + (let [two (state 2) + forty-two (state (+ 40 @two)) + notifications (atom [])] + (add-watch watchpoint ::test #(swap! notifications conj %&)) + (try + (is (= 42 @forty-two)) + (stop) + (is (= [[::test watchpoint :starting forty-two] + [::test watchpoint :starting two] + [::test watchpoint :started two] + [::test watchpoint :started forty-two] + ;; stopping + [::test watchpoint :stopping forty-two] + [::test watchpoint :stopped forty-two] + [::test watchpoint :stopping two] + [::test watchpoint :stopped two]] + @notifications)) + (finally + (remove-watch watchpoint ::test)))))