test: restructure into unit / integration / spec layers + shared harness
Reorganize the flat 49-file test/ into three layers (jpm test recurses, so all
are still discovered):
- test/unit/ white-box component tests (reader, evaluator, types,
persistent-map, lazy-seq, macro, interop, compiler)
- test/integration/ cross-cutting + regression batteries (conformance, jank,
sci-bootstrap/runtime, features, systematic-coverage, api,
core, namespaces, ported clojure suites) and
.../ports/ ported clojure/cljs test batches pending consolidation
- test/spec/ the behavioral contract (built out in following commits)
- test/support/harness.janet shared defspec table runner (cases compared via
Jolt's own =, with a :throws sentinel) + expect= helpers
Files moved with git mv (history preserved) and import paths fixed for depth.
jpm test green. README Test section updated.
Next: build out test/spec/ to cover the public API area-by-area, mining the
integration batteries and filling gaps.
This commit is contained in:
parent
1898308926
commit
16428179fa
52 changed files with 185 additions and 86 deletions
42
test/integration/ports/cljs-collections-test.janet
Normal file
42
test/integration/ports/cljs-collections-test.janet
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
(use ../../../src/jolt/api)
|
||||
(defn ct-eval [ctx s] (normalize-pvecs (eval-string ctx s)))
|
||||
(print "CLJS Collections Ported Tests")
|
||||
|
||||
(print "1: dissoc...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(= {:a :b} (dissoc {:a :b :c :d} :c))")) "dissoc")
|
||||
(assert (= true (ct-eval ctx "(= {} (dissoc {1 2 3 4} 1 3))")) "dissoc multi"))
|
||||
(print " ok")
|
||||
|
||||
(print "2: assoc...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(= {1 2 3 4} (assoc {} 1 2 3 4))")) "assoc multi")
|
||||
(assert (= true (ct-eval ctx "(= {1 2} (assoc {} 1 2))")) "assoc single"))
|
||||
(print " ok")
|
||||
|
||||
(print "3: set operations...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(set? (set []))")) "set empty")
|
||||
(assert (= true (ct-eval ctx "(= #{\"foo\"} (set [\"foo\"]))")) "set from vec")
|
||||
(assert (= true (ct-eval ctx "(= #{1 2 3} #{1 3 2})")) "set order")
|
||||
(assert (= true (ct-eval ctx "(= #{1 2 3} (disj #{1 2 3}))")) "disj none")
|
||||
(assert (= true (ct-eval ctx "(= #{1 2} (disj #{1 2 3} 3))")) "disj one")
|
||||
(assert (= true (ct-eval ctx "(= #{1} (disj #{1 2 3} 2 3))")) "disj multi")
|
||||
(assert (= true (ct-eval ctx "(= 4 (get #{1 2 3 4} 4))")) "get set")
|
||||
(assert (= true (ct-eval ctx "(contains? #{1 2 3 4} 4)")) "contains? set"))
|
||||
(print " ok")
|
||||
|
||||
(print "4: vector nth...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(= :a (nth [:a :b :c :d] 0))")) "nth")
|
||||
(assert (= true (ct-eval ctx "(= :c (nth [:a :b :c :d] 2 0.1))")) "nth float"))
|
||||
(print " ok")
|
||||
|
||||
(print "5: range...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(= 0 (count (range 10 0 1)))")) "range empty")
|
||||
(assert (= true (ct-eval ctx "(= 4 (count (range 0 10 3)))")) "range count")
|
||||
(assert (= true (ct-eval ctx "(= 1 (count (range 0 1 1)))")) "range single"))
|
||||
(print " ok")
|
||||
|
||||
(print "\nAll CLJS Collections Ported tests passed!")
|
||||
90
test/integration/ports/cljs-core-test.janet
Normal file
90
test/integration/ports/cljs-core-test.janet
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
(use ../../../src/jolt/api)
|
||||
(defn ct-eval [ctx s] (normalize-pvecs (eval-string ctx s)))
|
||||
(print "CLJS Core Ported Tests")
|
||||
|
||||
(print "1: metadata on maps...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(= {:foo \"bar\"} (meta (with-meta {:a 1} {:foo \"bar\"})))")) "with-meta on map"))
|
||||
(print " ok")
|
||||
|
||||
(print "2: atoms...")
|
||||
(let [ctx (init)]
|
||||
(ct-eval ctx "(def a (atom 0))")
|
||||
(assert (= true (ct-eval ctx "(= 0 (deref a))")) "deref")
|
||||
(assert (= true (ct-eval ctx "(= 1 (swap! a inc))")) "swap! inc")
|
||||
(ct-eval ctx "(def b (atom 0))")
|
||||
(assert (= true (ct-eval ctx "(= 1 (swap! b + 1))")) "swap! + 1")
|
||||
(assert (= true (ct-eval ctx "(= 4 (swap! b + 1 2))")) "swap! + 1 2")
|
||||
(assert (= true (ct-eval ctx "(= 10 (swap! b + 1 2 3))")) "swap! + 1 2 3")
|
||||
(assert (= true (ct-eval ctx "(= 20 (swap! b + 1 2 3 4))")) "swap! + 1 2 3 4")
|
||||
(assert (= true (ct-eval ctx "(atom? (atom 0))")) "atom?")
|
||||
(assert (= true (ct-eval ctx "(nil? (meta (atom 0)))")) "atom meta nil"))
|
||||
(print " ok")
|
||||
|
||||
(print "3: contains?...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(contains? {:a 1 :b 2} :a)")) "contains? map key")
|
||||
(assert (= true (ct-eval ctx "(not (contains? {:a 1 :b 2} :z))")) "contains? missing")
|
||||
(assert (= true (ct-eval ctx "(contains? [5 6 7] 1)")) "contains? vector index")
|
||||
(assert (= true (ct-eval ctx "(contains? [5 6 7] 2)")) "contains? vector index 2")
|
||||
(assert (= true (ct-eval ctx "(not (contains? [5 6 7] 3))")) "contains? vector oob")
|
||||
(assert (= true (ct-eval ctx "(not (contains? nil 42))")) "contains? nil"))
|
||||
(print " ok")
|
||||
|
||||
(print "4: get-in...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(= 1 (get-in {:foo 1 :bar 2} [:foo]))")) "get-in flat")
|
||||
(assert (= true (ct-eval ctx "(= 2 (get-in {:foo {:bar 2}} [:foo :bar]))")) "get-in nested"))
|
||||
(print " ok")
|
||||
|
||||
(print "5: multimethods...")
|
||||
(let [ctx (init)]
|
||||
(ct-eval ctx "(defmulti greet (fn [x] (:lang x)))")
|
||||
(ct-eval ctx "(defmethod greet :en [_] \"hello\")")
|
||||
(ct-eval ctx "(defmethod greet :fr [_] \"bonjour\")")
|
||||
(assert (= true (ct-eval ctx "(= \"hello\" (greet {:lang :en}))")) "dispatch :en")
|
||||
(assert (= true (ct-eval ctx "(= \"bonjour\" (greet {:lang :fr}))")) "dispatch :fr"))
|
||||
(print " ok")
|
||||
|
||||
(print "6: sequential equality...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(= (list 3 2 1) [3 2 1])")) "list = vector")
|
||||
(assert (= true (ct-eval ctx "(= () (rest nil))")) "rest nil")
|
||||
(assert (= true (ct-eval ctx "(= () (rest [1]))")) "rest [1]")
|
||||
(assert (= true (ct-eval ctx "(= () (rest ()))")) "rest empty"))
|
||||
(print " ok")
|
||||
|
||||
(print "7: seq operations...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(nil? (seq []))")) "seq empty vec"))
|
||||
(print " ok")
|
||||
|
||||
(print "8: empty and empty?...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(empty? nil)")) "empty? nil")
|
||||
(assert (= true (ct-eval ctx "(empty? ())")) "empty? ()")
|
||||
(assert (= true (ct-eval ctx "(empty? [])")) "empty? []")
|
||||
(assert (= true (ct-eval ctx "(empty? {})")) "empty? {}")
|
||||
(assert (= true (ct-eval ctx "(empty? #{})")) "empty? #{}")
|
||||
(assert (= true (ct-eval ctx "(empty? \"\")")) "empty? empty string")
|
||||
(assert (= true (ct-eval ctx "(not (empty? [1 2]))")) "empty? non-empty")
|
||||
(assert (= true (ct-eval ctx "(not (empty? {:a 1}))")) "empty? non-empty map"))
|
||||
(print " ok")
|
||||
|
||||
(print "9: distinct...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(= 0 (count (distinct ())))")) "distinct empty")
|
||||
(assert (= true (ct-eval ctx "(= 1 (count (distinct '(1))))")) "distinct single")
|
||||
(assert (= true (ct-eval ctx "(= 3 (count (distinct '(1 2 3 1 1 1))))")) "distinct multi count")
|
||||
(assert (= true (ct-eval ctx "(= 1 (count (distinct [42 42])))")) "distinct nums count"))
|
||||
(print " ok")
|
||||
|
||||
(print "10: some and some?...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(some? 1)")) "some? 1")
|
||||
(assert (= true (ct-eval ctx "(not (some? nil))")) "some? nil")
|
||||
(assert (= true (ct-eval ctx "(some even? [1 2 3])")) "some even?")
|
||||
(assert (= true (ct-eval ctx "(nil? (some even? [1 3 5]))")) "some even? nil"))
|
||||
(print " ok")
|
||||
|
||||
(print "\nAll CLJS Core Ported tests passed!")
|
||||
110
test/integration/ports/cljs-port-1-test.janet
Normal file
110
test/integration/ports/cljs-port-1-test.janet
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
(use ../../../src/jolt/api)
|
||||
(defn ct-eval [ctx s] (normalize-pvecs (eval-string ctx s)))
|
||||
(print "=== CLJS Ported Part 1 ===")
|
||||
(print "1: core math...")
|
||||
(let [ctx (init)]
|
||||
(assert (= 3 (ct-eval ctx "(+ 1 2)")) "+")
|
||||
(assert (= 0 (ct-eval ctx "(+)")) "+ zero")
|
||||
(assert (= 1 (ct-eval ctx "(- 3 2)")) "-")
|
||||
(assert (= 6 (ct-eval ctx "(* 2 3)")) "*")
|
||||
(assert (= 2 (ct-eval ctx "(/ 4 2)")) "/")
|
||||
(assert (= 3 (ct-eval ctx "(inc 2)")) "inc")
|
||||
(assert (= 1 (ct-eval ctx "(dec 2)")) "dec")
|
||||
(assert (= 1 (ct-eval ctx "(quot 5 3)")) "quot")
|
||||
(assert (= 2 (ct-eval ctx "(rem 5 3)")) "rem")
|
||||
(assert (= 2 (ct-eval ctx "(mod 5 3)")) "mod")
|
||||
(assert (= 3 (ct-eval ctx "(max 1 2 3)")) "max")
|
||||
(assert (= 1 (ct-eval ctx "(min 1 2 3)")) "min"))
|
||||
(print " passed")
|
||||
(print "2: predicates...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(nil? nil)")) "nil?")
|
||||
(assert (= false (ct-eval ctx "(nil? 1)")) "nil? false")
|
||||
(assert (= false (ct-eval ctx "(not true)")) "not")
|
||||
(assert (= true (ct-eval ctx "(not false)")) "not false")
|
||||
(assert (= true (ct-eval ctx "(some? 1)")) "some?")
|
||||
(assert (= true (ct-eval ctx "(string? \"hello\")")) "string?")
|
||||
(assert (= true (ct-eval ctx "(number? 42)")) "number?")
|
||||
(assert (= true (ct-eval ctx "(fn? inc)")) "fn?")
|
||||
(assert (= true (ct-eval ctx "(keyword? :foo)")) "keyword?")
|
||||
(assert (= true (ct-eval ctx "(map? {:a 1})")) "map?")
|
||||
(assert (= true (ct-eval ctx "(zero? 0)")) "zero?")
|
||||
(assert (= true (ct-eval ctx "(pos? 5)")) "pos?")
|
||||
(assert (= true (ct-eval ctx "(neg? -1)")) "neg?")
|
||||
(assert (= true (ct-eval ctx "(even? 4)")) "even?")
|
||||
(assert (= true (ct-eval ctx "(odd? 3)")) "odd?"))
|
||||
(print " passed")
|
||||
(print "3: comparison...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(= 1 1)")) "=")
|
||||
(assert (= false (ct-eval ctx "(= 1 2)")) "= false")
|
||||
(assert (= true (ct-eval ctx "(= 1 1 1)")) "= three")
|
||||
(assert (= false (ct-eval ctx "(not= 1 1)")) "not= false")
|
||||
(assert (= true (ct-eval ctx "(not= 1 2)")) "not= true")
|
||||
(assert (= true (ct-eval ctx "(< 1 2)")) "<")
|
||||
(assert (= true (ct-eval ctx "(> 2 1)")) ">")
|
||||
(assert (= true (ct-eval ctx "(<= 1 1)")) "<=")
|
||||
(assert (= true (ct-eval ctx "(>= 2 2)")) ">="))
|
||||
(print " passed")
|
||||
(print "4: vectors...")
|
||||
(let [ctx (init)]
|
||||
(assert (= :a (ct-eval ctx "(nth [:a :b :c :d] 0)")) "nth")
|
||||
(assert (= [1 2 3 4] (ct-eval ctx "(conj [1 2 3] 4)")) "conj")
|
||||
(assert (= 1 (ct-eval ctx "(first [1 2 3])")) "first")
|
||||
(assert (= [2 3] (ct-eval ctx "(rest [1 2 3])")) "rest")
|
||||
(assert (= 3 (ct-eval ctx "(count [1 2 3])")) "count"))
|
||||
(print " passed")
|
||||
(print "5: maps...")
|
||||
(let [ctx (init)]
|
||||
(assert (= 1 (ct-eval ctx "(get {:a 1} :a)")) "get")
|
||||
(assert (= nil (ct-eval ctx "(get {:a 1} :z)")) "get missing")
|
||||
(assert (= :d (ct-eval ctx "(get {:a 1} :z :d)")) "get default")
|
||||
(assert (= {:a 1 :b 2} (ct-eval ctx "(assoc {:a 1} :b 2)")) "assoc")
|
||||
(assert (= {:b 2} (ct-eval ctx "(dissoc {:a 1 :b 2} :a)")) "dissoc")
|
||||
(assert (= true (ct-eval ctx "(contains? {:a 1} :a)")) "contains?")
|
||||
(assert (= 3 (ct-eval ctx "(count {:a 1 :b 2 :c 3})")) "count")
|
||||
(assert (= 2 (ct-eval ctx "(count (keys {:a 1 :b 2}))")) "keys count"))
|
||||
(print " passed")
|
||||
(print "6: sets...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(set? #{1 2 3})")) "set?")
|
||||
(assert (= 4 (ct-eval ctx "(count (conj #{1 2 3} 4))")) "conj")
|
||||
(assert (= 2 (ct-eval ctx "(count (disj #{1 2 3} 3))")) "disj")
|
||||
(assert (= 3 (ct-eval ctx "(count #{1 2 3})")) "count")
|
||||
(assert (= true (ct-eval ctx "(= #{1 2 3} #{3 2 1})")) "= order-independent"))
|
||||
(print " passed")
|
||||
(print "7: seq operations...")
|
||||
(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 (= 2 (ct-eval ctx "(count (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 2 1] (ct-eval ctx "(reverse [1 2 3])")) "reverse")
|
||||
(assert (= true (ct-eval ctx "(every? even? [2 4 6])")) "every?"))
|
||||
(print " passed")
|
||||
(print "8: printing...")
|
||||
(let [ctx (init)]
|
||||
(assert (= "hello" (ct-eval ctx "(str \"hello\")")) "str")
|
||||
(assert (= "ab" (ct-eval ctx "(str \"a\" \"b\")")) "str two")
|
||||
(assert (= "42" (ct-eval ctx "(str 42)")) "str number")
|
||||
(assert (= "" (ct-eval ctx "(str nil)")) "str nil -> empty string (Clojure semantics)")
|
||||
(assert (= "a" (ct-eval ctx "(name :a)")) "name"))
|
||||
(print " passed")
|
||||
(print "9: apply...")
|
||||
(let [ctx (init)]
|
||||
(assert (= 3 (ct-eval ctx "(apply + [1 2])")) "apply +")
|
||||
(assert (= 3 (ct-eval ctx "(apply max [1 3 2])")) "apply max"))
|
||||
(print " passed")
|
||||
(print "10: equality across types...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(= {:a 1 :b 2} {:b 2 :a 1})")) "map order-independent"))
|
||||
(print " passed")
|
||||
(print "11: higher-order fns...")
|
||||
(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 " passed")
|
||||
(print "\nAll CLJS Ported Part 1 tests passed!")
|
||||
25
test/integration/ports/cljs-port-10-test.janet
Normal file
25
test/integration/ports/cljs-port-10-test.janet
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
(use ../../../src/jolt/api)
|
||||
(defn ct-eval [ctx s] (normalize-pvecs (eval-string ctx s)))
|
||||
(print "=== CLJS Ported Part 10 ===")
|
||||
|
||||
(print "43: when/when-not...")
|
||||
(let [ctx (init)]
|
||||
(assert (= 42 (ct-eval ctx "(when true 42)")) "when true")
|
||||
(assert (= nil (ct-eval ctx "(when false 42)")) "when false")
|
||||
(assert (= 42 (ct-eval ctx "(when-not false 42)")) "when-not false"))
|
||||
(print " ok")
|
||||
|
||||
(print "44: if-let/when-let...")
|
||||
(let [ctx (init)]
|
||||
(assert (= 2 (ct-eval ctx "(if-let [x 1] (inc x) 0)")) "if-let true")
|
||||
(assert (= 0 (ct-eval ctx "(if-let [x nil] (inc x) 0)")) "if-let nil")
|
||||
(assert (= 2 (ct-eval ctx "(when-let [x 1] (inc x))")) "when-let"))
|
||||
(print " ok")
|
||||
|
||||
(print "45: doto...")
|
||||
(let [ctx (init)]
|
||||
(ct-eval ctx "(def x (atom []))")
|
||||
(assert (= nil (ct-eval ctx "(doto nil)")) "doto nil returns nil"))
|
||||
(print " ok")
|
||||
|
||||
(print "\nAll CLJS Ported Part 10 tests passed!\n")
|
||||
77
test/integration/ports/cljs-port-1a-test.janet
Normal file
77
test/integration/ports/cljs-port-1a-test.janet
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
(use ../../../src/jolt/api)
|
||||
(defn ct-eval [ctx s] (normalize-pvecs (eval-string ctx s)))
|
||||
(print "=== CLJS Ported Part 1 ===")
|
||||
(print "1: core math...")
|
||||
(let [ctx (init)]
|
||||
(assert (= 3 (ct-eval ctx "(+ 1 2)")) "+")
|
||||
(assert (= 0 (ct-eval ctx "(+)")) "+ zero")
|
||||
(assert (= 1 (ct-eval ctx "(- 3 2)")) "-")
|
||||
(assert (= 6 (ct-eval ctx "(* 2 3)")) "*")
|
||||
(assert (= 2 (ct-eval ctx "(/ 4 2)")) "/")
|
||||
(assert (= 3 (ct-eval ctx "(inc 2)")) "inc")
|
||||
(assert (= 1 (ct-eval ctx "(dec 2)")) "dec")
|
||||
(assert (= 1 (ct-eval ctx "(quot 5 3)")) "quot")
|
||||
(assert (= 2 (ct-eval ctx "(rem 5 3)")) "rem")
|
||||
(assert (= 2 (ct-eval ctx "(mod 5 3)")) "mod")
|
||||
(assert (= 3 (ct-eval ctx "(max 1 2 3)")) "max")
|
||||
(assert (= 1 (ct-eval ctx "(min 1 2 3)")) "min"))
|
||||
(print " passed")
|
||||
(print "2: predicates...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(nil? nil)")) "nil?")
|
||||
(assert (= false (ct-eval ctx "(nil? 1)")) "nil? false")
|
||||
(assert (= false (ct-eval ctx "(not true)")) "not")
|
||||
(assert (= true (ct-eval ctx "(not false)")) "not false")
|
||||
(assert (= true (ct-eval ctx "(some? 1)")) "some?")
|
||||
(assert (= true (ct-eval ctx "(string? \"hello\")")) "string?")
|
||||
(assert (= true (ct-eval ctx "(number? 42)")) "number?")
|
||||
(assert (= true (ct-eval ctx "(fn? inc)")) "fn?")
|
||||
(assert (= true (ct-eval ctx "(keyword? :foo)")) "keyword?")
|
||||
(assert (= true (ct-eval ctx "(map? {:a 1})")) "map?")
|
||||
(assert (= true (ct-eval ctx "(zero? 0)")) "zero?")
|
||||
(assert (= true (ct-eval ctx "(pos? 5)")) "pos?")
|
||||
(assert (= true (ct-eval ctx "(neg? -1)")) "neg?")
|
||||
(assert (= true (ct-eval ctx "(even? 4)")) "even?")
|
||||
(assert (= true (ct-eval ctx "(odd? 3)")) "odd?"))
|
||||
(print " passed")
|
||||
(print "3: comparison...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(= 1 1)")) "=")
|
||||
(assert (= false (ct-eval ctx "(= 1 2)")) "= false")
|
||||
(assert (= true (ct-eval ctx "(= 1 1 1)")) "= three")
|
||||
(assert (= false (ct-eval ctx "(not= 1 1)")) "not= false")
|
||||
(assert (= true (ct-eval ctx "(not= 1 2)")) "not= true")
|
||||
(assert (= true (ct-eval ctx "(< 1 2)")) "<")
|
||||
(assert (= true (ct-eval ctx "(> 2 1)")) ">")
|
||||
(assert (= true (ct-eval ctx "(<= 1 1)")) "<=")
|
||||
(assert (= true (ct-eval ctx "(>= 2 2)")) ">="))
|
||||
(print " passed")
|
||||
(print "4: vectors...")
|
||||
(let [ctx (init)]
|
||||
(assert (= :a (ct-eval ctx "(nth [:a :b :c :d] 0)")) "nth")
|
||||
(assert (= [1 2 3 4] (ct-eval ctx "(conj [1 2 3] 4)")) "conj")
|
||||
(assert (= 1 (ct-eval ctx "(first [1 2 3])")) "first")
|
||||
(assert (= [2 3] (ct-eval ctx "(rest [1 2 3])")) "rest")
|
||||
(assert (= 3 (ct-eval ctx "(count [1 2 3])")) "count"))
|
||||
(print " passed")
|
||||
(print "5: maps...")
|
||||
(let [ctx (init)]
|
||||
(assert (= 1 (ct-eval ctx "(get {:a 1} :a)")) "get")
|
||||
(assert (= nil (ct-eval ctx "(get {:a 1} :z)")) "get missing")
|
||||
(assert (= :d (ct-eval ctx "(get {:a 1} :z :d)")) "get default")
|
||||
(assert (= {:a 1 :b 2} (ct-eval ctx "(assoc {:a 1} :b 2)")) "assoc")
|
||||
(assert (= {:b 2} (ct-eval ctx "(dissoc {:a 1 :b 2} :a)")) "dissoc")
|
||||
(assert (= true (ct-eval ctx "(contains? {:a 1} :a)")) "contains?")
|
||||
(assert (= 3 (ct-eval ctx "(count {:a 1 :b 2 :c 3})")) "count")
|
||||
(assert (= 2 (ct-eval ctx "(count (keys {:a 1 :b 2}))")) "keys count"))
|
||||
(print " passed")
|
||||
(print "6: sets...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(set? #{1 2 3})")) "set?")
|
||||
(assert (= 4 (ct-eval ctx "(count (conj #{1 2 3} 4))")) "conj count")
|
||||
(assert (= 2 (ct-eval ctx "(count (disj #{1 2 3} 3))")) "disj count")
|
||||
(assert (= 3 (ct-eval ctx "(count #{1 2 3})")) "count")
|
||||
(assert (= true (ct-eval ctx "(= #{1 2 3} #{3 2 1})")) "= order-independent"))
|
||||
(print " passed")
|
||||
(print "\nAll CLJS Ported Part 1a tests passed!")
|
||||
|
||||
37
test/integration/ports/cljs-port-1b-test.janet
Normal file
37
test/integration/ports/cljs-port-1b-test.janet
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
(use ../../../src/jolt/api)
|
||||
(defn ct-eval [ctx s] (normalize-pvecs (eval-string ctx s)))
|
||||
(print "=== CLJS Ported Part 1b ===")
|
||||
(print "7: seq operations...")
|
||||
(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 2 1] (ct-eval ctx "(reverse [1 2 3])")) "reverse")
|
||||
(assert (= true (ct-eval ctx "(every? even? [2 4 6])")) "every?"))
|
||||
(print " passed")
|
||||
(print "8: printing...")
|
||||
(let [ctx (init)]
|
||||
(assert (= "hello" (ct-eval ctx "(str \"hello\")")) "str")
|
||||
(assert (= "ab" (ct-eval ctx "(str \"a\" \"b\")")) "str two")
|
||||
(assert (= "42" (ct-eval ctx "(str 42)")) "str number")
|
||||
(assert (= "a" (ct-eval ctx "(name :a)")) "name"))
|
||||
(print " passed")
|
||||
(print "9: apply...")
|
||||
(let [ctx (init)]
|
||||
(assert (= 3 (ct-eval ctx "(apply + [1 2])")) "apply +")
|
||||
(assert (= 3 (ct-eval ctx "(apply max [1 3 2])")) "apply max"))
|
||||
(print " passed")
|
||||
(print "10: equality...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(= {:a 1 :b 2} {:b 2 :a 1})")) "map order"))
|
||||
(print " passed")
|
||||
(print "11: higher-order fns...")
|
||||
(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 " passed")
|
||||
(print "\nAll CLJS Ported Part 1b tests passed!")
|
||||
77
test/integration/ports/cljs-port-2-test.janet
Normal file
77
test/integration/ports/cljs-port-2-test.janet
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
(use ../../../src/jolt/api)
|
||||
(defn ct-eval [ctx s] (normalize-pvecs (eval-string ctx s)))
|
||||
(print "=== CLJS Ported Part 2 ===")
|
||||
(print "12: 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 "13: 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 catch"))
|
||||
(print " ok")
|
||||
(print "14: 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 "15: 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 "16: printing...")
|
||||
(let [ctx (init)]
|
||||
(assert (= "hello" (ct-eval ctx "(str \"hello\")")) "str")
|
||||
(assert (= "42" (ct-eval ctx "(str 42)")) "str number")
|
||||
(assert (= "a" (ct-eval ctx "(name :a)")) "name")
|
||||
(assert (= ":hello" (ct-eval ctx "(pr-str :hello)")) "pr-str keyword"))
|
||||
(print " ok")
|
||||
(print "17: apply...")
|
||||
(let [ctx (init)]
|
||||
(assert (= 3 (ct-eval ctx "(apply + [1 2])")) "apply +")
|
||||
(assert (= 3 (ct-eval ctx "(apply max [1 3 2])")) "apply max"))
|
||||
(print " ok")
|
||||
(print "18: equality...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(= {:a 1 :b 2} {:b 2 :a 1})")) "map order-independent")
|
||||
(assert (= false (ct-eval ctx "(= {:a 1} {:a 2})")) "map different values")
|
||||
(assert (= 1 (ct-eval ctx "(:a (with-meta {:a 1} {:c 3}))")) "with-meta preserves value")
|
||||
(assert (= 3 (ct-eval ctx "(:c (with-meta {:a 1} {:c 3}))")) "with-meta preserves meta via get"))
|
||||
(print " ok")
|
||||
(print "19: 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 "20: seq edge cases...")
|
||||
(let [ctx (init)]
|
||||
(assert (= nil (ct-eval ctx "(seq [])")) "seq empty")
|
||||
(assert (= nil (ct-eval ctx "(seq nil)")) "seq nil")
|
||||
(assert (= nil (ct-eval ctx "(first nil)")) "first nil")
|
||||
(assert (= 1 (ct-eval ctx "(first [1 2 3])")) "first vector"))
|
||||
(print " ok")
|
||||
(print "21: atoms extended...")
|
||||
(let [ctx (init)]
|
||||
(ct-eval ctx "(def a (atom 10))")
|
||||
(assert (= 10 (ct-eval ctx "(deref a)")) "deref")
|
||||
(ct-eval ctx "(reset! a 42)")
|
||||
(assert (= 42 (ct-eval ctx "(deref a)")) "reset!")
|
||||
(ct-eval ctx "(swap! a inc)")
|
||||
(assert (= 43 (ct-eval ctx "(deref a)")) "swap! inc")
|
||||
(assert (= 43 (ct-eval ctx "@a")) "@ deref macro"))
|
||||
(print " ok")
|
||||
(print "\nAll CLJS Ported Part 2 tests passed!")
|
||||
32
test/integration/ports/cljs-port-3-test.janet
Normal file
32
test/integration/ports/cljs-port-3-test.janet
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
(use ../../../src/jolt/api)
|
||||
(defn ct-eval [ctx s] (normalize-pvecs (eval-string ctx s)))
|
||||
(print "=== CLJS Ported Part 3 ===")
|
||||
(print "16: destructuring...")
|
||||
(let [ctx (init)]
|
||||
(assert (= 1 (ct-eval ctx "(let [[x] [1 2 3]] x)")) "seq destructure")
|
||||
(assert (= 2 (ct-eval ctx "(let [[_ y] [1 2 3]] y)")) "seq destructure rest")
|
||||
(assert (= 3 (ct-eval ctx "(let [[_ _ z] [1 2 3]] z)")) "seq destructure last"))
|
||||
(print " passed")
|
||||
(print "17: set operations...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(set? #{1 2 3})")) "set?")
|
||||
(assert (= 3 (ct-eval ctx "(count #{1 2 3})")) "set count")
|
||||
(assert (= true (ct-eval ctx "(contains? #{1 2} 1)")) "contains? set")
|
||||
(assert (= 1 (ct-eval ctx "(get #{1 2 3} 1)")) "get set"))
|
||||
(print " passed")
|
||||
(print "18: reader literals...")
|
||||
(let [ctx (init)]
|
||||
(assert (= [1 2 3] (ct-eval ctx "[1 2 3]")) "vector literal")
|
||||
(assert (= {:a 1} (ct-eval ctx "{:a 1}")) "map literal")
|
||||
(assert (= true (ct-eval ctx "true")) "true literal")
|
||||
(assert (= nil (ct-eval ctx "nil")) "nil literal")
|
||||
(assert (= 42 (ct-eval ctx "42")) "number literal"))
|
||||
(print " passed")
|
||||
(print "19: syntax-quote...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(= '(1 2 3) '(1 2 3))")) "sq basic list"))
|
||||
(print " passed")
|
||||
(print "20: walk...")
|
||||
(print " skipped (clojure.walk needs IFn protocol)")
|
||||
|
||||
(print "\nAll CLJS Ported Part 3 tests passed!")
|
||||
22
test/integration/ports/cljs-port-3b-test.janet
Normal file
22
test/integration/ports/cljs-port-3b-test.janet
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
(use ../../../src/jolt/api)
|
||||
(defn ct-eval [ctx s] (normalize-pvecs (eval-string ctx s)))
|
||||
(print "=== CLJS Ported Part 3b ===")
|
||||
(print "21: clojure.string...")
|
||||
(let [ctx (init)]
|
||||
(load-string ctx (slurp "src/jolt/clojure/string.clj"))
|
||||
(assert (= true (ct-eval ctx "(blank? nil)")) "blank? nil")
|
||||
(assert (= true (ct-eval ctx "(blank? \" \")")) "blank? spaces")
|
||||
(assert (= "Abc" (ct-eval ctx "(capitalize \"abc\")")) "capitalize")
|
||||
(assert (= "hello" (ct-eval ctx "(lower-case \"HELLO\")")) "lower-case")
|
||||
(assert (= "hello" (ct-eval ctx "(trim \" hello \")")) "trim"))
|
||||
(print " passed")
|
||||
(print "22: clojure.set...")
|
||||
(let [ctx (init)]
|
||||
(load-string ctx (slurp "src/jolt/clojure/set.clj"))
|
||||
(assert (= 3 (ct-eval ctx "(count (union #{1 2} #{2 3}))")) "union")
|
||||
(assert (= 1 (ct-eval ctx "(count (intersection #{1 2} #{2 3}))")) "intersection")
|
||||
(assert (= 1 (ct-eval ctx "(count (difference #{1 2} #{2 3}))")) "difference"))
|
||||
(print " passed")
|
||||
(print "\nAll CLJS Ported Part 3 tests passed!")
|
||||
|
||||
(print "\nAll CLJS Ported Part 3b tests passed!")
|
||||
48
test/integration/ports/cljs-port-4-test.janet
Normal file
48
test/integration/ports/cljs-port-4-test.janet
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
(use ../../../src/jolt/api)
|
||||
(defn ct-eval [ctx s] (normalize-pvecs (eval-string ctx s)))
|
||||
(print "=== CLJS Ported Part 4 ===")
|
||||
|
||||
(print "23: deftype/defrecord...")
|
||||
(let [ctx (init)]
|
||||
(ct-eval ctx "(deftype Point [x y])")
|
||||
(assert (= true (ct-eval ctx "(instance? Point (Point. 3 4))")) "instance? true")
|
||||
(assert (= 3 (ct-eval ctx "(. (Point. 3 4) x)")) ".field access")
|
||||
(ct-eval ctx "(defrecord Person [name age])")
|
||||
(assert (= true (ct-eval ctx "(map? (Person. \"A\" 30))")) "record is map?")
|
||||
(assert (= "Alice" (ct-eval ctx "(:name (Person. \"Alice\" 30))")) "record keyword access"))
|
||||
(print " ok")
|
||||
|
||||
(print "24: multimethods...")
|
||||
(let [ctx (init)]
|
||||
(ct-eval ctx "(defmulti greet (fn [x] (:lang x)))")
|
||||
(ct-eval ctx "(defmethod greet :en [_] \"hello\")")
|
||||
(ct-eval ctx "(defmethod greet :fr [_] \"bonjour\")")
|
||||
(assert (= "hello" (ct-eval ctx "(greet {:lang :en})")) "dispatch :en")
|
||||
(assert (= "bonjour" (ct-eval ctx "(greet {:lang :fr})")) "dispatch :fr"))
|
||||
(print " ok")
|
||||
|
||||
(print "25: protocols...")
|
||||
(let [ctx (init)]
|
||||
(ct-eval ctx "(defprotocol Greet (g [this]))")
|
||||
(ct-eval ctx "(deftype Dog [name])")
|
||||
(ct-eval ctx "(extend-type Dog Greet (g [this] (str \"woof \" (.-name this))))")
|
||||
(assert (= "woof Rex" (ct-eval ctx "(g (Dog. \"Rex\"))")) "extend-type"))
|
||||
(print " ok")
|
||||
|
||||
(print "26: var system...")
|
||||
(let [ctx (init)]
|
||||
(ct-eval ctx "(def xv 42)")
|
||||
(assert (= true (ct-eval ctx "(var? (var xv))")) "var?")
|
||||
(assert (= 42 (ct-eval ctx "(var-get (var xv))")) "var-get")
|
||||
(ct-eval ctx "(var-set (var xv) 99)")
|
||||
(assert (= 99 (ct-eval ctx "(var-get (var xv))")) "var-set"))
|
||||
(print " ok")
|
||||
|
||||
(print "27: range/into/concat...")
|
||||
(let [ctx (init)]
|
||||
(assert (= 5 (ct-eval ctx "(count (range 5))")) "range count")
|
||||
(assert (= [0 1 2 3 4] (ct-eval ctx "(into [] (range 5))")) "range into vec")
|
||||
(assert (= 4 (ct-eval ctx "(count (concat [1 2] [3 4]))")) "concat count"))
|
||||
(print " ok")
|
||||
|
||||
(print "\nAll CLJS Ported Part 4 tests passed!")
|
||||
22
test/integration/ports/cljs-port-5-test.janet
Normal file
22
test/integration/ports/cljs-port-5-test.janet
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
(use ../../../src/jolt/api)
|
||||
(defn ct-eval [ctx s] (normalize-pvecs (eval-string ctx s)))
|
||||
(print "=== CLJS Ported Part 5 ===")
|
||||
(print "22: destructuring...")
|
||||
(let [ctx (init)]
|
||||
(assert (= 1 (ct-eval ctx "(let [[x] [1 2 3]] x)")) "seq destructure")
|
||||
(assert (= 2 (ct-eval ctx "(let [[_ y] [1 2 3]] y)")) "seq destructure rest"))
|
||||
(print " ok")
|
||||
(print "23: metadata...")
|
||||
(let [ctx (init)]
|
||||
(ct-eval ctx "(def ^:dynamic *dyn* 42)")
|
||||
(assert (= true (ct-eval ctx "(var-dynamic? (var *dyn*))")) "dynamic metadata")
|
||||
(assert (= 1 (ct-eval ctx "(:a (with-meta {:a 1} {:c 3}))")) "with-meta preserves"))
|
||||
(print " ok")
|
||||
(print "24: function composition...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "((complement odd?) 2)")) "complement")
|
||||
(assert (= 5 (ct-eval ctx "((constantly 5) :anything)")) "constantly")
|
||||
(assert (= true (ct-eval ctx "((every-pred number? even?) 4)")) "every-pred")
|
||||
(assert (= ":hello" (ct-eval ctx "(pr-str :hello)")) "pr-str keyword"))
|
||||
(print " ok")
|
||||
(print "\nAll CLJS Ported Part 5 tests passed!")
|
||||
30
test/integration/ports/cljs-port-6-test.janet
Normal file
30
test/integration/ports/cljs-port-6-test.janet
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
(use ../../../src/jolt/api)
|
||||
(defn ct-eval [ctx s] (normalize-pvecs (eval-string ctx s)))
|
||||
(print "=== CLJS Ported Part 6 ===")
|
||||
|
||||
(print "28: anon fn #()...")
|
||||
(let [ctx (init)]
|
||||
(assert (= 6 (ct-eval ctx "(#(+ % 5) 1)")) "#() %")
|
||||
(assert (= 0 (ct-eval ctx "(#(do 0))")) "#() do body"))
|
||||
(print " ok")
|
||||
|
||||
(print "29: symbol operations...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(symbol? 'foo)")) "symbol?")
|
||||
(assert (= "foo" (ct-eval ctx "(name 'foo)")) "name symbol")
|
||||
(assert (= "bar" (ct-eval ctx "(name :bar)")) "name keyword"))
|
||||
(print " ok")
|
||||
|
||||
(print "30: keyword operations...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(keyword? :foo)")) "keyword?")
|
||||
(assert (= :foo (ct-eval ctx "(keyword \"foo\")")) "keyword string"))
|
||||
(print " ok")
|
||||
|
||||
(print "31: list operations...")
|
||||
(let [ctx (init)]
|
||||
(assert (= 3 (ct-eval ctx "(count (list 3 2 1))")) "list count")
|
||||
(assert (= 1 (ct-eval ctx "(first '(1 2 3))")) "first list"))
|
||||
(print " ok")
|
||||
|
||||
(print "\nAll CLJS Ported Part 6 tests passed!\n")
|
||||
20
test/integration/ports/cljs-port-7-test.janet
Normal file
20
test/integration/ports/cljs-port-7-test.janet
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
(use ../../../src/jolt/api)
|
||||
(defn ct-eval [ctx s] (normalize-pvecs (eval-string ctx s)))
|
||||
(print "=== CLJS Ported Part 7 ===")
|
||||
|
||||
(print "32: seq destructuring...")
|
||||
(let [ctx (init)]
|
||||
(assert (= 1 (ct-eval ctx "(let [[x] [1 2 3]] x)")) "seq destructure")
|
||||
(assert (= 2 (ct-eval ctx "(let [[_ y] [1 2 3]] y)")) "seq destructure skip")
|
||||
(assert (= 3 (ct-eval ctx "(let [[_ _ z] [1 2 3]] z)")) "seq destructure end"))
|
||||
(print " ok")
|
||||
|
||||
(print "33: & rest args...")
|
||||
(let [ctx (init)]
|
||||
(ct-eval ctx "(defn sum [& xs] (apply + xs))")
|
||||
(assert (= 6 (ct-eval ctx "(sum 1 2 3)")) "& rest sum")
|
||||
(ct-eval ctx "(defn first-two [a b & rest] (count rest))")
|
||||
(assert (= 2 (ct-eval ctx "(first-two 1 2 3 4)")) "& rest after fixed"))
|
||||
(print " ok")
|
||||
|
||||
(print "\nAll CLJS Ported Part 7 tests passed!\n")
|
||||
35
test/integration/ports/cljs-port-8-test.janet
Normal file
35
test/integration/ports/cljs-port-8-test.janet
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
(use ../../../src/jolt/api)
|
||||
(defn ct-eval [ctx s] (normalize-pvecs (eval-string ctx s)))
|
||||
(print "=== CLJS Ported Part 8 ===")
|
||||
|
||||
(print "35: range and repeat...")
|
||||
(let [ctx (init)]
|
||||
(assert (= 5 (ct-eval ctx "(count (range 5))")) "range")
|
||||
(assert (= 4 (ct-eval ctx "(count (repeat 4 :x))")) "repeat")
|
||||
(assert (= 3 (ct-eval ctx "(count (repeatedly 3 (constantly :y)))")) "repeatedly"))
|
||||
(print " ok")
|
||||
|
||||
(print "36: concat and into...")
|
||||
(let [ctx (init)]
|
||||
(assert (= 4 (ct-eval ctx "(count (concat [1 2] [3 4]))")) "concat")
|
||||
(assert (= 4 (ct-eval ctx "(count (into [] (range 4)))")) "into"))
|
||||
(print " ok")
|
||||
|
||||
(print "37: take-while/drop-while...")
|
||||
(let [ctx (init)]
|
||||
(assert (= 2 (ct-eval ctx "(count (take-while even? [2 4 3 5]))")) "take-while")
|
||||
(assert (= 2 (ct-eval ctx "(count (drop-while even? [2 4 3 5]))")) "drop-while"))
|
||||
(print " ok")
|
||||
|
||||
(print "38: partition...")
|
||||
(let [ctx (init)]
|
||||
(assert (= 2 (ct-eval ctx "(count (partition 2 [1 2 3 4]))")) "partition 2"))
|
||||
(print " ok")
|
||||
|
||||
(print "39: sorting...")
|
||||
(let [ctx (init)]
|
||||
(assert (= [1 2 3] (ct-eval ctx "(sort [3 1 2])")) "sort")
|
||||
(assert (= [1 2 3] (ct-eval ctx "(distinct [1 2 1 3 2])")) "distinct"))
|
||||
(print " ok")
|
||||
|
||||
(print "\nAll CLJS Ported Part 8 tests passed!\n")
|
||||
18
test/integration/ports/cljs-port-9-test.janet
Normal file
18
test/integration/ports/cljs-port-9-test.janet
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
(use ../../../src/jolt/api)
|
||||
(defn ct-eval [ctx s] (normalize-pvecs (eval-string ctx s)))
|
||||
(print "=== CLJS Ported Part 9 ===")
|
||||
|
||||
(print "40: seq predicates...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(empty? [])")) "empty? true")
|
||||
(assert (= false (ct-eval ctx "(empty? [1])")) "empty? false")
|
||||
(assert (= true (ct-eval ctx "(every? pos? [1 2 3])")) "every? pos"))
|
||||
(print " ok")
|
||||
|
||||
(print "41: complement...")
|
||||
(let [ctx (init)]
|
||||
(assert (= false (ct-eval ctx "((complement pos?) 1)")) "complement pos")
|
||||
(assert (= true (ct-eval ctx "((complement pos?) -1)")) "complement neg"))
|
||||
(print " ok")
|
||||
|
||||
(print "\nAll CLJS Ported Part 9 tests passed!\n")
|
||||
131
test/integration/ports/cljs-port-test.janet
Normal file
131
test/integration/ports/cljs-port-test.janet
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
(use ../../../src/jolt/api)
|
||||
(defn ct-eval [ctx s] (normalize-pvecs (eval-string ctx s)))
|
||||
(print "CLJS Ported Tests")
|
||||
|
||||
(print "1: math...")
|
||||
(let [ctx (init)]
|
||||
(assert (= 3 (ct-eval ctx "(+ 1 2)")) "+")
|
||||
(assert (= 1 (ct-eval ctx "(- 3 2)")) "-")
|
||||
(assert (= 6 (ct-eval ctx "(* 2 3)")) "*")
|
||||
(assert (= 3 (ct-eval ctx "(inc 2)")) "inc")
|
||||
(assert (= 1 (ct-eval ctx "(dec 2)")) "dec")
|
||||
(assert (= 1 (ct-eval ctx "(quot 5 3)")) "quot")
|
||||
(assert (= 2 (ct-eval ctx "(rem 5 3)")) "rem")
|
||||
(assert (= 2 (ct-eval ctx "(mod 5 3)")) "mod")
|
||||
(assert (= 3 (ct-eval ctx "(max 1 2 3)")) "max")
|
||||
(assert (= 1 (ct-eval ctx "(min 1 2 3)")) "min"))
|
||||
(print " ok")
|
||||
|
||||
(print "2: predicates...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(nil? nil)")) "nil?")
|
||||
(assert (= false (ct-eval ctx "(nil? 1)")) "nil? false")
|
||||
(assert (= false (ct-eval ctx "(not true)")) "not")
|
||||
(assert (= true (ct-eval ctx "(not false)")) "not false")
|
||||
(assert (= true (ct-eval ctx "(some? 1)")) "some?")
|
||||
(assert (= true (ct-eval ctx "(number? 42)")) "number?")
|
||||
(assert (= true (ct-eval ctx "(fn? inc)")) "fn?")
|
||||
(assert (= true (ct-eval ctx "(keyword? :foo)")) "keyword?")
|
||||
(assert (= true (ct-eval ctx "(zero? 0)")) "zero?")
|
||||
(assert (= true (ct-eval ctx "(pos? 5)")) "pos?")
|
||||
(assert (= true (ct-eval ctx "(neg? -1)")) "neg?")
|
||||
(assert (= true (ct-eval ctx "(even? 4)")) "even?")
|
||||
(assert (= true (ct-eval ctx "(odd? 3)")) "odd?"))
|
||||
(print " ok")
|
||||
|
||||
(print "3: comparison...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(= 1 1)")) "=")
|
||||
(assert (= true (ct-eval ctx "(not= 1 2)")) "not= true")
|
||||
(assert (= true (ct-eval ctx "(< 1 2)")) "<")
|
||||
(assert (= true (ct-eval ctx "(> 2 1)")) ">")
|
||||
(assert (= true (ct-eval ctx "(<= 1 1)")) "<=")
|
||||
(assert (= true (ct-eval ctx "(>= 2 2)")) ">="))
|
||||
(print " ok")
|
||||
|
||||
(print "4: vectors...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(= :a (nth [:a :b :c :d] 0))")) "nth")
|
||||
(assert (= true (ct-eval ctx "(= 4 (count (conj [1 2 3] 4)))")) "conj count")
|
||||
(assert (= true (ct-eval ctx "(= 1 (first [1 2 3]))")) "first")
|
||||
(assert (= true (ct-eval ctx "(= 2 (count (rest [1 2 3])))")) "rest count")
|
||||
(assert (= true (ct-eval ctx "(= 3 (count [1 2 3]))")) "count"))
|
||||
(print " ok")
|
||||
|
||||
(print "5: maps...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(= 1 (get {:a 1} :a))")) "get")
|
||||
(assert (= true (ct-eval ctx "(nil? (get {:a 1} :z))")) "get missing")
|
||||
(assert (= true (ct-eval ctx "(= :d (get {:a 1} :z :d))")) "get default")
|
||||
(assert (= true (ct-eval ctx "(= 2 (count (assoc {:a 1} :b 2)))")) "assoc count")
|
||||
(assert (= true (ct-eval ctx "(= 1 (count (dissoc {:a 1 :b 2} :a)))")) "dissoc count")
|
||||
(assert (= true (ct-eval ctx "(contains? {:a 1} :a)")) "contains?")
|
||||
(assert (= true (ct-eval ctx "(= 3 (count {:a 1 :b 2 :c 3}))")) "count")
|
||||
(assert (= true (ct-eval ctx "(= 2 (count (keys {:a 1 :b 2})))")) "keys"))
|
||||
(print " ok")
|
||||
|
||||
(print "6: sets...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(set? #{1 2 3})")) "set?")
|
||||
(assert (= true (ct-eval ctx "(= 4 (count (conj #{1 2 3} 4)))")) "conj count")
|
||||
(assert (= true (ct-eval ctx "(= 2 (count (disj #{1 2 3} 3)))")) "disj count")
|
||||
(assert (= true (ct-eval ctx "(= 3 (count #{1 2 3}))")) "count")
|
||||
(assert (= true (ct-eval ctx "(= #{1 2 3} #{3 2 1})")) "= order"))
|
||||
(print " ok")
|
||||
|
||||
(print "7: seq ops...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(nil? (seq []))")) "seq empty")
|
||||
(assert (= true (ct-eval ctx "(= 3 (count (map inc [1 2 3])))")) "map count")
|
||||
(assert (= true (ct-eval ctx "(= 2 (count (filter odd? [1 2 3 4])))")) "filter count")
|
||||
(assert (= true (ct-eval ctx "(= 6 (reduce + [1 2 3]))")) "reduce")
|
||||
(assert (= true (ct-eval ctx "(= 3 (count (take 3 [1 2 3 4 5])))")) "take count")
|
||||
(assert (= true (ct-eval ctx "(= 2 (count (drop 3 [1 2 3 4 5])))")) "drop count")
|
||||
(assert (= true (ct-eval ctx "(= 3 (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 (= true (ct-eval ctx "(= 0 (deref (atom 0)))")) "deref")
|
||||
(assert (= true (ct-eval ctx "(= 1 (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 (= true (ct-eval ctx "(= 30 (let [x 10 y 20] (+ x y)))")) "let")
|
||||
(assert (= true (ct-eval ctx "(= :a (if true :a :b))")) "if true")
|
||||
(assert (= true (ct-eval ctx "(= :b (if false :a :b))")) "if false")
|
||||
(assert (= true (ct-eval ctx "(= 2 (do 1 2))")) "do")
|
||||
(assert (= true (ct-eval ctx "(= 3 (loop [x 0] (if (< x 3) (recur (inc x)) x)))")) "loop")
|
||||
(assert (= true (ct-eval ctx "(= :caught (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 (= true (ct-eval ctx "(= 7 (add 3 4))")) "defn")
|
||||
(assert (= true (ct-eval ctx "(= 42 (when true 42))")) "when")
|
||||
(assert (= true (ct-eval ctx "(= 3 (and 1 2 3))")) "and")
|
||||
(assert (= true (ct-eval ctx "(= 1 (or 1 2 3))")) "or")
|
||||
(assert (= true (ct-eval ctx "(= 49 ((fn [x] (* x x)) 7))")) "fn"))
|
||||
(print " ok")
|
||||
|
||||
(print "11: higher-order...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(= 3 ((comp inc inc) 1))")) "comp")
|
||||
(assert (= true (ct-eval ctx "(= 3 ((partial + 1 2)))")) "partial")
|
||||
(assert (= true (ct-eval ctx "(= 5 ((constantly 5) :anything))")) "constantly")
|
||||
(assert (= true (ct-eval ctx "(= 3 (identity 3))")) "identity"))
|
||||
(print " ok")
|
||||
|
||||
(print "12: constructors...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(= 3 (count (vector 1 2 3)))")) "vector count")
|
||||
(assert (= true (ct-eval ctx "(= 2 (count (hash-map :a 1 :b 2)))")) "hash-map count")
|
||||
(assert (= true (ct-eval ctx "(= 3 (count (hash-set 1 2 3)))")) "hash-set count")
|
||||
(assert (= true (ct-eval ctx "(= 3 (count (zipmap [:a :b :c] [1 2 3])))")) "zipmap count"))
|
||||
(print " ok")
|
||||
|
||||
(print "\nAll CLJS Ported Tests passed!")
|
||||
59
test/integration/ports/phase10-test.janet
Normal file
59
test/integration/ports/phase10-test.janet
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
(use ../../../src/jolt/api)
|
||||
(use ../../../src/jolt/reader)
|
||||
(use ../../../src/jolt/evaluator)
|
||||
|
||||
(defn ct-eval [ctx s] (normalize-pvecs (eval-string ctx s)))
|
||||
|
||||
(defn load-clj [ctx filepath]
|
||||
(def source (slurp filepath))
|
||||
(var remaining source)
|
||||
(while (> (length (string/trim remaining)) 0)
|
||||
(def fr (parse-next remaining))
|
||||
(def form (fr 0))
|
||||
(set remaining (fr 1))
|
||||
(when (not (nil? form))
|
||||
(eval-form ctx @{} form))))
|
||||
|
||||
(print "40: clojure.string...")
|
||||
(let [ctx (init)]
|
||||
(load-clj ctx "src/jolt/clojure/string.clj")
|
||||
(assert (= true (ct-eval ctx "(blank? nil)")) "blank? nil")
|
||||
(assert (= true (ct-eval ctx "(blank? \" \")")) "blank? whitespace")
|
||||
(assert (= false (ct-eval ctx "(blank? \"a\")")) "blank? non-empty")
|
||||
(assert (= "Abc" (ct-eval ctx "(capitalize \"abc\")")) "capitalize")
|
||||
(assert (= "hello" (ct-eval ctx "(lower-case \"HELLO\")")) "lower-case")
|
||||
(assert (= "HELLO" (ct-eval ctx "(upper-case \"hello\")")) "upper-case")
|
||||
(assert (= true (ct-eval ctx "(includes? \"hello\" \"ell\")")) "includes? true")
|
||||
(assert (= "foo" (ct-eval ctx "(trim \"foo\")")) "trim")
|
||||
(assert (= true (ct-eval ctx "(starts-with? \"hello\" \"he\")")) "starts-with? true")
|
||||
(assert (= true (ct-eval ctx "(ends-with? \"hello\" \"lo\")")) "ends-with? true"))
|
||||
(print " passed")
|
||||
|
||||
(print "41: clojure.set...")
|
||||
(let [ctx (init)]
|
||||
(load-clj ctx "src/jolt/clojure/set.clj")
|
||||
(assert (= 3 (ct-eval ctx "(count (union #{1 2} #{2 3}))")) "union")
|
||||
(assert (= 1 (ct-eval ctx "(count (intersection #{1 2} #{2 3}))")) "intersection")
|
||||
(assert (= 1 (ct-eval ctx "(count (difference #{1 2} #{2 3}))")) "difference")
|
||||
(assert (= true (ct-eval ctx "(subset? #{1} #{1 2 3})")) "subset? true")
|
||||
(assert (= true (ct-eval ctx "(superset? #{1 2 3} #{1})")) "superset? true"))
|
||||
(print " passed")
|
||||
|
||||
(print "42: clojure.walk/zip — modules loadable")
|
||||
(let [ctx (init)] (load-clj ctx "src/jolt/clojure/walk.clj") (print " walk: loaded"))
|
||||
(let [ctx (init)] (load-clj ctx "src/jolt/clojure/zip.clj") (print " zip: loaded"))
|
||||
(print " passed")
|
||||
|
||||
(print "43: stdlib summary")
|
||||
(print " clojure.string — 19 functions")
|
||||
(print " clojure.set — 10 functions")
|
||||
(print " clojure.walk — 7 functions")
|
||||
(print " clojure.zip — zipper data structure")
|
||||
(print " clojure.edn — EDN reader/writer stubs")
|
||||
(print " clojure.java-io — file I/O wrappers")
|
||||
(print " jolt.interop — Janet interop")
|
||||
(print " jolt.shell — shell command execution")
|
||||
(print " jolt.http — HTTP client")
|
||||
(print " passed")
|
||||
|
||||
(print "All Phase 10 tests passed!")
|
||||
50
test/integration/ports/phase12-test.janet
Normal file
50
test/integration/ports/phase12-test.janet
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
# Phase 12: Protocol System Tests
|
||||
(use ../../../src/jolt/api)
|
||||
(defn ct-eval [ctx s] (normalize-pvecs (eval-string ctx s)))
|
||||
|
||||
(print "35: defprotocol...")
|
||||
(let [ctx (init)]
|
||||
(ct-eval ctx "(defprotocol Greet (greet [this]))")
|
||||
(let [p (ct-eval ctx "Greet")]
|
||||
(assert (not (nil? p)) "protocol var exists")
|
||||
(assert (= :jolt/protocol (get p :jolt/type)) "protocol type tag")
|
||||
(assert (get (get p :methods) :greet) "protocol has greet method"))
|
||||
(assert (or (function? (ct-eval ctx "greet")) (cfunction? (ct-eval ctx "greet"))) "method fn exists"))
|
||||
(print " passed")
|
||||
|
||||
(print "36: extend-type...")
|
||||
(let [ctx (init)]
|
||||
(ct-eval ctx "(deftype Person [name])")
|
||||
(ct-eval ctx "(defprotocol Namable (get-name [this]))")
|
||||
(ct-eval ctx "(extend-type Person Namable (get-name [this] (.-name this)))")
|
||||
(assert (= "Alice" (ct-eval ctx "(get-name (Person. \"Alice\"))")) "extend-type works"))
|
||||
(print " passed")
|
||||
|
||||
(print "37: extend-protocol...")
|
||||
(let [ctx (init)]
|
||||
(ct-eval ctx "(deftype Dog [breed])")
|
||||
(ct-eval ctx "(deftype Cat [color])")
|
||||
(ct-eval ctx "(defprotocol Animal (speak [this]))")
|
||||
(ct-eval ctx "(extend-protocol Animal
|
||||
Dog (speak [this] (str \"woof from \" (.-breed this)))
|
||||
Cat (speak [this] (str \"meow from \" (.-color this))))")
|
||||
(assert (= "woof from poodle" (ct-eval ctx "(speak (Dog. \"poodle\"))")) "dog speak")
|
||||
(assert (= "meow from black" (ct-eval ctx "(speak (Cat. \"black\"))")) "cat speak"))
|
||||
(print " passed")
|
||||
|
||||
(print "38: satisfies?...")
|
||||
(let [ctx (init)]
|
||||
(ct-eval ctx "(deftype Point [x y])")
|
||||
(ct-eval ctx "(defprotocol Locatable (location [this]))")
|
||||
(ct-eval ctx "(extend-type Point Locatable (location [this] [(.-x this) (.-y this)]))")
|
||||
(assert (= true (ct-eval ctx "(satisfies? Locatable (Point. 3 4))")) "satisfies? true")
|
||||
(assert (= false (ct-eval ctx "(satisfies? Locatable {:x 1})")) "satisfies? false"))
|
||||
(print " passed")
|
||||
|
||||
(print "39: reify...")
|
||||
(let [ctx (init)]
|
||||
(ct-eval ctx "(defprotocol Stringable (to-str [this]))")
|
||||
(assert (= "works" (ct-eval ctx "(to-str (reify Stringable (to-str [this] \"works\")))")) "reify single method"))
|
||||
(print " passed")
|
||||
|
||||
(print "\nAll Phase 12 tests passed!")
|
||||
44
test/integration/ports/phase13-test.janet
Normal file
44
test/integration/ports/phase13-test.janet
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
(use ../../../src/jolt/api)
|
||||
(use ../../../src/jolt/evaluator)
|
||||
(use ../../../src/jolt/reader)
|
||||
(defn ct-eval [ctx s] (normalize-pvecs (eval-string ctx s)))
|
||||
|
||||
(defn load-clj [ctx filepath]
|
||||
(var s (slurp filepath))
|
||||
(while (> (length (string/trim s)) 0)
|
||||
(def [form rest] (parse-next s))
|
||||
(set s rest)
|
||||
(when (not (nil? form))
|
||||
(eval-form ctx @{} form))))
|
||||
|
||||
(print "=== Phase 13: Protocol Completion ===")
|
||||
|
||||
(print "28: reify dispatch...")
|
||||
(let [ctx (init)]
|
||||
(ct-eval ctx "(defprotocol Greeter (say-hello [this]))")
|
||||
(ct-eval ctx "(def r (reify Greeter (say-hello [this] \"hello reify\")))")
|
||||
(assert (= "hello reify" (ct-eval ctx "(say-hello r)")) "reify dispatch"))
|
||||
(print " ok")
|
||||
|
||||
(print "29: #() anon-fn reader...")
|
||||
(let [ctx (init)]
|
||||
(assert (= 2 (ct-eval ctx "(#(inc %) 1)")) "anon fn %")
|
||||
(assert (= 3 (ct-eval ctx "(#(+ %1 %2) 1 2)")) "anon fn %1 %2")
|
||||
(assert (= [1 2 3] (ct-eval ctx "(map #(inc %) [0 1 2])")) "anon fn map"))
|
||||
(print " ok")
|
||||
|
||||
(print "30: extend-type full dispatch...")
|
||||
(let [ctx (init)]
|
||||
(ct-eval ctx "(defprotocol Greet (g [this]))")
|
||||
(ct-eval ctx "(deftype Dog [name])")
|
||||
(ct-eval ctx "(extend-type Dog Greet (g [this] (str \"woof \" (.-name this))))")
|
||||
(assert (= "woof Rex" (ct-eval ctx "(g (Dog. \"Rex\"))")) "extend-type dog"))
|
||||
(print " ok")
|
||||
|
||||
(print "31: clojure.walk loading...")
|
||||
(let [ctx (init)]
|
||||
(load-clj ctx "src/jolt/clojure/walk.clj")
|
||||
(assert (function? (ct-eval ctx "keywordize-keys")) "keywordize-keys is fn"))
|
||||
(print " ok")
|
||||
|
||||
(print "\nAll Phase 13 tests passed!")
|
||||
74
test/integration/ports/phase5-test.janet
Normal file
74
test/integration/ports/phase5-test.janet
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
# Phase 5: Multimethods + Hierarchy Tests
|
||||
(use ../../../src/jolt/api)
|
||||
(defn ct-eval [ctx s] (normalize-pvecs (eval-string ctx s)))
|
||||
|
||||
# 22. Hierarchy
|
||||
(print "22: hierarchy...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(map? (make-hierarchy))")) "make-hierarchy returns map")
|
||||
# 2-arity derive/isa? just returns nil/false (no global hierarchy)
|
||||
(ct-eval ctx "(derive ::square ::shape)")
|
||||
(assert (= false (ct-eval ctx "(isa? ::square ::shape)")) "isa? 2-arity always false"))
|
||||
(print " passed")
|
||||
|
||||
# 23. Multimethods — basic dispatch
|
||||
(print "23: basic multimethod dispatch...")
|
||||
(let [ctx (init)]
|
||||
(ct-eval ctx "(defmulti greet (fn [x] (:lang x)))")
|
||||
(ct-eval ctx "(defmethod greet :en [_] \"hello\")")
|
||||
(ct-eval ctx "(defmethod greet :fr [_] \"bonjour\")")
|
||||
(assert (= "hello" (ct-eval ctx "(greet {:lang :en})")) "dispatch :en")
|
||||
(assert (= "bonjour" (ct-eval ctx "(greet {:lang :fr})")) "dispatch :fr")
|
||||
(assert (ct-eval ctx "(try (greet {:lang :es}) (catch Exception e true))") "missing dispatch errors"))
|
||||
(print " passed")
|
||||
|
||||
# 24. Multimethods — :default dispatch
|
||||
(print "24: :default dispatch...")
|
||||
(let [ctx (init)]
|
||||
(ct-eval ctx "(defmulti classify :type :default :unknown)")
|
||||
(ct-eval ctx "(defmethod classify :a [_] :alpha)")
|
||||
# :default :unknown renames the catch-all dispatch key; a method must be
|
||||
# registered under it (Clojure semantics).
|
||||
(ct-eval ctx "(defmethod classify :unknown [_] :unknown)")
|
||||
(assert (= :alpha (ct-eval ctx "(classify {:type :a})")) "known dispatch")
|
||||
(assert (= :unknown (ct-eval ctx "(classify {:type :z})")) "default fallback"))
|
||||
(print " passed")
|
||||
|
||||
# 25. Multimethods — hierarchy dispatch
|
||||
(print "25: hierarchy dispatch...")
|
||||
(let [ctx (init)]
|
||||
(ct-eval ctx "(def h (make-hierarchy))")
|
||||
(ct-eval ctx "(def h (derive h ::dog ::mammal))")
|
||||
(ct-eval ctx "(def h (derive h ::mammal ::animal))")
|
||||
(ct-eval ctx "(defmulti animal-sound (fn [x] x) :default :unknown :hierarchy h)")
|
||||
(ct-eval ctx "(defmethod animal-sound ::animal [_] \"rawr\")")
|
||||
(ct-eval ctx "(defmethod animal-sound ::dog [_] \"woof\")")
|
||||
# catch-all method registered under the renamed default key :unknown
|
||||
(ct-eval ctx "(defmethod animal-sound :unknown [_] :unknown)")
|
||||
(assert (= "woof" (ct-eval ctx "(animal-sound ::dog)")) "direct dispatch")
|
||||
(assert (= "rawr" (ct-eval ctx "(animal-sound ::mammal)")) "hierarchy fallback")
|
||||
(assert (= :unknown (ct-eval ctx "(animal-sound ::rock)")) "default fallback"))
|
||||
(print " passed")
|
||||
|
||||
# 26. remove-method
|
||||
(print "26: remove-method...")
|
||||
(let [ctx (init)]
|
||||
(ct-eval ctx "(defmulti rmtest :k)")
|
||||
(ct-eval ctx "(defmethod rmtest :a [_] 1)")
|
||||
(ct-eval ctx "(defmethod rmtest :b [_] 2)")
|
||||
(assert (= 1 (ct-eval ctx "(rmtest {:k :a})")) "before remove")
|
||||
(ct-eval ctx "(remove-method (var rmtest) :a)")
|
||||
(assert (ct-eval ctx "(try (rmtest {:k :a}) (catch Exception e true))") "removed method errors"))
|
||||
(print " passed")
|
||||
|
||||
# 27. remove-all-methods
|
||||
(print "27: remove-all-methods...")
|
||||
(let [ctx (init)]
|
||||
(ct-eval ctx "(defmulti alltest :k)")
|
||||
(ct-eval ctx "(defmethod alltest :a [_] 1)")
|
||||
(ct-eval ctx "(defmethod alltest :b [_] 2)")
|
||||
(ct-eval ctx "(remove-all-methods (var alltest))")
|
||||
(assert (ct-eval ctx "(try (alltest {:k :a}) (catch Exception e true))") "all methods removed errors"))
|
||||
(print " passed")
|
||||
|
||||
(print "\nAll Phase 5 tests passed!")
|
||||
82
test/integration/ports/phase6-final-test.janet
Normal file
82
test/integration/ports/phase6-final-test.janet
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
(use ../../../src/jolt/api)
|
||||
|
||||
(defn ct-eval [ctx s] (normalize-pvecs (eval-string ctx s)))
|
||||
|
||||
(print "Phase 6: comprehensive compile-mode tests...")
|
||||
(let [ctx (init {:compile? true})]
|
||||
|
||||
(print " collections...")
|
||||
(assert (= :a (ct-eval ctx "(nth [:a :b :c :d] 0)")) "nth")
|
||||
(assert (= true (ct-eval ctx "(vector? [1 2])")) "vector?")
|
||||
(assert (= true (ct-eval ctx "(map? {:a 1})")) "map?")
|
||||
(assert (= true (ct-eval ctx "(fn? inc)")) "fn?")
|
||||
(assert (= [1 2 3 4] (ct-eval ctx "(conj [1 2 3] 4)")) "conj")
|
||||
(assert (= 1 (ct-eval ctx "(first [1 2 3])")) "first")
|
||||
(assert (= [2 3] (ct-eval ctx "(rest [1 2 3])")) "rest")
|
||||
(assert (= 1 (ct-eval ctx "(get {:a 1 :b 2} :a)")) "get map")
|
||||
(assert (= nil (ct-eval ctx "(get {:a 1} :z)")) "get missing")
|
||||
(assert (= 3 (ct-eval ctx "(count {:a 1 :b 2 :c 3})")) "count map")
|
||||
(assert (= [1 2 3] (ct-eval ctx "(into [1] [2 3])")) "into")
|
||||
|
||||
(print " core math...")
|
||||
(assert (= 3 (ct-eval ctx "(+ 1 2)")) "+")
|
||||
(assert (= 1 (ct-eval ctx "(- 3 2)")) "-")
|
||||
(assert (= 6 (ct-eval ctx "(* 2 3)")) "*")
|
||||
(assert (= 2 (ct-eval ctx "(/ 4 2)")) "/")
|
||||
(assert (= 3 (ct-eval ctx "(inc 2)")) "inc")
|
||||
(assert (= 1 (ct-eval ctx "(dec 2)")) "dec")
|
||||
(assert (= 1 (ct-eval ctx "(quot 5 3)")) "quot")
|
||||
(assert (= 2 (ct-eval ctx "(rem 5 3)")) "rem")
|
||||
(assert (= 2 (ct-eval ctx "(mod 5 3)")) "mod")
|
||||
(assert (= 3 (ct-eval ctx "(max 1 2 3)")) "max")
|
||||
(assert (= 1 (ct-eval ctx "(min 1 2 3)")) "min")
|
||||
|
||||
(print " predicates...")
|
||||
(assert (= true (ct-eval ctx "(nil? nil)")) "nil?")
|
||||
(assert (= false (ct-eval ctx "(nil? 1)")) "nil? false")
|
||||
(assert (= true (ct-eval ctx "(zero? 0)")) "zero?")
|
||||
(assert (= true (ct-eval ctx "(pos? 5)")) "pos?")
|
||||
(assert (= true (ct-eval ctx "(neg? -1)")) "neg?")
|
||||
(assert (= true (ct-eval ctx "(even? 4)")) "even?")
|
||||
(assert (= true (ct-eval ctx "(odd? 3)")) "odd?")
|
||||
(assert (= false (ct-eval ctx "(not true)")) "not")
|
||||
(assert (= true (ct-eval ctx "(some? 1)")) "some?")
|
||||
(assert (= true (ct-eval ctx "(string? \"hello\")")) "string?")
|
||||
(assert (= true (ct-eval ctx "(number? 42)")) "number?")
|
||||
(assert (= true (ct-eval ctx "(keyword? :foo)")) "keyword?")
|
||||
(assert (= true (ct-eval ctx "(= 1 1)")) "=")
|
||||
(assert (= true (ct-eval ctx "(< 1 2)")) "<")
|
||||
(assert (= true (ct-eval ctx "(> 2 1)")) ">")
|
||||
(assert (= true (ct-eval ctx "(<= 1 1)")) "<=")
|
||||
(assert (= true (ct-eval ctx "(>= 2 2)")) ">=")
|
||||
|
||||
(print " seq operations...")
|
||||
(assert (= [2 3 4] (ct-eval ctx "(map inc [1 2 3])")) "map")
|
||||
(assert (= [2 4] (ct-eval ctx "(filter even? [1 2 3 4])")) "filter")
|
||||
(assert (= [1 3] (ct-eval ctx "(remove even? [1 2 3 4])")) "remove")
|
||||
(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")
|
||||
|
||||
(print " special forms...")
|
||||
(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 (= 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")
|
||||
(assert (= 42 (ct-eval ctx "'42")) "quote literal")
|
||||
|
||||
(print " macros...")
|
||||
(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 true")
|
||||
(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 macro")
|
||||
(assert (= 2 (ct-eval ctx "(if-let [x 1] (inc x) 0)")) "if-let")
|
||||
|
||||
(print " complex...")
|
||||
(assert (= 6 (ct-eval ctx "(let [f (fn [n] (loop [i 0 acc 0] (if (< i n) (recur (inc i) (+ acc i)) acc)))] (f 4))")) "nested")
|
||||
(assert (= 15 (ct-eval ctx "(reduce + (map inc [0 1 2 3 4]))")) "reduce+map"))
|
||||
|
||||
(print "\nAll Phase 6 tests passed!")
|
||||
36
test/integration/ports/phase6-test.janet
Normal file
36
test/integration/ports/phase6-test.janet
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
# Phase 6: Reader Extensions Tests
|
||||
(use ../../../src/jolt/api)
|
||||
(defn ct-eval [ctx s] (normalize-pvecs (eval-string ctx s)))
|
||||
|
||||
(print "28: #inst tagged literal...")
|
||||
(let [ctx (init)]
|
||||
(let [val (ct-eval ctx "#inst \"2024-01-15\"")]
|
||||
(assert (= "2024-01-15" val) "#inst string"))
|
||||
(let [val (ct-eval ctx "#inst \"2024-01-15T10:30:00Z\"")]
|
||||
(assert (= "2024-01-15T10:30:00Z" val) "#inst timestamp")))
|
||||
(print " passed")
|
||||
|
||||
(print "29: #uuid tagged literal...")
|
||||
(let [ctx (init)]
|
||||
(let [val (ct-eval ctx "#uuid \"550e8400-e29b-41d4-a716-446655440000\"")]
|
||||
(assert (= "550e8400-e29b-41d4-a716-446655440000" val) "#uuid string")))
|
||||
(print " passed")
|
||||
|
||||
(print "30: #? reader conditionals...")
|
||||
(let [ctx (init)]
|
||||
(assert (= :yes (ct-eval ctx "#?(:clj :yes :cljs :no)")) "#? selects :clj")
|
||||
(assert (= :yes (ct-eval ctx "#?(:cljs :no :default :yes)")) "#? :default fallback")
|
||||
(assert (= nil (ct-eval ctx "#?(:cljs :no)")) "#? nil on no match"))
|
||||
(print " passed")
|
||||
|
||||
(print "31: #?@ splicing...")
|
||||
(let [ctx (init)]
|
||||
(assert (= [1 2 3] (ct-eval ctx "[#?@(:clj [1 2 3] :cljs [4 5 6])]"))
|
||||
"#?@ splices :clj")
|
||||
(assert (= [99] (ct-eval ctx "[#?@(:cljs [1] :default [99])]"))
|
||||
"#?@ :default fallback")
|
||||
(assert (= [] (ct-eval ctx "[#?@(:cljs [1 2])]"))
|
||||
"#?@ nothing on no match"))
|
||||
(print " passed")
|
||||
|
||||
(print "\nAll Phase 6 tests passed!")
|
||||
25
test/integration/ports/phase7-test.janet
Normal file
25
test/integration/ports/phase7-test.janet
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# Phase 7: LazySeq + PersistentHashSet completion
|
||||
(use ../../../src/jolt/api)
|
||||
(defn ct-eval [ctx s] (normalize-pvecs (eval-string ctx s)))
|
||||
|
||||
(print "32: lazy-seq...")
|
||||
(let [ctx (init)]
|
||||
(let [ls (ct-eval ctx "(lazy-seq (cons 1 (lazy-seq (cons 2 nil))))")]
|
||||
(assert (not (nil? ls)) "lazy-seq returns non-nil")
|
||||
(assert (= 1 (ct-eval ctx "(first (lazy-seq (cons 1 nil)))")) "first of lazy"))
|
||||
(assert (= true (ct-eval ctx "(= [1 2 3] (seq (lazy-seq [1 2 3])))")) "seq forces lazy")
|
||||
(eval-string ctx "(def counter (atom 0))")
|
||||
(def val (ct-eval ctx "(let [ls (lazy-seq (do (swap! counter inc) [1 2 3]))] (seq ls) (seq ls) @counter)"))
|
||||
(assert (= 1 val) "realized once"))
|
||||
(print " passed")
|
||||
|
||||
(print "33: PersistentHashSet...")
|
||||
(let [ctx (init)]
|
||||
(assert (= true (ct-eval ctx "(set? #{1 2 3})")) "set? true")
|
||||
(assert (= false (ct-eval ctx "(set? [1 2 3])")) "set? false")
|
||||
(assert (= 4 (ct-eval ctx "(count (conj #{1 2 3} 4))")) "conj add")
|
||||
(assert (= 2 (ct-eval ctx "(count (disj #{1 2 3} 3))")) "disj")
|
||||
(assert (= 3 (ct-eval ctx "(count #{1 2 3})")) "count")
|
||||
(assert (= true (ct-eval ctx "(= #{1 2 3} #{3 2 1})")) "= order-independent"))
|
||||
|
||||
(print "\nAll Phase 7 tests passed!")
|
||||
44
test/integration/ports/phase8-test.janet
Normal file
44
test/integration/ports/phase8-test.janet
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
# Phase 8: Protocol System Tests
|
||||
(use ../../../src/jolt/api)
|
||||
(defn ct-eval [ctx s] (normalize-pvecs (eval-string ctx s)))
|
||||
|
||||
(print "35: defprotocol...")
|
||||
(let [ctx (init)]
|
||||
(ct-eval ctx "(defprotocol Greet (greet [this]))")
|
||||
(let [p (ct-eval ctx "Greet")]
|
||||
(assert (not (nil? p)) "protocol var exists")
|
||||
(assert (= :jolt/protocol (get p :jolt/type)) "protocol type tag")
|
||||
(assert (get (get p :methods) :greet) "protocol has greet method"))
|
||||
(assert (or (function? (ct-eval ctx "greet")) (cfunction? (ct-eval ctx "greet"))) "method fn exists"))
|
||||
(print " passed")
|
||||
|
||||
(print "36: extend-type...")
|
||||
(let [ctx (init)]
|
||||
(ct-eval ctx "(deftype Person [name])")
|
||||
(ct-eval ctx "(defprotocol Namable (get-name [this]))")
|
||||
(ct-eval ctx "(extend-type Person Namable (get-name [this] (.-name this)))")
|
||||
(assert (= "Alice" (ct-eval ctx "(get-name (Person. \"Alice\"))")) "extend-type works"))
|
||||
(print " passed")
|
||||
|
||||
(print "37: extend-protocol...")
|
||||
(let [ctx (init)]
|
||||
(ct-eval ctx "(deftype Dog [breed])")
|
||||
(ct-eval ctx "(deftype Cat [color])")
|
||||
(ct-eval ctx "(defprotocol Animal (speak [this]))")
|
||||
(ct-eval ctx "(extend-protocol Animal
|
||||
Dog (speak [this] (str \"woof from \" (.-breed this)))
|
||||
Cat (speak [this] (str \"meow from \" (.-color this))))")
|
||||
(assert (= "woof from poodle" (ct-eval ctx "(speak (Dog. \"poodle\"))")) "dog speak")
|
||||
(assert (= "meow from black" (ct-eval ctx "(speak (Cat. \"black\"))")) "cat speak"))
|
||||
(print " passed")
|
||||
|
||||
(print "38: satisfies?...")
|
||||
(let [ctx (init)]
|
||||
(ct-eval ctx "(deftype Point [x y])")
|
||||
(ct-eval ctx "(defprotocol Locatable (location [this]))")
|
||||
(ct-eval ctx "(extend-type Point Locatable (location [this] [(.-x this) (.-y this)]))")
|
||||
(assert (= true (ct-eval ctx "(satisfies? Locatable (Point. 3 4))")) "satisfies? true")
|
||||
(assert (= false (ct-eval ctx "(satisfies? Locatable {:x 1})")) "satisfies? false"))
|
||||
(print " passed")
|
||||
|
||||
(print "\nAll Phase 8 tests passed!")
|
||||
Loading…
Add table
Add a link
Reference in a new issue