parent
db510832be
commit
20e230b5dd
4 changed files with 53 additions and 11 deletions
|
|
@ -66,7 +66,7 @@
|
|||
(NotStartedState. ~(str state))))))
|
||||
|
||||
(defn- record! [{:keys [ns name]} f done]
|
||||
(let [state (trampoline f)]
|
||||
(let [state (f)]
|
||||
(swap! done conj (ns-resolve ns name))
|
||||
state))
|
||||
|
||||
|
|
|
|||
39
test/check/fun_with_values_test.clj
Normal file
39
test/check/fun_with_values_test.clj
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
(ns check.fun-with-values-test
|
||||
(:require [mount.core :as mount :refer [defstate]]
|
||||
[clojure.test :refer :all]))
|
||||
|
||||
(defn f [n]
|
||||
(fn [m]
|
||||
(+ n m)))
|
||||
|
||||
(defn g [a b]
|
||||
(+ a b))
|
||||
|
||||
(defstate scalar :start 42)
|
||||
(defstate fun :start #(inc 41))
|
||||
(defstate with-fun :start (inc 41))
|
||||
(defstate with-partial :start (partial g 41))
|
||||
(defstate f-in-f :start (f 41))
|
||||
(defstate f-value :start (g 41 1))
|
||||
|
||||
(defn with-fun-and-values [f]
|
||||
(mount/start #'check.fun-with-values-test/scalar
|
||||
#'check.fun-with-values-test/fun
|
||||
#'check.fun-with-values-test/with-fun
|
||||
#'check.fun-with-values-test/with-partial
|
||||
#'check.fun-with-values-test/f-in-f
|
||||
#'check.fun-with-values-test/f-value)
|
||||
(f)
|
||||
(mount/stop))
|
||||
|
||||
(use-fixtures :each with-fun-and-values)
|
||||
|
||||
(deftest fun-with-values
|
||||
(is (= scalar 42))
|
||||
(is (= (fun) 42))
|
||||
(is (= with-fun 42))
|
||||
(is (= (with-partial 1) 42))
|
||||
(is (= (f-in-f 1) 42))
|
||||
(is (= f-value 42)))
|
||||
|
||||
(run-tests)
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
(defstate test-conn :start 42
|
||||
:stop #(constantly 0))
|
||||
|
||||
(defstate test-nrepl :start vector)
|
||||
(defstate test-nrepl :start [])
|
||||
|
||||
(deftest start-with
|
||||
|
||||
|
|
@ -44,3 +44,4 @@
|
|||
(is (instance? mount.core.NotStartedState test-conn))
|
||||
(is (instance? mount.core.NotStartedState test-nrepl))
|
||||
(mount/stop))))
|
||||
|
||||
|
|
|
|||
|
|
@ -15,17 +15,17 @@
|
|||
(defn suspend [s] (koncat s :suspended))
|
||||
(defn resume [s] (koncat s :resumed))
|
||||
|
||||
(defstate web-server :start #(start :w)
|
||||
:stop #(stop :w)
|
||||
:suspend #(suspend :w)
|
||||
:resume #(resume :w))
|
||||
(defstate web-server :start (start :w)
|
||||
:stop (stop :w)
|
||||
:suspend (suspend :w)
|
||||
:resume (resume :w))
|
||||
|
||||
(defstate q-listener :start #(start :q)
|
||||
:stop #(stop :q)
|
||||
:suspend #(suspend :q)
|
||||
:resume #(resume :q))
|
||||
(defstate q-listener :start (start :q)
|
||||
:stop (stop :q)
|
||||
:suspend (suspend :q)
|
||||
:resume (resume :q))
|
||||
|
||||
(defstate randomizer :start #(rand-int 42))
|
||||
(defstate randomizer :start (rand-int 42))
|
||||
|
||||
(deftest suspendable-lifecycle
|
||||
|
||||
|
|
@ -139,3 +139,5 @@
|
|||
(is (= q-listener :q-suspended))
|
||||
(is (= web-server :w-suspended))
|
||||
(mount/stop))))
|
||||
|
||||
(run-tests)
|
||||
|
|
|
|||
Loading…
Reference in a new issue