summaryrefslogtreecommitdiff
path: root/macros_test.fnl
diff options
context:
space:
mode:
authorAndrey Orst <andreyorst@gmail.com>2020-10-22 22:32:06 +0300
committerAndrey Orst <andreyorst@gmail.com>2020-10-22 22:32:06 +0300
commitab3377a587c96c8df185d8000570fda08fa209a4 (patch)
tree90644995485b9ac2b1fe8ca09130456c4218695d /macros_test.fnl
parentbdea62d872a534b5a9a24b42aa25aa627df1e2c5 (diff)
add more tests
Diffstat (limited to 'macros_test.fnl')
-rw-r--r--macros_test.fnl44
1 files changed, 44 insertions, 0 deletions
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)