jolt/test/integration/ports/cljs-port-4-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

48 lines
1.9 KiB
Text

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