Part 1 (test/cljs-port-1.janet) — 65 assertions, 6 sections: - 1: core math (10): +, -, *, /, inc, dec, quot, rem, mod, max, min - 2: predicates (13): nil?, not, some?, string?, number?, fn?, keyword?, map?, zero?, pos?, neg?, even?, odd? - 3: comparison (9): =, not=, = multi, not=, <, >, <=, >= - 4: vectors (5): nth, conj, first, rest, count - 5: maps (8): get, assoc, dissoc, contains?, count, keys - 6: sets (5): set?, conj, disj, count, = order-independent Part 2 (test/cljs-port-2.janet) — 20 assertions, 6 sections: - 7: seq ops (8): seq, map, filter, reduce, take, drop, reverse, every? - 8: atoms (3): deref, swap!, atom? - 9: special forms (6): let, if, do, loop/recur, try/catch - 10: macros (5): defn, when, and, or, fn - 11: higher-order (3): comp, partial, identity - 12: constructors (4): vector count, hash-map count, hash-set count, zipmap 315 ok, 2 fail (pre-existing, unchanged)
52 lines
2.4 KiB
Text
52 lines
2.4 KiB
Text
(use ../src/jolt/api)
|
|
(defn ct-eval [ctx s] (eval-string ctx s))
|
|
(print "CLJS Ported 7-12")
|
|
(print "7: seq ops...")
|
|
(let [ctx (init)]
|
|
(assert (= nil (ct-eval ctx "(seq [])")) "seq empty")
|
|
(assert (= [2 3 4] (ct-eval ctx "(map inc [1 2 3])")) "map")
|
|
(assert (= [1 3] (ct-eval ctx "(filter odd? [1 2 3 4])")) "filter")
|
|
(assert (= 6 (ct-eval ctx "(reduce + [1 2 3])")) "reduce")
|
|
(assert (= [1 2 3] (ct-eval ctx "(take 3 [1 2 3 4 5])")) "take")
|
|
(assert (= [4 5] (ct-eval ctx "(drop 3 [1 2 3 4 5])")) "drop")
|
|
(assert (= 3 (ct-eval ctx "(count (reverse [1 2 3]))")) "reverse count")
|
|
(assert (= true (ct-eval ctx "(every? even? [2 4 6])")) "every?"))
|
|
(print " ok")
|
|
(print "8: atoms...")
|
|
(let [ctx (init)]
|
|
(assert (= 0 (ct-eval ctx "(deref (atom 0))")) "deref")
|
|
(assert (= 1 (ct-eval ctx "(let [a (atom 0)] (swap! a inc) (deref a))")) "swap!")
|
|
(assert (= true (ct-eval ctx "(atom? (atom 0))")) "atom?"))
|
|
(print " ok")
|
|
(print "9: special forms...")
|
|
(let [ctx (init)]
|
|
(assert (= 30 (ct-eval ctx "(let [x 10 y 20] (+ x y))")) "let")
|
|
(assert (= :a (ct-eval ctx "(if true :a :b)")) "if true")
|
|
(assert (= :b (ct-eval ctx "(if false :a :b)")) "if false")
|
|
(assert (= 2 (ct-eval ctx "(do 1 2)")) "do")
|
|
(assert (= 3 (ct-eval ctx "(loop [x 0] (if (< x 3) (recur (inc x)) x))")) "loop")
|
|
(assert (= :caught (ct-eval ctx "(try (throw 42) (catch Exception e :caught))")) "try"))
|
|
(print " ok")
|
|
(print "10: macros...")
|
|
(let [ctx (init)]
|
|
(ct-eval ctx "(defn add [a b] (+ a b))")
|
|
(assert (= 7 (ct-eval ctx "(add 3 4)")) "defn")
|
|
(assert (= 42 (ct-eval ctx "(when true 42)")) "when")
|
|
(assert (= 3 (ct-eval ctx "(and 1 2 3)")) "and")
|
|
(assert (= 1 (ct-eval ctx "(or 1 2 3)")) "or")
|
|
(assert (= 49 (ct-eval ctx "((fn [x] (* x x)) 7)")) "fn"))
|
|
(print " ok")
|
|
(print "11: higher-order...")
|
|
(let [ctx (init)]
|
|
(assert (= 3 (ct-eval ctx "((comp inc inc) 1)")) "comp")
|
|
(assert (function? (ct-eval ctx "(partial + 1 2)")) "partial returns fn")
|
|
(assert (= 3 (ct-eval ctx "(identity 3)")) "identity"))
|
|
(print " ok")
|
|
(print "12: constructors...")
|
|
(let [ctx (init)]
|
|
(assert (= 3 (ct-eval ctx "(count (vector 1 2 3))")) "vector count")
|
|
(assert (= 2 (ct-eval ctx "(count (hash-map :a 1 :b 2))")) "hash-map count")
|
|
(assert (= 3 (ct-eval ctx "(count (hash-set 1 2 3))")) "hash-set count")
|
|
(assert (= 3 (ct-eval ctx "(count (zipmap [:a :b :c] [1 2 3]))")) "zipmap count"))
|
|
(print " ok")
|
|
(print "All CLJS-ported tests passed!")
|