From ab3377a587c96c8df185d8000570fda08fa209a4 Mon Sep 17 00:00:00 2001 From: Andrey Orst Date: Thu, 22 Oct 2020 22:32:06 +0300 Subject: add more tests --- macros_test.fnl | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 macros_test.fnl (limited to 'macros_test.fnl') diff --git a/macros_test.fnl b/macros_test.fnl new file mode 100644 index 0000000..422f282 --- /dev/null +++ b/macros_test.fnl @@ -0,0 +1,44 @@ +(import-macros {: if-let : when-let : if-some : when-some : into} :macros.core) +(import-macros {: assert-eq : assert-ne : assert*} :test) +(local {: eq?} (require :core)) + +;;;;;;;;;;;;;;;;;;;;;;;;;; into ;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(assert-eq (into [] []) []) +(assert-eq (into [1 2 3] []) [1 2 3]) +(assert-eq (into [1 2 3] [4 5 6]) [1 2 3 4 5 6]) + +(assert-eq (into {} {}) {}) +(assert-eq (into {:a 1} {}) {:a 1}) +(assert-eq (into {:a 1} {:b 2}) {:a 1 :b 2}) + +(assert-eq (into [] {}) []) ;; different bodies are being used so worth testing +(assert-eq (into {} []) []) + +;; can't transform table with more than one key-value pair, as order +;; is undeterminitive +(assert-eq (into [] {:a 1}) [[:a 1]]) +(assert-eq (into [[:b 2]] {:a 1}) [[:b 2] [:a 1]]) +(assert-eq (into [[:c 3]] {}) [[:c 3]]) + +(assert-eq (into {} [[:c 3] [:a 1] [:b 2]]) {:a 1 :b 2 :c 3}) +(assert-eq (into {:d 4} [[:c 3] [:a 1] [:b 2]]) {:a 1 :b 2 :c 3 :d 4}) +(assert-eq (into {:a 0 :b 0 :c 0} [[:c 3] [:a 1] [:b 2]]) {:a 1 :b 2 :c 3}) + +;;;;;;;;;;;;;;;;;;;;;;; let variants ;;;;;;;;;;;;;;;;;;;;;;;; + +(assert-eq (when-let [a 4] a) 4) +(assert* (not (when-let [a false] a)) "(not (when-let [a false] a))") +(assert* (not (when-let [a nil] a)) "(not (when-let [a nil] a))") + +(assert-eq (when-some [a [1 2 3]] a) [1 2 3]) +(assert-eq (when-some [a false] a) false) +(assert* (not (when-some [a nil] a)) "(when-some [a nil] a)") + +(assert-eq (if-let [a 4] a 10) 4) +(assert-eq (if-let [a false] a 10) 10) +(assert-eq (if-let [a nil] a 10) 10) + +(assert-eq (if-some [a [1 2 3]] a :nothing) [1 2 3]) +(assert-eq (if-some [a false] a :nothing) false) +(assert-eq (if-some [a nil] a :nothing) :nothing) -- cgit v1.2.3