-
Notifications
You must be signed in to change notification settings - Fork 128
Extended equality
Midje check's the right-hand side of a =>
using extended equality. That adds some special cases onto Clojure's =
:
-
When the right-hand-side is a function, it's applied to the actual result:
1 => even?
See Checkers for a prepackaged set of useful functions.
-
When the left-hand-side is a string and the right-hand-side is a regular expression, the behavior is that of
re-find
:"the entire string need not match" => #"ne*d"
If you want the entire string to match, you can either write the regular expression with
^
and$
, or you can use one of the prepackaged checkers:"the entire string need not match" => (just #"ne*d") ; fails
-
Unlike with Clojure's
=
, two regular expressions formed from=
strings are counted as equal. -
If a comparison would normally blow up, it returns false:
"five" => odd? ; false instead of a java.lang.ClassCastException
It's common for checkers to apply extended equality recursively. Here, for example, is how you say that a list of numbers must be exactly two even numbers followed by two odd:
[2 4 1 3] => (just [even? even? odd? odd?])
If you want to use extended equality in your own checkers, include this in your namespace declaration:
(:use [midje.util.checkers [extended-=]])