-
Notifications
You must be signed in to change notification settings - Fork 129
Collection examples
QQ edited this page Dec 23, 2017
·
4 revisions
;; The container checkers work on strings:
user> (fact "the quick brown fox" => (has-suffix "fox"))
true
;; I've tried to make diagnostics useful:
user> (fact "where is the animal?" => (contains "hen"))
FAIL at (NO_SOURCE_FILE:1)
Actual result did not agree with the checking function.
Actual result: "where is the animal?"
Checking function: (contains "hen")
The checker said this about the reason:
Best match found: [\h \e]
false
user> (fact "where is the animal?" => (contains "hen" :gaps-ok))
true
user> (fact "where is the animal?" => (contains "lama" :in-any-order :gaps-ok))
true
;; "Lama" is too a valid alternate spelling of "llama".
;; The same checkers work on collections:
user> (fact [4 'h "regex" 2] => (contains [2 #"re" 4] :in-any-order :gaps-ok))
true
;; You can use checkers within checkers:
user> (fact {:a 1 :b 3 :c 5} => (just {:a odd? :b odd? :c odd?}))
true
;; One I use a lot is for maps with array values:
user> (fact {:notes ["Behold! The value is 5"] :actual 3}
=> (contains {:notes (just [#"value is 5"])}))
true