comparison src/clojure/contrib/test_contrib/test_macro_utils.clj @ 10:ef7dbbd6452c

added clojure source goodness
author Robert McIntyre <rlm@mit.edu>
date Sat, 21 Aug 2010 06:25:44 -0400
parents
children
comparison
equal deleted inserted replaced
9:35cf337adfcf 10:ef7dbbd6452c
1 ;; Test routines for macro_utils.clj
2
3 ;; by Konrad Hinsen
4 ;; last updated May 6, 2009
5
6 ;; Copyright (c) Konrad Hinsen, 2008. All rights reserved. The use
7 ;; and distribution terms for this software are covered by the Eclipse
8 ;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
9 ;; which can be found in the file epl-v10.html at the root of this
10 ;; distribution. By using this software in any fashion, you are
11 ;; agreeing to be bound by the terms of this license. You must not
12 ;; remove this notice, or any other, from this software.
13
14 (ns clojure.contrib.test-macro-utils
15 (:use [clojure.test :only (deftest is are run-tests use-fixtures)]
16 [clojure.contrib.macro-utils
17 :only (macrolet symbol-macrolet defsymbolmacro with-symbol-macros
18 mexpand-1 mexpand mexpand-all)]
19 [clojure.contrib.monads
20 :only (with-monad domonad)]))
21
22 (use-fixtures :each
23 (fn [f] (binding [*ns* (the-ns 'clojure.contrib.test-macro-utils)]
24 (f))))
25
26 (deftest macrolet-test
27 (is (= (macroexpand-1
28 '(macrolet [(foo [form] `(~form ~form))] (foo x)))
29 '(do (x x)))))
30
31 (deftest symbol-macrolet-test
32 (is (= (macroexpand-1
33 '(symbol-macrolet [x xx y yy]
34 (exp [a y] (x y))))
35 '(do (exp [a yy] (xx yy)))))
36 (is (= (macroexpand-1
37 '(symbol-macrolet [def foo]
38 (def def def)))
39 '(do (def def foo))))
40 (is (= (macroexpand-1
41 '(symbol-macrolet [x foo z bar]
42 (let [a x b y x b] [a b x z])))
43 '(do (let* [a foo b y x b] [a b x bar]))))
44 (is (= (macroexpand-1
45 '(symbol-macrolet [x foo z bar]
46 (fn ([x y] [x y z]) ([x y z] [x y z]))))
47 '(do (fn* ([x y] [x y bar]) ([x y z] [x y z])))))
48 (is (= (macroexpand-1
49 '(symbol-macrolet [x foo z bar]
50 (fn f ([x y] [x y z]) ([x y z] [x y z]))))
51 '(do (fn* f ([x y] [x y bar]) ([x y z] [x y z])))))
52 (is (= (nth (second (macroexpand-1
53 '(symbol-macrolet [x xx y yy z zz]
54 (domonad m [a x b y x z] [a b x z])))) 2)
55 '(do (m-bind xx (fn* ([a]
56 (m-bind yy (fn* ([b]
57 (m-bind zz (fn* ([x]
58 (m-result [a b x zz]))))))))))))))
59
60 (deftest symbol-test
61 (defsymbolmacro sum-2-3 (plus 2 3))
62 (is (= (macroexpand '(with-symbol-macros (+ 1 sum-2-3)))
63 '(do (+ 1 (plus 2 3)))))
64 (is (= (macroexpand '(macrolet [(plus [a b] `(+ ~a ~b))] (+ 1 sum-2-3)))
65 '(do (+ 1 (clojure.core/+ 2 3)))))
66 (ns-unmap *ns* 'sum-2-3))
67