Checkers for collections and strings.
Checkers for collections and strings.
(compatibility-check actual expected looseness)
Fling an error if the combination of actual, expected, and looseness won't work.
Fling an error if the combination of actual, expected, and looseness won't work.
(contains expected)
(contains expected looseness)
Checks that the expected result is a subsequence of the actual result:
To succeed, f's result must be (1) contiguous and (2) in the same order as in the contains clause. Here are examples:
[3 4 5 700] => (contains [4 5 700]) ; true [4 700 5] => (contains [4 5 700]) ; false [4 5 'hi 700] => (contains [4 5 700]) ; false
The :in-any-order modifier loosens the second requirement:
['hi 700 5 4] => (contains [4 5 700] :in-any-order) ; true [4 5 'hi 700] => (contains [4 5 700] :in-any-order) ; false b/c 'hi is in middle
The :gaps-ok modifier loosens the first:
[4 5 'hi 700] => (contains [4 5 700] :gaps-ok) ; true [4 700 'hi' 5] => (contains [4 5 700] :gaps-ok) ; false b/c of bad order
The two modifiers can be used at the same time:
[4 700 5] => (contains [4 5 700] :gaps-ok :in-any-order) ; true [4 5 'hi 700] => (contains [4 5 700] :in-any-order :gaps-ok) ; true [700 'hi 4 5 'hi] => (contains [4 5 700] :in-any-order :gaps-ok) ; true
Another way to indicate :in-any-order is to describe what's contained by a set. The following two are equivalent:
[700 4 5] => (contains [4 5 700] :in-any-order) [700 4 5] => (contains #{4 5 700})
:gaps-ok can be used with a set. (So can :in-any-order, but it has no effect.)
Checks that the expected result is a subsequence of the actual result: To succeed, f's result must be (1) contiguous and (2) in the same order as in the contains clause. Here are examples: [3 4 5 700] => (contains [4 5 700]) ; true [4 700 5] => (contains [4 5 700]) ; false [4 5 'hi 700] => (contains [4 5 700]) ; false The :in-any-order modifier loosens the second requirement: ['hi 700 5 4] => (contains [4 5 700] :in-any-order) ; true [4 5 'hi 700] => (contains [4 5 700] :in-any-order) ; false b/c 'hi is in middle The :gaps-ok modifier loosens the first: [4 5 'hi 700] => (contains [4 5 700] :gaps-ok) ; true [4 700 'hi' 5] => (contains [4 5 700] :gaps-ok) ; false b/c of bad order The two modifiers can be used at the same time: [4 700 5] => (contains [4 5 700] :gaps-ok :in-any-order) ; true [4 5 'hi 700] => (contains [4 5 700] :in-any-order :gaps-ok) ; true [700 'hi 4 5 'hi] => (contains [4 5 700] :in-any-order :gaps-ok) ; true Another way to indicate :in-any-order is to describe what's contained by a set. The following two are equivalent: [700 4 5] => (contains [4 5 700] :in-any-order) [700 4 5] => (contains #{4 5 700}) :gaps-ok can be used with a set. (So can :in-any-order, but it has no effect.)
(eight-of expected)
Checks whether a sequence contains precisely eight results, and that they each match the checker.
Ex. (fact [:a :a :a :a :a :a :a :a] => (eight-of :a))
Checks whether a sequence contains precisely eight results, and that they each match the checker. Ex. (fact [:a :a :a :a :a :a :a :a] => (eight-of :a))
(five-of expected)
Checks whether a sequence contains precisely five results, and that they each match the checker.
Ex. (fact [:a :a :a :a :a] => (five-of :a))
Checks whether a sequence contains precisely five results, and that they each match the checker. Ex. (fact [:a :a :a :a :a] => (five-of :a))
(four-of expected)
Checks whether a sequence contains precisely four results, and that they each match the checker.
Ex. (fact [:a :a :a :a] => (four-of :a))
Checks whether a sequence contains precisely four results, and that they each match the checker. Ex. (fact [:a :a :a :a] => (four-of :a))
(has quantifier predicate)
You can apply Clojure's quantification functions (every?, some, and so on) to all the values of sequence.
Ex. (fact (f) => (has every? odd?))
You can apply Clojure's quantification functions (every?, some, and so on) to all the values of sequence. Ex. (fact (f) => (has every? odd?))
(has-prefix expected-prefix)
(has-prefix expected-prefix looseness?)
Checks that the actual result starts with the expected result:
[1 2 3] => (has-prefix [1 2]) ; true [1 2 3] => (has-prefix [2 1]) ; false - order matters [1 2 3] => (has-prefix [2 1] :in-any-order) ; true [1 2 3] => (has-prefix #{2 1}) ; true
Checks that the actual result starts with the expected result: [1 2 3] => (has-prefix [1 2]) ; true [1 2 3] => (has-prefix [2 1]) ; false - order matters [1 2 3] => (has-prefix [2 1] :in-any-order) ; true [1 2 3] => (has-prefix #{2 1}) ; true
(has-suffix expected-suffix)
(has-suffix expected-suffix looseness?)
Checks that the actual result ends with the expected result:
[1 2 3] => (has-suffix [2 3]) ; true [1 2 3] => (has-suffix [3 2]) ; false - order matters [1 2 3] => (has-suffix [3 2] :in-any-order) ; true [1 2 3] => (has-suffix #{3 2}) ; true
Checks that the actual result ends with the expected result: [1 2 3] => (has-suffix [2 3]) ; true [1 2 3] => (has-suffix [3 2]) ; false - order matters [1 2 3] => (has-suffix [3 2] :in-any-order) ; true [1 2 3] => (has-suffix #{3 2}) ; true
(just expected)
(just expected looseness)
A variant of contains, just, will fail if the left-hand-side contains any extra values: [1 2 3] => (just [1 2 3]) ; true [1 2 3] => (just [1 2 3 4]) ; false
The first of those seems senseless, since you could just use this:
[1 2 3] => [1 2 3]
However, it's required if you want to use checkers in the expected result:
[1 2 3] => [odd? even? odd?] ; false b/c 2nd-level fns aren't normally treated as checkers. [1 2 3] => (just [odd? even? odd?]) ; true
just is also useful if you don't care about order:
[1 3 2] => (just [1 2 3] :in-any-order) [1 3 2] => (just #{1 2 3})
A variant of contains, just, will fail if the left-hand-side contains any extra values: [1 2 3] => (just [1 2 3]) ; true [1 2 3] => (just [1 2 3 4]) ; false The first of those seems senseless, since you could just use this: [1 2 3] => [1 2 3] However, it's required if you want to use checkers in the expected result: [1 2 3] => [odd? even? odd?] ; false b/c 2nd-level fns aren't normally treated as checkers. [1 2 3] => (just [odd? even? odd?]) ; true just is also useful if you don't care about order: [1 3 2] => (just [1 2 3] :in-any-order) [1 3 2] => (just #{1 2 3})
(n-of expected expected-count)
Checks whether a sequence contains precisely n results, and that they each match the checker.
Ex. (fact (repeat 100 :a) => (n-of :a 100))
Checks whether a sequence contains precisely n results, and that they each match the checker. Ex. (fact (repeat 100 :a) => (n-of :a 100))
(nine-of expected)
Checks whether a sequence contains precisely nine results, and that they each match the checker.
Ex. (fact [:a :a :a :a :a :a :a :a :a] => (nine-of :a))
Checks whether a sequence contains precisely nine results, and that they each match the checker. Ex. (fact [:a :a :a :a :a :a :a :a :a] => (nine-of :a))
(one-of expected)
Checks whether a sequence contains precisely one result, and that it matches the checker.
Ex. (fact [:a] => (one-of :a))
Checks whether a sequence contains precisely one result, and that it matches the checker. Ex. (fact [:a] => (one-of :a))
(seven-of expected)
Checks whether a sequence contains precisely seven results, and that they each match the checker.
Ex. (fact [:a :a :a :a :a :a :a] => (seven-of :a))
Checks whether a sequence contains precisely seven results, and that they each match the checker. Ex. (fact [:a :a :a :a :a :a :a] => (seven-of :a))
(six-of expected)
Checks whether a sequence contains precisely six results, and that they each match the checker.
Ex. (fact [:a :a :a :a :a :a] => (six-of :a))
Checks whether a sequence contains precisely six results, and that they each match the checker. Ex. (fact [:a :a :a :a :a :a] => (six-of :a))
(standardized-arguments actual expected looseness)
Reduce arguments to standard forms so there are fewer combinations to consider. Also blow up for some incompatible forms.
Reduce arguments to standard forms so there are fewer combinations to consider. Also blow up for some incompatible forms.
(ten-of expected)
Checks whether a sequence contains precisely ten results, and that they each match the checker.
Ex. (fact [:a :a :a :a :a :a :a :a :a :a] => (ten-of :a))
Checks whether a sequence contains precisely ten results, and that they each match the checker. Ex. (fact [:a :a :a :a :a :a :a :a :a :a] => (ten-of :a))
(three-of expected)
Checks whether a sequence contains precisely three results, and that they each match the checker.
Ex. (fact [:a :a :a] => (three-of :a))
Checks whether a sequence contains precisely three results, and that they each match the checker. Ex. (fact [:a :a :a] => (three-of :a))
(two-of expected)
Checks whether a sequence contains precisely two results, and that they each match the checker.
Ex. (fact [:a :a] => (two-of :a))
Checks whether a sequence contains precisely two results, and that they each match the checker. Ex. (fact [:a :a] => (two-of :a))
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close