feat(strictness): subs validates bounds; assoc! bounds-checks vector index
- subs requires a string and validates 0<=start<=end<=count (no Janet from-end/clamping); negative/out-of-range/nil indices throw - assoc! on a transient vector bounds-checks the index (0..count) subs 11-fail -> 24/5 (5 remaining are byte-vs-codepoint Unicode, platform); assoc_bang 32/6 -> 35/3. clojure-test-suite pass 3889->3898. spec: string/subs-strictness (7), transient/assoc!-bounds (4). jpm test green.
This commit is contained in:
parent
6544d8ef44
commit
740b50aef3
4 changed files with 35 additions and 6 deletions
|
|
@ -33,3 +33,13 @@
|
|||
["replace" "\"hexxo\"" "(do (require (quote [clojure.string :as s])) (s/replace \"hello\" \"l\" \"x\"))"]
|
||||
["reverse" "\"cba\"" "(do (require (quote [clojure.string :as s])) (s/reverse \"abc\"))"]
|
||||
["index-of" "2" "(do (require (quote [clojure.string :as s])) (s/index-of \"hello\" \"l\"))"])
|
||||
|
||||
# subs validates bounds like Clojure (no Janet from-end/clamping).
|
||||
(defspec "string / subs strictness"
|
||||
["subs basic" "\"bcd\"" "(subs \"abcde\" 1 4)"]
|
||||
["subs to end" "\"cde\"" "(subs \"abcde\" 2)"]
|
||||
["subs start>end" :throws "(subs \"abcde\" 2 1)"]
|
||||
["subs negative" :throws "(subs \"abcde\" -1)"]
|
||||
["subs end past len" :throws "(subs \"abcde\" 1 6)"]
|
||||
["subs nil start" :throws "(subs \"abcde\" nil 2)"]
|
||||
["subs on nil" :throws "(subs nil 1 2)"])
|
||||
|
|
|
|||
|
|
@ -90,3 +90,9 @@
|
|||
["conj! no args" "[]" "(persistent! (conj!))"]
|
||||
["conj! identity" "[1 2]" "(conj! [1 2])"]
|
||||
["conj! map merges map" "{:a 1, :b 2}" "(persistent! (conj! (transient {:a 1}) {:b 2}))"])
|
||||
|
||||
(defspec "transient / assoc! bounds"
|
||||
["assoc! existing idx" "[1 9 3]" "(persistent! (assoc! (transient [1 2 3]) 1 9))"]
|
||||
["assoc! at count grows" "[1 2 3]" "(persistent! (assoc! (transient [1 2]) 2 3))"]
|
||||
["assoc! out of bounds" :throws "(assoc! (transient [0 1 2]) 4 4)"]
|
||||
["assoc! negative" :throws "(assoc! (transient []) -1 0)"])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue