stdlib: port clojure.data, rewrite clojure.zip; fix with-meta nil; add battery
clojure.data: ported from the ClojureScript impl (jolt-native equality-partition fn instead of host-type protocol dispatch). Verified against Clojure's own data-test (12/13 canonical; the 13th needs nil-valued-map support, jolt-c7h). Used mapv over the reference's (doall (map …)) — jolt's lazy multi-coll map + doall don't force as a reduce accumulator (jolt-dzh). clojure.zip: jolt's was a broken custom reimplementation; replaced with a port of real clojure.zip (metadata-based locs). Uses (nth loc …) instead of (loc …) because meta-bearing vectors aren't invocable as fns (jolt-vh5). core: with-meta now accepts nil metadata (Clojure allows (with-meta x nil)); it crashed calling keys on nil. This is what unblocked zip's make-node. New vendored battery (test/clojure-stdlib/, from clojurust's suite with fixtures corrected to match real Clojure): walk 34, zip 33, data 61 all clean; edn guarded at 43 (still a stub — jolt-b7y). Conformance 218/218 all modes; full suite green.
This commit is contained in:
parent
c975f5d1c3
commit
e623968b45
8 changed files with 812 additions and 95 deletions
101
test/clojure-stdlib/clojure/walk_test/walk.cljc
Normal file
101
test/clojure-stdlib/clojure/walk_test/walk.cljc
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
(ns clojure.walk-test.walk
|
||||
(:require [clojure.test :refer [deftest is testing]]
|
||||
[clojure.walk :as w]))
|
||||
|
||||
(deftest test-walk
|
||||
(testing "walk with identity"
|
||||
(is (= [1 2 3] (w/walk identity identity [1 2 3])))
|
||||
(is (= '(1 2 3) (w/walk identity identity '(1 2 3))))
|
||||
(is (= #{1 2 3} (w/walk identity identity #{1 2 3}))))
|
||||
|
||||
(testing "walk with inner transform"
|
||||
(is (= [2 3 4] (w/walk inc identity [1 2 3])))
|
||||
(is (= [2 3 4] (w/walk inc vec [1 2 3]))))
|
||||
|
||||
(testing "walk with outer transform"
|
||||
(is (= [1 2 3] (w/walk identity vec '(1 2 3))))))
|
||||
|
||||
(deftest test-postwalk
|
||||
(testing "postwalk with numbers"
|
||||
(is (= [2 3 4] (w/postwalk #(if (number? %) (inc %) %) [1 2 3]))))
|
||||
|
||||
(testing "postwalk with nested structures"
|
||||
(is (= [2 [3 4] 5]
|
||||
(w/postwalk #(if (number? %) (inc %) %) [1 [2 3] 4]))))
|
||||
|
||||
(testing "postwalk preserves types"
|
||||
(is (vector? (w/postwalk identity [1 2 3])))
|
||||
(is (list? (w/postwalk identity '(1 2 3))))
|
||||
(is (set? (w/postwalk identity #{1 2 3})))
|
||||
(is (map? (w/postwalk identity {:a 1 :b 2}))))
|
||||
|
||||
(testing "postwalk on maps"
|
||||
(is (= {:a 2 :b 3}
|
||||
(w/postwalk #(if (number? %) (inc %) %) {:a 1 :b 2}))))
|
||||
|
||||
(testing "postwalk on empty collections"
|
||||
(is (= [] (w/postwalk identity [])))
|
||||
(is (= {} (w/postwalk identity {})))
|
||||
(is (= #{} (w/postwalk identity #{})))
|
||||
(is (= '() (w/postwalk identity '())))))
|
||||
|
||||
(deftest test-prewalk
|
||||
(testing "prewalk with numbers"
|
||||
(is (= [2 3 4] (w/prewalk #(if (number? %) (inc %) %) [1 2 3]))))
|
||||
|
||||
(testing "prewalk with nested structures"
|
||||
(is (= [2 [3 4] 5]
|
||||
(w/prewalk #(if (number? %) (inc %) %) [1 [2 3] 4]))))
|
||||
|
||||
(testing "prewalk transforms before descending"
|
||||
;; prewalk applies f to the outer form first, so we can replace
|
||||
;; entire subtrees before they are walked
|
||||
(is (= [:replaced]
|
||||
(w/prewalk #(if (= % [1 2 3]) [:replaced] %) [1 2 3])))))
|
||||
|
||||
(deftest test-keywordize-keys
|
||||
(testing "basic keywordize"
|
||||
(is (= {:a 1 :b 2} (w/keywordize-keys {"a" 1 "b" 2}))))
|
||||
|
||||
(testing "nested keywordize"
|
||||
(is (= {:a {:b 2}} (w/keywordize-keys {"a" {"b" 2}}))))
|
||||
|
||||
(testing "non-string keys unchanged"
|
||||
(is (= {:a 1 42 2} (w/keywordize-keys {"a" 1 42 2}))))
|
||||
|
||||
(testing "already keyword keys unchanged"
|
||||
(is (= {:a 1} (w/keywordize-keys {:a 1})))))
|
||||
|
||||
(deftest test-stringify-keys
|
||||
(testing "basic stringify"
|
||||
(is (= {"a" 1 "b" 2} (w/stringify-keys {:a 1 :b 2}))))
|
||||
|
||||
(testing "nested stringify"
|
||||
(is (= {"a" {"b" 2}} (w/stringify-keys {:a {:b 2}}))))
|
||||
|
||||
(testing "non-keyword keys unchanged"
|
||||
(is (= {"a" 1 42 2} (w/stringify-keys {:a 1 42 2})))))
|
||||
|
||||
(deftest test-postwalk-replace
|
||||
(testing "basic replacement"
|
||||
(is (= [:x :y :c] (w/postwalk-replace {:a :x :b :y} [:a :b :c]))))
|
||||
|
||||
(testing "nested replacement"
|
||||
(is (= [:x [:y :c]] (w/postwalk-replace {:a :x :b :y} [:a [:b :c]]))))
|
||||
|
||||
(testing "no matches"
|
||||
(is (= [1 2 3] (w/postwalk-replace {:a :x} [1 2 3]))))
|
||||
|
||||
(testing "empty smap"
|
||||
(is (= [1 2 3] (w/postwalk-replace {} [1 2 3])))))
|
||||
|
||||
(deftest test-prewalk-replace
|
||||
(testing "basic replacement"
|
||||
(is (= [:x :y :c] (w/prewalk-replace {:a :x :b :y} [:a :b :c]))))
|
||||
|
||||
(testing "nested replacement"
|
||||
(is (= [:x [:y :c]] (w/prewalk-replace {:a :x :b :y} [:a [:b :c]]))))
|
||||
|
||||
(testing "replaces before descending"
|
||||
;; prewalk-replace replaces the whole form first, then walks children
|
||||
(is (= :replaced (w/prewalk-replace {[:a :b] :replaced} [:a :b])))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue