matcha

->RecordMatcher

(->RecordMatcher match description describe-mismatch)
Positional factory function for class matcha.RecordMatcher.

<

(< a)
matches based if the value given is greater-than or equal to

(matcha/run-match (matcha/< 1) 2) ; => passes
(matcha/run-match (matcha/< 1) 0) ; => fails

<=

(<= a)
matches based if the value given is greater-than or equal to

(matcha/run-match (matcha/<= 1) 1) ; => passes
(matcha/run-match (matcha/<= 1) 0) ; => fails

=

(= a)
matches based on equality of the value given

(matcha/run-match (matcha/= 1) 1) ; => passes
(matcha/run-match (matcha/= 1) 2) ; => fails

>

(> a)
matches based if the value given is greater-than

(matcha/run-match (matcha/> 1) 2) ; => passes
(matcha/run-match (matcha/> 1) 0) ; => fails

>=

(>= a)
matches based if the value given is less-than or equal to

(matcha/run-match (matcha/<= 1) 1) ; => passes
(matcha/run-match (matcha/<= 1) 0) ; => fails

all-of

(all-of & ms)
matches if all of the matchers given pass:

(matcha/run-match (matcha/all-of (matcha/= 1) (matcha/= 1)) 1) ; => passes
(matcha/run-match (matcha/all-of (matcha/= 1) (matcha/= 1)) 2) ; => fails

any-of

(any-of & ms)
passes if any of the given matchers pass:

(matcha/run-match (matcha/any-of (matcha/= 1) (matcha/= 2)) 2) ; => passes
(matcha/run-match (matcha/any-of (matcha/= 3) (matcha/= 2)) 1) ; => fails

assert-good-matcher

(assert-good-matcher {:keys [match description describe-mismatch], :as matcher})

char?

passes if the value is a char
(matcha/run-match matcha/char? {}) ; => passes
(matcha/run-match matcha/char? 1) ; => fails

coll?

passes if the value is a collection

(matcha/run-match matcha/coll? []) ; => passes
(matcha/run-match matcha/coll? 5) ; => fails

contains-in-order

(contains-in-order & strings)
passes if the string contains the strings in order

(matcha/run-match (matcha/contains-in-order "a" "b") "ab") ; => passes
(matcha/run-match (matcha/contains-in-order "a" "b") "ac") ; => fails

contains-in-order-matches

(contains-in-order-matches given-string strings)

contains-string

(contains-string s)
passes if the string includes the given string

(matcha/run-match (matcha/contains-string "a") "a") ; => passes
(matcha/run-match (matcha/contains-string "a") "b") ; => fails

decimal?

passes if the value is a decimal

(matcha/run-match matcha/decimal? bigdec 1)) ; => passes
(matcha/run-match matcha/decimal? 5) ; => fails

describe-class-mismatch

(describe-class-mismatch x)

describe-list

(describe-list call xs)

describe-mismatch-feature

(describe-mismatch-feature x feature-name feature-mismatch)

empty?

matches if the collection passed is empty

(matcha/run-match matcha/empty? [1]) ; => passes
(matcha/run-match matcha/empty? [])  ; => fails

ends-with

(ends-with s)
passes if the string ends with the given string

(matcha/run-match (matcha/ends-with "a") "ba") ; => passes
(matcha/run-match (matcha/ends-with "a") "ab") ; => fails

equal-ignoring-case

(equal-ignoring-case s)
passes if the string is equal to the other string ignoring case

(matcha/run-match (matcha/equal-ignoring-case "a") "A") ; => passes
(matcha/run-match (matcha/equal-ignoring-case "a") "ab") ; => fails

equal-ignoring-whitespace

(equal-ignoring-whitespace s)
passes if the string is equal to the other string ignoring whitespace

(matcha/run-match (matcha/equal-ignoring-whitespace "a") "a ") ; => passes
(matcha/run-match (matcha/equal-ignoring-whitespace "a ") "ab") ; => fails

every?

(every? m)
passes if every element of the sequence received matches the matcher

