test(spec): numbers, strings, predicates — fix variadic <, seq?, index-of
Add spec suites for numbers/arithmetic, strings (str + clojure.string), and type/value predicates. Bugs they caught and fixed: - <, >, <=, >= were binary-only; now variadic ((< 1 2 3) chains) - seq? was true for vectors; vectors are not ISeq in Clojure, so (seq? [1]) is now false (true only for lists/lazy-seqs) - clojure.string/index-of and last-index-of were 1-based (stray inc); now 0-based per Clojure Corrected a systematic-coverage assertion that encoded the old seq? bug. jpm test green, conformance 218/218.
This commit is contained in:
parent
b353d625f1
commit
68d6b1d6c1
6 changed files with 178 additions and 12 deletions
|
|
@ -108,24 +108,23 @@
|
|||
s)))
|
||||
|
||||
(defn index-of
|
||||
|
||||
"0-based index of the first occurrence of value in s, or nil."
|
||||
([s value]
|
||||
(let [idx (str-find value s)]
|
||||
(when idx (inc idx))))
|
||||
(str-find value s))
|
||||
([s value from]
|
||||
(let [idx (str-find value (subs s from))]
|
||||
(when idx (+ from (inc idx))))))
|
||||
(when idx (+ from idx)))))
|
||||
|
||||
(defn last-index-of
|
||||
|
||||
([s value]
|
||||
(let [r (str-reverse-b s) sval (str-reverse-b value)
|
||||
idx (str-find sval r)]
|
||||
(when idx (inc (- (count s) (+ idx (count value)))))))
|
||||
(when idx (- (count s) (+ idx (count value))))))
|
||||
([s value from]
|
||||
(let [sub (subs s 0 from) r (str-reverse-b sub) sval (str-reverse-b value)
|
||||
idx (str-find sval r)]
|
||||
(when idx (inc (- from (+ idx (count value))))))))
|
||||
(when idx (- from (+ idx (count value)))))))
|
||||
|
||||
(defn re-quote-replacement
|
||||
"Escape special characters (backslash and dollar) in a regex replacement
|
||||
|
|
|
|||
|
|
@ -87,7 +87,9 @@
|
|||
(defn core-symbol? [x] (and (struct? x) (= :symbol (x :jolt/type))))
|
||||
(defn core-vector? [x] (jvec? x))
|
||||
(defn core-map? [x] (or (phm? x) (struct? x) (if (and (table? x) (get x :jolt/deftype)) true false)))
|
||||
(defn core-seq? [x] (or (array? x) (tuple? x) (pvec? x) (plist? x) (lazy-seq? x)))
|
||||
# seq? is true only for actual sequences (lists, lazy-seqs) — NOT vectors, which
|
||||
# are not ISeq in Clojure. (A Janet array represents a Clojure list/seq result.)
|
||||
(defn core-seq? [x] (or (array? x) (plist? x) (lazy-seq? x)))
|
||||
(defn core-coll? [x] (or (array? x) (tuple? x) (pvec? x) (plist? x) (struct? x) (phm? x) (set? x) (lazy-seq? x)))
|
||||
|
||||
(defn core-true? [x] (= true x))
|
||||
|
|
@ -239,10 +241,17 @@
|
|||
|
||||
(defn core-not= [& args] (not (apply core-= args)))
|
||||
|
||||
(defn core-< [a b] (< a b))
|
||||
(defn core-> [a b] (> a b))
|
||||
(defn core-<= [a b] (<= a b))
|
||||
(defn core->= [a b] (>= a b))
|
||||
# Comparisons are variadic: (< a b c) means a < b < c.
|
||||
(defn- chain-cmp [op xs]
|
||||
(var ok true) (var i 0)
|
||||
(while (and ok (< i (dec (length xs))))
|
||||
(unless (op (in xs i) (in xs (+ i 1))) (set ok false))
|
||||
(++ i))
|
||||
ok)
|
||||
(defn core-< [& xs] (chain-cmp < xs))
|
||||
(defn core-> [& xs] (chain-cmp > xs))
|
||||
(defn core-<= [& xs] (chain-cmp <= xs))
|
||||
(defn core->= [& xs] (chain-cmp >= xs))
|
||||
|
||||
# ============================================================
|
||||
# Collections
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue