summaryrefslogtreecommitdiff
path: root/macros_test.fnl
diff options
context:
space:
mode:
authorAndrey Orst <andreyorst@gmail.com>2020-10-23 22:18:07 +0300
committerAndrey Orst <andreyorst@gmail.com>2020-10-23 22:18:07 +0300
commite7bae75ddfb676cc4c0ee22a9339a9a79c837c4a (patch)
tree416721b8a3a8d4e7510f3a8c3cbceb89dda4a055 /macros_test.fnl
parente16763df4de9e198adf48d746407d43fa5538221 (diff)
Changes
- add runtime check to into - add sort of a test framework - remove mapkv in favor of generalized mapv that works both for sequences and tables - add more tests - update doc
Diffstat (limited to 'macros_test.fnl')
-rw-r--r--macros_test.fnl99
1 files changed, 56 insertions, 43 deletions
diff --git a/macros_test.fnl b/macros_test.fnl
index 422f282..349be1b 100644
--- a/macros_test.fnl
+++ b/macros_test.fnl
@@ -1,44 +1,57 @@
(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)
+(import-macros {: assert-eq : assert-ne : assert* : test} :test)
+(local {: eq?} (require :core)) ;; required for testing
+
+
+(test into-test
+ (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})
+
+ ;; different bodies are being used so worth testing
+ (assert-eq (into [] {}) [])
+ (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 [a (fn [] {:a 1})
+ b (fn [] [[:b 2]])]
+ (assert-eq (into (a) (b)) {:a 1 :b 2})
+ (assert-eq (into (b) (a)) [[:b 2] [:a 1]]))
+
+ (let [a {}
+ b []]
+ (assert-eq (into a [1 2 3]) [1 2 3])
+ (assert-eq (into b [1 2 3]) [1 2 3]))
+ (let [a {}
+ b []]
+ (assert-eq (into b {:a 1}) [[:a 1]])))
+
+(test 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))