Advertisement
Guest User

Untitled

a guest
Feb 17th, 2012
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defmacro are
  2.   "Checks multiple assertions with a template expression.
  3.  See clojure.template/do-template for an explanation of
  4.  templates.
  5.  
  6.  Example: (are [x y] (= x y)  
  7.                2 (+ 1 1)
  8.                4 (* 2 2))
  9.  Expands to:
  10.           (do (is (= 2 (+ 1 1)))
  11.               (is (= 4 (* 2 2))))
  12.  
  13.  Note: This breaks some reporting features, such as line numbers."
  14.   {:added "1.1"}
  15.   [argv expr & args]
  16.   (if (and
  17.        ;; Catch no args, i.e., (are [a b] (= a b))
  18.        (seq args)
  19.        ;; Catch wrong number of args
  20.        (zero? (mod (count args) (count argv))))
  21.     `(temp/do-template ~argv (is ~expr) ~@args)
  22.     (throw (IllegalArgumentException. "The number of args doesn't match are's argv."))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement