diff options
author | Konrad Hinsen <konrad.hinsen@laposte.net> | 2009-05-05 12:58:44 +0000 |
---|---|---|
committer | Konrad Hinsen <konrad.hinsen@laposte.net> | 2009-05-05 12:58:44 +0000 |
commit | dbb8c617a842103d671c0d7cf692aab4387a5717 (patch) | |
tree | cc62fc9aba199d793c085840ec88326e923966cd /src/clojure/contrib/test_contrib | |
parent | 1d80038e7605a9b4487f5a6f17de33780c8ef188 (diff) |
New library macro-utils
Diffstat (limited to 'src/clojure/contrib/test_contrib')
-rw-r--r-- | src/clojure/contrib/test_contrib/macro_utils.clj | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/clojure/contrib/test_contrib/macro_utils.clj b/src/clojure/contrib/test_contrib/macro_utils.clj new file mode 100644 index 00000000..25a0fcaf --- /dev/null +++ b/src/clojure/contrib/test_contrib/macro_utils.clj @@ -0,0 +1,64 @@ +;; Test routines for macro_utils.clj + +;; by Konrad Hinsen +;; last updated May 4, 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-contrib.macro-utils + (:use [clojure.contrib.test-is :only (deftest is are run-tests)] + [clojure.contrib.macro-utils + :only (macrolet symbol-macrolet defsymbolmacro with-symbol-macros + mexpand-1 mexpand mexpand-all)] + [clojure.contrib.monads + :only (with-monad domonad)])) + +(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 (= (macroexpand-1 + '(symbol-macrolet [x xx y yy z zz] + (domonad m [a x b y x z] [a b x z]))) + '(do (let* [m-bind (:m-bind m) m-result (:m-result m) + m-zero (:m-zero m) m-plus (:m-plus m)] + (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)) |