(matcha/run-match (matcha/every? (matcha/= 1)) [1]) ; => passes
(matcha/run-match (matcha/every? (matcha/= 1)) [2]) ; => fails

falsey?

passes if the value is falsey

(matcha/run-match matcha/falsey? #{}) ; => passes
(matcha/run-match matcha/falsey? nil) ; => fails

float?

passes if the value is a float

(matcha/run-match matcha/float? (float 1.0)) ; => passes
(matcha/run-match matcha/float? 5) ; => fails

fn?

passes if the value is a function

(matcha/run-match matcha/fn? #()) ; => passes
(matcha/run-match matcha/fn? 5) ; => fails

format-message

(format-message result)
turns the results of a failing match into a human readable error message,
suitable for printing with clojure.core/print or clojure.core/println

has-count

(has-count n)
passes if the sequence received has the given count
(matcha/run-match (matcha/has-count 1) [1]) ; => passes
(matcha/run-match (matcha/has-count 2) [])  ; => fails

has-count-that

(has-count-that m)
passes if the sequence received has the given count
(matcha/run-match (matcha/has-count-that (matcha/= 1)) [1]) ; => passes
(matcha/run-match (matcha/has-count-that (matcha/= 1)) [])  ; => fails

has-denominator

(has-denominator n)
passes if the ratio has the denominator given
(matcha/run-match (matcha/has-numerator 1) 1/10) ; => passes
(matcha/run-match matcha/nil? 1) ; => fails

has-entry

(has-entry k v)
passes if the map received has the given map-entry

(matcha/run-match (matcha/has-entry :a 1) {:a 1}) ; => passes
(matcha/run-match (matcha/has-entry :a 1) {:a 2})  ; => fails

has-entry-that

(has-entry-that k matcher)
passes if the map received has a value at the key given that matches the matcher

(matcha/run-match (matcha/has-entry-that :a (matcha/= 1)) {:a 1}) ; => passes
(matcha/run-match (matcha/has-entry-that :a (matcha/= 2)) {:a 2})  ; => fails

has-key

(has-key v)
passes if the map received has the given key

(matcha/run-match (matcha/has-key 1) {:a 1}) ; => passes
(matcha/run-match (matcha/has-key 1) {:a 2})  ; => fails

has-nth

(has-nth m n)
passes if the sequence received has the value matching the matcher given at
(nth n)

(matcha/run-match (matcha/has-count 1) [1]) ; => passes
(matcha/run-match (matcha/has-count 2) [])  ; => fails

has-numerator

(has-numerator n)
passes if the ratio has the numerator given
(matcha/run-match (matcha/has-numerator 1) 1/10) ; => passes
(matcha/run-match matcha/nil? 1) ; => fails

has-val

(has-val v)
passes if the map received has the given val

(matcha/run-match (matcha/has-val 1) {:a 1}) ; => passes
(matcha/run-match (matcha/has-val 1) {:a 2})  ; => fails

includes

(includes x)
passes if the sequence received includes the given item

(matcha/run-match (matcha/includes 1) [1]) ; => passes
(matcha/run-match (matcha/includes 1) [2]) ; => fails

instance?

(instance? klazz)
passes if the value matches the given class
(matcha/run-match (matcha/instance? clojure.lang.Keyword) :foo) ; => passes
(matcha/run-match (matcha/instance? clojure.lang.Keyword) 1) ; => fails

is

macro

(is matcher x)
clojure.test integration

runs a matcher against a given value, reporting failures via clojure.test
(just like `clojure.test/is`)

is-in?

(is-in? xs)
passes if the value is included in the given collection

(matcha/run-match (matcha/is-in? [1]) 1) ; => passes
(matcha/run-match (matcha/is-in? [5]) 1) ; => fails

isa?

(isa? parent)
passes if the value isa? the given object

(matcha/run-match (matcha/isa? :parent) :child) ; => passes
(matcha/run-match (matcha/isa? :child) :child) ; => fails

keyword?

passes if the value is a keyword
(matcha/run-match matcha/keyword? :foo) ; => passes
(matcha/run-match matcha/keyword? 1) ; => fails

list?

passes if the value is a list

(matcha/run-match matcha/list? '()) ; => passes
(matcha/run-match matcha/list? 5) ; => fails

make-record-matcher

(make-record-matcher match description)(make-record-matcher match description describe-mismatch)

map->RecordMatcher

(map->RecordMatcher m__5869__auto__)
Factory function for class matcha.RecordMatcher, taking a map of keywords to field values.

map?

passes if the value is a map
(matcha/run-match matcha/map? {}) ; => passes
(matcha/run-match matcha/map? 1) ; => fails

Matcher

protocol

members

describe-mismatch

(describe-mismatch this a)
returns a human readable string of the mismatch of the matcher and the value given. It is an *error* to call describe-mismatch without checking match first, and you should expect unspecified behavior, exceptions, and so on.

description

(description this)
returns a human readable description of the matcher

match

(match this a)
returns a truthy value if the matcher matches the given value

nil?

passes if the value is nil
(matcha/run-match matcha/nil? nil) ; => passes
(matcha/run-match matcha/nil? 1) ; => fails

not

(not m)
passes if the given matcher fails
(matcha/run-match (matcha/not (matcha/= 1)) 1) ; => passes
(matcha/run-match (matcha/not (matcha/= 2)) 1) ; => fails

on

(on f m feature-name)(on f m feature-name class-name)
combinator. Passes if the (f the-value) matches the matcher

pp

(pp x)

ratio?

passes if the value is a ratio

(matcha/run-match matcha/ratio? 1/5) ; => passes
(matcha/run-match matcha/ratio? 5) ; => fails

rational?

passes if the value is a rational

(matcha/run-match matcha/rational? 1) ; => passes
(matcha/run-match matcha/rational? "a") ; => fails

re-matches

(re-matches re)
passes if the string matches the regex given

(matcha/run-match (matcha/is-in? #"\d+") "1") ; => passes
(matcha/run-match (matcha/is-in? #"\d+") "a") ; => fails

run-match

(run-match matcher a)
runs a matcher, given a value to match against.
Returns a map:

if the matcher matches the value:
{:pass? true}

if the matcher fails:
{:pass? false
 :matcher matcher
 :expected (a string)
 :was (a string)}

the results can be made human readable with (format-message result)

seq?

passes if the value is a seq
(matcha/run-match matcha/seq? {}) ; => passes
(matcha/run-match matcha/seq? 1) ; => fails

set?

passes if the value is a set

(matcha/run-match matcha/set? #{}) ; => passes
(matcha/run-match matcha/set? 5) ; => fails

some

(some m)
passes if some elements of the sequence received matches the matcher

(matcha/run-match (matcha/some? (matcha/= 1)) [1 2]) ; => passes
(matcha/run-match (matcha/some? (matcha/= 1)) [2]) ; => fails

standard-describe-mismatch

(standard-describe-mismatch x)

starts-with

(starts-with s)
passes if the string starts with the given string

(matcha/run-match (matcha/starts-with "a") "ab") ; => passes
(matcha/run-match (matcha/starts-with "a") "ba") ; => fails

string?

passes if the value is a string
(matcha/run-match matcha/string? "foo") ; => passes
(matcha/run-match matcha/string? 1) ; => fails

symbol?

passes if the value is a symbol
(matcha/run-match matcha/symbol? 'foo) ; => passes
(matcha/run-match matcha/symbol? 1) ; => fails

truthy?

passes if the value is truthy

(matcha/run-match matcha/truthy? #{}) ; => passes
(matcha/run-match matcha/truthy? nil) ; => fails

type-matcher

(type-matcher pred type-name m)
checks the value matches a predicate before matching
using the matcher given.

vector?

passes if the value is a vector
(matcha/run-match matcha/vector? {}) ; => passes
(matcha/run-match matcha/vector? 1) ; => fails