test: fold phase ports into spec; promote compile-mode test
Mine the phase* port batteries into the spec layer and delete them (their
behavior is now covered by spec): phase5 (hierarchies), phase6 (tagged
literals/reader-conditionals), phase7 (lazy/sets), phase8+phase12 (protocols;
phase12 was a duplicate of phase8), phase10 (strings/set), phase13
(reify/walk). Unique cases mined into spec: reader #inst/#uuid/#?@ splice,
(Type. args) dot constructor, lazy-seq body-runs-once, keywordize-keys/
stringify-keys, custom :default key and explicit :hierarchy dispatch.
phase6-final tested the COMPILE-MODE path ({:compile? true}), distinct from the
interpreter-based spec — kept and renamed integration/compile-mode-test.
jpm test green, conformance 218/218.
This commit is contained in:
parent
3f5b42d784
commit
bcd0e42b33
13 changed files with 19 additions and 338 deletions
82
test/integration/compile-mode-test.janet
Normal file
82
test/integration/compile-mode-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!")
|
||||
Loading…
Add table
Add a link
Reference in a new issue