structural-typing.assist.testutil

Useful shorthand for tests of new code, like custom predicates.

both-names

(both-names pred)

Generate the readable names of both the original and lifted predicates. Provoke a test failure if they’re not the same. Otherwise, return the value for further checking.

 (both-names (member [1 2 3])) => "(member [1 2 3])"

check-all-for-explanations

(check-all-for-explanations & args)

Same as check-for-explanations but uses all-built-like.

check-for-explanations

(check-for-explanations & args)

Run built-like against the arguments. The result is supposed to be error messages and a nil return value. If not, provoke an error. If so, return the explanations.

 (check-for-explanations :Figure {:points 3}) => (just (err:missing :color))

err:maplike

(err:maplike path bad-nonterminal)

err:missing

(err:missing path)

err:not-collection

err:not-maplike

err:not-sequential

err:selector-at-nil

(err:selector-at-nil path)

err:shouldbe

(err:shouldbe path should-be is)(err:shouldbe path should-be is omit-quotes)

Produces the same error messsage produced when a predicate not altered by explain-with fails.

err:value-nil

(err:value-nil path)

err:whole-value-nil

(err:whole-value-nil)

explain-lifted

(explain-lifted pred exval)

lift-and-run the predicate against the expred, then generate a list of explanations. Note that it’s safe to use this on an already-lifted predicate.

exval

(exval leaf-value path whole-value)(exval leaf-value path)(exval leaf-value)

Generate an “extended value”. Omitted values are replaced with useful defaults.

  (exval 5 :x) => (exval 5 :x {:x 5})
  (exval 5) => (exval 5 :x {:x 5})

lift-and-run

(lift-and-run pred exval)

lift-pred the pred and run it against the exval.

oopsie-for

(oopsie-for leaf-value & {:as kvs})

Create a function that takes an oopsie and checks it. Examples:

 ... => (oopsie-for 5) ; :leaf-value must be 5, other keys irrelevant
 ... => (oopsie-for 5 :whole-value {:x 5})  ; two keys relevant, others not.