test: regression coverage for the core migration + the two bug fixes
Spec suites (interpret) for the overlay-migrated fns and both fixes: - control-flow: if-let/when-let/if-some/when-some else-scope (9 cases) - predicates: not-any?/idents/numeric preds/NaN?/abs/object?/... (24 cases) - sequences: nthrest()/nthnext/distinct? value-eq/replace nil/take-last/... (23) Plus 10 cases added to the all-3-modes conformance set for the highest-risk fixes (if-let scope, nthrest (), distinct? value-eq), so compile + self-host are guarded too: conformance 218 -> 228 in all three modes. Full suite green.
This commit is contained in:
parent
f22eb660d3
commit
e646af123a
4 changed files with 89 additions and 0 deletions
|
|
@ -299,6 +299,21 @@
|
|||
["map literal nested" "{:a {:b 2}}" "(let [y 2] {:a {:b y}})"]
|
||||
["map literal keyfn" "{:x 1}" "(let [k :x] {k 1})"]
|
||||
["map literal in fn" "6" "(do (defn mk [a b] {:sum (+ a b)}) (:sum (mk 2 4)))"]
|
||||
|
||||
### ---- overlay migration (jolt-1j0): run in all 3 modes ----
|
||||
# if-let/when-let bind only in the taken branch (else sees outer scope)
|
||||
["if-let else outer scope" "5" "(let [x 5] (if-let [x nil] :then x))"]
|
||||
["if-some else outer" "5" "(let [x 5] (if-some [x nil] :then x))"]
|
||||
["when-let body multi" "14" "(when-let [x 7] (inc x) (* x 2))"]
|
||||
# nthrest returns () (not nil) for an exhausted n>0 walk; coll for n<=0
|
||||
["nthrest exhausted" "(quote ())" "(nthrest nil 100)"]
|
||||
["nthrest n=0 keeps coll" "[1 2 3]" "(nthrest [1 2 3] 0)"]
|
||||
["nthnext surprising nil" "nil" "(nthnext nil nil)"]
|
||||
# distinct? compares by value
|
||||
["distinct? equal colls" "false" "(distinct? [1 2] [1 2])"]
|
||||
["not-any?" "true" "(not-any? even? [1 3 5])"]
|
||||
["take-last" "[3 4]" "(take-last 2 [1 2 3 4])"]
|
||||
["replace nil val" "[1 nil 3]" "(replace {2 nil} [1 2 3])"]
|
||||
])
|
||||
|
||||
# Run every case under a given context factory and return the failures. The same
|
||||
|
|
|
|||
|
|
@ -44,6 +44,22 @@
|
|||
["if-some zero" "1" "(if-some [x 0] (inc x) :none)"]
|
||||
["when-some nil" "nil" "(when-some [x nil] x)"])
|
||||
|
||||
# Regression: if-let/when-let/if-some/when-some bind the name ONLY in the
|
||||
# then/body branch. The else branch (and a falsy when-let body, which there is
|
||||
# none of) must see the surrounding scope, not the binding — so the else of
|
||||
# (let [x 5] (if-let [x nil] ...)) sees x=5, like Clojure. (Previously the macros
|
||||
# wrapped the whole `if` in the binding's let*, leaking it into the else.)
|
||||
(defspec "control / conditional-binding scope"
|
||||
["if-let else sees outer" "5" "(let [x 5] (if-let [x nil] :then x))"]
|
||||
["if-let then binds" "7" "(let [x 5] (if-let [x 7] x :else))"]
|
||||
["if-some else sees outer" "5" "(let [x 5] (if-some [x nil] :then x))"]
|
||||
["if-some binds false" "false" "(if-some [x false] x :else)"]
|
||||
["when-let else via or" "5" "(let [x 5] (or (when-let [x nil] x) x))"]
|
||||
["when-let multi-form body" "14" "(when-let [x 7] (inc x) (* x 2))"]
|
||||
["if-let in fn param" "9" "((fn [xs] (if-let [xs nil] :then xs)) 9)"]
|
||||
["when-some binds zero" "1" "(when-some [x 0] (inc x))"]
|
||||
["if-let evals test once" "1" "(let [c (atom 0)] (if-let [v (do (swap! c inc) :v)] @c :none))"])
|
||||
|
||||
(defspec "control / iteration"
|
||||
["dotimes side-effect" "5" "(let [a (atom 0)] (dotimes [i 5] (swap! a inc)) @a)"]
|
||||
["while" "5" "(let [a (atom 0)] (while (< @a 5) (swap! a inc)) @a)"]
|
||||
|
|
|
|||
|
|
@ -59,6 +59,35 @@
|
|||
["symbol constructor" "(quote x)" "(symbol \"x\")"]
|
||||
["name of string" "\"s\"" "(name \"s\")"])
|
||||
|
||||
# Predicates moved from Janet to the Clojure overlay (jolt-1j0). Jolt has no
|
||||
# ratio/bigdecimal types (so ratio?/decimal? are always false, rational?=int?),
|
||||
# and no distinct host object/undefined types (object?/undefined? always false).
|
||||
(defspec "predicates / overlay-migrated"
|
||||
["not-any? true" "true" "(not-any? even? [1 3 5])"]
|
||||
["not-any? false" "false" "(not-any? even? [1 2 3])"]
|
||||
["not-every? true" "true" "(not-every? even? [2 4 5])"]
|
||||
["not-every? false" "false" "(not-every? even? [2 4 6])"]
|
||||
["ident? number" "false" "(ident? 1)"]
|
||||
["qualified-ident?" "true" "(qualified-ident? :a/b)"]
|
||||
["qualified-ident? no" "false" "(qualified-ident? :a)"]
|
||||
["simple-ident?" "true" "(simple-ident? :a)"]
|
||||
["ratio?" "false" "(ratio? 3)"]
|
||||
["decimal?" "false" "(decimal? 3)"]
|
||||
["rational? int" "true" "(rational? 3)"]
|
||||
["rational? float" "false" "(rational? 3.5)"]
|
||||
["nat-int? zero" "true" "(nat-int? 0)"]
|
||||
["nat-int? neg" "false" "(nat-int? -1)"]
|
||||
["pos-int?" "true" "(pos-int? 5)"]
|
||||
["neg-int?" "true" "(neg-int? -3)"]
|
||||
["NaN? on nan" "true" "(NaN? (/ 0.0 0.0))"]
|
||||
["NaN? on number" "false" "(NaN? 5)"]
|
||||
["abs negative" "3" "(abs -3)"]
|
||||
["abs positive" "2.5" "(abs 2.5)"]
|
||||
["object?" "false" "(object? 1)"]
|
||||
["undefined?" "false" "(undefined? 1)"]
|
||||
["keyword-identical?" "true" "(keyword-identical? :a :a)"]
|
||||
["keyword-identical? no" "false" "(keyword-identical? :a :b)"])
|
||||
|
||||
(defspec "predicates / equality & identity"
|
||||
["= same" "true" "(= 1 1)"]
|
||||
["= vectors" "true" "(= [1 2] [1 2])"]
|
||||
|
|
|
|||
|
|
@ -199,3 +199,32 @@
|
|||
["nthnext nil count" :throws "(nthnext [0 1 2] nil)"]
|
||||
["update vec oob" :throws "(update [] 1 identity)"]
|
||||
["update vec kw key" :throws "(update [1 2 3] :k identity)"])
|
||||
|
||||
# Regression cases for clojure.core fns moved from Janet to the Clojure overlay
|
||||
# (jolt-1j0), plus two bugs fixed in the process: nthrest returns () (not nil)
|
||||
# for an exhausted n>0 walk, and distinct? compares by VALUE (equal collections
|
||||
# are not distinct).
|
||||
(defspec "seq / overlay-migrated fns"
|
||||
["nthrest exhausted -> ()" "()" "(nthrest nil 100)"]
|
||||
["nthrest vec exhausted" "()" "(nthrest [1 2 3] 100)"]
|
||||
["nthrest n<=0 keeps coll" "[1 2 3]" "(nthrest [1 2 3] 0)"]
|
||||
["nthrest drops n" "[3 4 5]" "(nthrest [1 2 3 4 5] 2)"]
|
||||
["nthnext exhausted -> nil" "nil" "(nthnext [1 2] 5)"]
|
||||
["nthnext surprising nil" "nil" "(nthnext nil nil)"]
|
||||
["nthnext drops n" "[3 4]" "(nthnext [1 2 3 4] 2)"]
|
||||
["distinct? distinct" "true" "(distinct? 1 2 3)"]
|
||||
["distinct? dup" "false" "(distinct? 1 2 1)"]
|
||||
["distinct? equal colls" "false" "(distinct? [1 2] [1 2])"]
|
||||
["distinct? single" "true" "(distinct? 5)"]
|
||||
["replace maps elements" "[:a 2 :c 2]" "(replace {1 :a 3 :c} [1 2 3 2])"]
|
||||
["replace preserves nil val" "[1 nil 3]" "(replace {2 nil} [1 2 3])"]
|
||||
["take-last" "[3 4]" "(take-last 2 [1 2 3 4])"]
|
||||
["take-last empty -> nil" "nil" "(take-last 2 [])"]
|
||||
["take-last n>len" "[1 2]" "(take-last 9 [1 2])"]
|
||||
["drop-last default 1" "[1 2]" "(drop-last [1 2 3])"]
|
||||
["drop-last n" "[1 2]" "(drop-last 2 [1 2 3 4])"]
|
||||
["split-with" "[[2 4] [5 6]]" "(split-with even? [2 4 5 6])"]
|
||||
["replicate" "[:x :x :x]" "(replicate 3 :x)"]
|
||||
["bounded-count" "3" "(bounded-count 3 [1 2 3 4 5])"]
|
||||
["run! side effects" "6" "(let [a (atom 0)] (run! (fn [x] (swap! a + x)) [1 2 3]) @a)"]
|
||||
["completing wraps rf" "3" "((completing +) 1 2)"])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue