diff 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
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/clojure/contrib/test_contrib/test_macro_utils.clj	Sat Aug 21 06:25:44 2010 -0400
     1.3 @@ -0,0 +1,67 @@
     1.4 +;; Test routines for macro_utils.clj
     1.5 +
     1.6 +;; by Konrad Hinsen
     1.7 +;; last updated May 6, 2009
     1.8 +
     1.9 +;; Copyright (c) Konrad Hinsen, 2008. All rights reserved.  The use
    1.10 +;; and distribution terms for this software are covered by the Eclipse
    1.11 +;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
    1.12 +;; which can be found in the file epl-v10.html at the root of this
    1.13 +;; distribution.  By using this software in any fashion, you are
    1.14 +;; agreeing to be bound by the terms of this license.  You must not
    1.15 +;; remove this notice, or any other, from this software.
    1.16 +
    1.17 +(ns clojure.contrib.test-macro-utils
    1.18 +  (:use [clojure.test :only (deftest is are run-tests use-fixtures)]
    1.19 +	[clojure.contrib.macro-utils
    1.20 +	 :only (macrolet symbol-macrolet defsymbolmacro with-symbol-macros
    1.21 +		mexpand-1 mexpand mexpand-all)]
    1.22 +	[clojure.contrib.monads
    1.23 +	 :only (with-monad domonad)]))
    1.24 +
    1.25 +(use-fixtures :each
    1.26 +  (fn [f] (binding [*ns* (the-ns 'clojure.contrib.test-macro-utils)]
    1.27 +	    (f))))
    1.28 +
    1.29 +(deftest macrolet-test
    1.30 +  (is (= (macroexpand-1
    1.31 +	   '(macrolet [(foo [form] `(~form ~form))]  (foo x)))
    1.32 +	 '(do (x x)))))
    1.33 +
    1.34 +(deftest symbol-macrolet-test
    1.35 +  (is (= (macroexpand-1
    1.36 +	   '(symbol-macrolet [x xx y yy]
    1.37 +              (exp [a y] (x y))))
    1.38 +	 '(do (exp [a yy] (xx yy)))))
    1.39 +  (is (= (macroexpand-1
    1.40 +	   '(symbol-macrolet [def foo]
    1.41 +              (def def def)))
    1.42 +	 '(do (def def foo))))
    1.43 +  (is (= (macroexpand-1
    1.44 +	   '(symbol-macrolet [x foo z bar]
    1.45 +	      (let [a x b y x b] [a b x z])))
    1.46 +	 '(do (let* [a foo b y x b] [a b x bar]))))
    1.47 +  (is (= (macroexpand-1
    1.48 +	   '(symbol-macrolet [x foo z bar]
    1.49 +	      (fn ([x y] [x y z]) ([x y z] [x y z]))))
    1.50 +	 '(do (fn* ([x y] [x y bar]) ([x y z] [x y z])))))
    1.51 +  (is (= (macroexpand-1
    1.52 +	   '(symbol-macrolet [x foo z bar]
    1.53 +	      (fn f ([x y] [x y z]) ([x y z] [x y z]))))
    1.54 +	 '(do (fn* f ([x y] [x y bar]) ([x y z] [x y z])))))
    1.55 +  (is (= (nth (second (macroexpand-1
    1.56 +		       '(symbol-macrolet [x xx y yy z zz]
    1.57 +			  (domonad m [a x b y x z] [a b x z])))) 2)
    1.58 +	 '(do (m-bind xx (fn* ([a]
    1.59 +	      (m-bind yy (fn* ([b]
    1.60 +	      (m-bind zz (fn* ([x]
    1.61 +	      (m-result [a b x zz]))))))))))))))
    1.62 +
    1.63 +(deftest symbol-test
    1.64 +  (defsymbolmacro sum-2-3 (plus 2 3))
    1.65 +  (is (= (macroexpand '(with-symbol-macros (+ 1 sum-2-3)))
    1.66 +	 '(do (+ 1 (plus 2 3)))))
    1.67 +  (is (= (macroexpand '(macrolet [(plus [a b] `(+ ~a ~b))] (+ 1 sum-2-3)))
    1.68 +	 '(do (+ 1 (clojure.core/+ 2 3)))))
    1.69 +  (ns-unmap *ns* 'sum-2-3))
    1.70 +