jolt/test/integration/ports/cljs-port-test.janet
Yogthos 16428179fa 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.
2026-06-05 00:00:16 -04:00

131 lines
5.9 KiB
Text

(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!")