-
Notifications
You must be signed in to change notification settings - Fork 21
/
standalone.cljc
32 lines (26 loc) · 1.18 KB
/
standalone.cljc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(ns matcher-combinators.standalone
"An API for using matcher-combinators outside the context of a test framework"
(:require [matcher-combinators.core :as core]
[matcher-combinators.parser]))
(defn match
"Returns a map indicating whether the `actual` value matches `expected`.
`expected` can be the expected value, a matcher, or a predicate fn of actual.
Return map includes the following keys:
- :match/result - either :match or :mismatch
- :mismatch/detail - the actual value with mismatch annotations. Only present when :match/result is :mismatch"
[matcher actual]
(let [{:keys [matcher-combinators.result/type
matcher-combinators.result/value]}
(core/match matcher actual)]
(cond-> {:match/result type}
(= :mismatch type)
(assoc :mismatch/detail value))))
(defn match?
"Given a `matcher` and `actual`, returns `true` if
`(match matcher actual)` results in a match. Else, returns `false.`
Given only a `matcher`, returns a function that will
return true or false by the same logic."
([matcher]
(fn [actual] (match? matcher actual)))
([matcher actual]
(core/indicates-match? (core/match matcher actual))))