2015-11-30 22:23:03 +00:00
|
|
|
(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))
|
|
|
|
|
|
2015-12-01 02:13:30 +00:00
|
|
|
(defn- pf [n]
|
|
|
|
|
(+ 41 n))
|
|
|
|
|
|
2015-12-01 13:46:43 +00:00
|
|
|
(defn fna []
|
|
|
|
|
42)
|
|
|
|
|
|
2015-11-30 22:23:03 +00:00
|
|
|
(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))
|
2015-12-01 13:46:43 +00:00
|
|
|
(defstate f-no-args-value :start (fna))
|
|
|
|
|
(defstate f-no-args :start fna)
|
2015-12-01 02:13:30 +00:00
|
|
|
(defstate f-args :start g)
|
2015-11-30 22:23:03 +00:00
|
|
|
(defstate f-value :start (g 41 1))
|
2015-12-01 02:13:30 +00:00
|
|
|
(defstate private-f :start pf)
|
2015-11-30 22:23:03 +00:00
|
|
|
|
|
|
|
|
(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
|
2015-12-01 02:13:30 +00:00
|
|
|
#'check.fun-with-values-test/f-args
|
2015-12-01 13:46:43 +00:00
|
|
|
#'check.fun-with-values-test/f-no-args-value
|
|
|
|
|
#'check.fun-with-values-test/f-no-args
|
2015-12-01 02:13:30 +00:00
|
|
|
#'check.fun-with-values-test/private-f
|
2015-11-30 22:23:03 +00:00
|
|
|
#'check.fun-with-values-test/f-value)
|
|
|
|
|
(f)
|
|
|
|
|
(mount/stop))
|
|
|
|
|
|
|
|
|
|
(use-fixtures :each with-fun-and-values)
|
|
|
|
|
|
|
|
|
|
(deftest fun-with-values
|
2015-12-06 03:55:51 +00:00
|
|
|
(is (= @scalar 42))
|
|
|
|
|
(is (= (@fun) 42))
|
|
|
|
|
(is (= @with-fun 42))
|
|
|
|
|
(is (= (@with-partial 1) 42))
|
|
|
|
|
(is (= (@f-in-f 1) 42))
|
|
|
|
|
(is (= @f-no-args-value 42))
|
|
|
|
|
(is (= (@f-no-args) 42))
|
|
|
|
|
(is (= (@f-args 41 1) 42))
|
|
|
|
|
(is (= (@private-f 1) 42))
|
|
|
|
|
(is (= @f-value 42)))
|
|
|
|
|
|
|
|
|
|
(deftest deref-fun-with-values
|
|
|
|
|
(mount/in-cljc-mode)
|
2015-11-30 22:23:03 +00:00
|
|
|
(is (= scalar 42))
|
|
|
|
|
(is (= (fun) 42))
|
|
|
|
|
(is (= with-fun 42))
|
|
|
|
|
(is (= (with-partial 1) 42))
|
|
|
|
|
(is (= (f-in-f 1) 42))
|
2015-12-01 13:46:43 +00:00
|
|
|
(is (= f-no-args-value 42))
|
|
|
|
|
(is (= (f-no-args) 42))
|
2015-12-01 02:13:30 +00:00
|
|
|
(is (= (f-args 41 1) 42))
|
|
|
|
|
(is (= (private-f 1) 42))
|
2015-12-06 03:55:51 +00:00
|
|
|
(is (= f-value 42))
|
|
|
|
|
(mount/in-clj-mode))
|