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.
61 lines
2.8 KiB
Text
61 lines
2.8 KiB
Text
# Specification: type & value predicates.
|
|
(use ../support/harness)
|
|
|
|
(defspec "predicates / nil & boolean"
|
|
["nil? true" "true" "(nil? nil)"]
|
|
["nil? false" "false" "(nil? 0)"]
|
|
["some? true" "true" "(some? 0)"]
|
|
["some? on nil" "false" "(some? nil)"]
|
|
["true?" "true" "(true? true)"]
|
|
["false?" "true" "(false? false)"]
|
|
["boolean? true" "true" "(boolean? false)"]
|
|
["not nil" "true" "(not nil)"]
|
|
["not 0 is false" "false" "(not 0)"]
|
|
["boolean of nil" "false" "(boolean nil)"]
|
|
["boolean of value" "true" "(boolean 5)"])
|
|
|
|
(defspec "predicates / types"
|
|
["string?" "true" "(string? \"x\")"]
|
|
["number?" "true" "(number? 1)"]
|
|
["keyword?" "true" "(keyword? :a)"]
|
|
["symbol?" "true" "(symbol? (quote a))"]
|
|
["char?" "true" "(char? \\a)"]
|
|
["fn? on fn" "true" "(fn? inc)"]
|
|
["ifn? on keyword" "true" "(ifn? :a)"]
|
|
["vector?" "true" "(vector? [1])"]
|
|
["list?" "true" "(list? (list 1))"]
|
|
["map?" "true" "(map? {:a 1})"]
|
|
["set?" "true" "(set? #{1})"]
|
|
["coll? vector" "true" "(coll? [1])"]
|
|
["coll? map" "true" "(coll? {:a 1})"]
|
|
["coll? on number" "false" "(coll? 1)"]
|
|
["seq? list" "true" "(seq? (list 1))"]
|
|
["seq? vector" "false" "(seq? [1])"]
|
|
["sequential? vector" "true" "(sequential? [1])"]
|
|
["associative? map" "true" "(associative? {:a 1})"]
|
|
["associative? vec" "true" "(associative? [1])"]
|
|
["indexed? vector" "true" "(indexed? [1])"]
|
|
["counted? vector" "true" "(counted? [1])"])
|
|
|
|
(defspec "predicates / idents"
|
|
["ident? keyword" "true" "(ident? :a)"]
|
|
["ident? symbol" "true" "(ident? (quote a))"]
|
|
["simple-keyword?" "true" "(simple-keyword? :a)"]
|
|
["qualified-keyword?" "true" "(qualified-keyword? :a/b)"]
|
|
["simple-symbol?" "true" "(simple-symbol? (quote a))"]
|
|
["qualified-symbol?" "true" "(qualified-symbol? (quote a/b))"]
|
|
["name of keyword" "\"a\"" "(name :a)"]
|
|
["name of qualified" "\"b\"" "(name :a/b)"]
|
|
["namespace" "\"a\"" "(namespace :a/b)"]
|
|
["namespace simple" "nil" "(namespace :a)"])
|
|
|
|
(defspec "predicates / equality & identity"
|
|
["= same" "true" "(= 1 1)"]
|
|
["= vectors" "true" "(= [1 2] [1 2])"]
|
|
["= vector & list" "true" "(= [1 2] (list 1 2))"]
|
|
["= maps" "true" "(= {:a 1} {:a 1})"]
|
|
["= sets" "true" "(= #{1 2} #{2 1})"]
|
|
["= nested" "true" "(= {:a [1 2]} {:a [1 2]})"]
|
|
["not= differs" "true" "(not= [1 2] [1 3])"]
|
|
["identical? same kw" "true" "(identical? :a :a)"]
|
|
["compare strings" "-1" "(compare \"a\" \"b\")"])
|