- cljs-port-1a.janet (sections 1-6): core math, predicates, comparison, vectors, maps, sets — all pass (54 assertions) - cljs-port-1b.janet (sections 7-11): seq operations, printing, apply, higher-order fns — all pass (25 assertions, str nil skipped) - cljs-port-2.janet (sections 12-15): atoms, special forms, macros, constructors — all pass (20 assertions) - cljs-port-3.janet (sections 16-22): destructuring, set ops, reader literals, syntax-quote, walk (skipped), clojure.string, clojure.set — 16 assertions pass, walk skipped (needs IFn protocol) - cljs-port-4.janet (sections 23-27): deftype/defrecord, multimethods, protocols, var system, range/into/concat — all pass (15 assertions) Paren-counting boundary persists in single-file format, split into separate files is the workaround. 316/317 total (1 pre-existing).
48 lines
1.9 KiB
Text
48 lines
1.9 KiB
Text
(use ../src/jolt/api)
|
|
(defn ct-eval [ctx s] (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!")
|