Skip to content
marick edited this page Apr 25, 2012 · 2 revisions

In some versions of Lisp, if was a macro that expanded into cond, something like this:

(defmacro my-if [test true-branch false-branch]
  `(cond ~test ~true-branch :else ~false-branch))

There are (at least!) two ways of testing such a macro. You can test that code that uses it behaves correctly. (Does it take the true branch when the test is true? The false branch otherwise?) You can also expand a form with the macro and check that the right expansion is produced. The =expands-to=> arrow helps you do that:

(fact
  (my-if (odd? 1) 1 2) =expands-to=> (clojure.core/cond (odd? 1) 1 :else 2))
Clone this wiki locally