diff options
author | Stuart Sierra <mail@stuartsierra.com> | 2010-08-10 21:40:47 -0400 |
---|---|---|
committer | Stuart Sierra <mail@stuartsierra.com> | 2010-08-10 21:40:47 -0400 |
commit | 38743f83bdd60d6687dabcea3864b04bbd554a6c (patch) | |
tree | 44b31d4900c2d5720679abe911694d64fc516d0a /modules/macro-utils/src | |
parent | a6a92b9b3d2bfd9a56e1e5e9cfba706d1aeeaae5 (diff) |
Add test sources to their respective modules
Diffstat (limited to 'modules/macro-utils/src')
-rw-r--r-- | modules/macro-utils/src/test/clojure/clojure/contrib/test_macro_utils.clj | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/modules/macro-utils/src/test/clojure/clojure/contrib/test_macro_utils.clj b/modules/macro-utils/src/test/clojure/clojure/contrib/test_macro_utils.clj new file mode 100644 index 00000000..8b603a67 --- /dev/null +++ b/modules/macro-utils/src/test/clojure/clojure/contrib/test_macro_utils.clj @@ -0,0 +1,67 @@ +;; Test routines for macro_utils.clj + +;; by Konrad Hinsen +;; last updated May 6, 2009 + +;; Copyright (c) Konrad Hinsen, 2008. All rights reserved. The use +;; and distribution terms for this software are covered by the Eclipse +;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) +;; which can be found in the file epl-v10.html at the root of this +;; distribution. By using this software in any fashion, you are +;; agreeing to be bound by the terms of this license. You must not +;; remove this notice, or any other, from this software. + +(ns clojure.contrib.test-macro-utils + (:use [clojure.test :only (deftest is are run-tests use-fixtures)] + [clojure.contrib.macro-utils + :only (macrolet symbol-macrolet defsymbolmacro with-symbol-macros + mexpand-1 mexpand mexpand-all)] + [clojure.contrib.monads + :only (with-monad domonad)])) + +(use-fixtures :each + (fn [f] (binding [*ns* (the-ns 'clojure.contrib.test-macro-utils)] + (f)))) + +(deftest macrolet-test + (is (= (macroexpand-1 + '(macrolet [(foo [form] `(~form ~form))] (foo x))) + '(do (x x))))) + +(deftest symbol-macrolet-test + (is (= (macroexpand-1 + '(symbol-macrolet [x xx y yy] + (exp [a y] (x y)))) + '(do (exp [a yy] (xx yy))))) + (is (= (macroexpand-1 + '(symbol-macrolet [def foo] + (def def def))) + '(do (def def foo)))) + (is (= (macroexpand-1 + '(symbol-macrolet [x foo z bar] + (let [a x b y x b] [a b x z]))) + '(do (let* [a foo b y x b] [a b x bar])))) + (is (= (macroexpand-1 + '(symbol-macrolet [x foo z bar] + (fn ([x y] [x y z]) ([x y z] [x y z])))) + '(do (fn* ([x y] [x y bar]) ([x y z] [x y z]))))) + (is (= (macroexpand-1 + '(symbol-macrolet [x foo z bar] + (fn f ([x y] [x y z]) ([x y z] [x y z])))) + '(do (fn* f ([x y] [x y bar]) ([x y z] [x y z]))))) + (is (= (nth (second (macroexpand-1 + '(symbol-macrolet [x xx y yy z zz] + (domonad m [a x b y x z] [a b x z])))) 2) + '(do (m-bind xx (fn* ([a] + (m-bind yy (fn* ([b] + (m-bind zz (fn* ([x] + (m-result [a b x zz])))))))))))))) + +(deftest symbol-test + (defsymbolmacro sum-2-3 (plus 2 3)) + (is (= (macroexpand '(with-symbol-macros (+ 1 sum-2-3))) + '(do (+ 1 (plus 2 3))))) + (is (= (macroexpand '(macrolet [(plus [a b] `(+ ~a ~b))] (+ 1 sum-2-3))) + '(do (+ 1 (clojure.core/+ 2 3))))) + (ns-unmap *ns* 'sum-2-3)) + |