annotate src/clojure/test_clojure/metadata.clj @ 10:ef7dbbd6452c

added clojure source goodness
author Robert McIntyre <rlm@mit.edu>
date Sat, 21 Aug 2010 06:25:44 -0400
parents
children
rev   line source
rlm@10 1 ; Copyright (c) Rich Hickey. All rights reserved.
rlm@10 2 ; The use and distribution terms for this software are covered by the
rlm@10 3 ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
rlm@10 4 ; which can be found in the file epl-v10.html at the root of this distribution.
rlm@10 5 ; By using this software in any fashion, you are agreeing to be bound by
rlm@10 6 ; the terms of this license.
rlm@10 7 ; You must not remove this notice, or any other, from this software.
rlm@10 8
rlm@10 9 ; Authors: Stuart Halloway, Frantisek Sodomka
rlm@10 10
rlm@10 11 (ns clojure.test-clojure.metadata
rlm@10 12 (:use clojure.test
rlm@10 13 [clojure.test-clojure.helpers :only (eval-in-temp-ns)]))
rlm@10 14
rlm@10 15 (def public-namespaces
rlm@10 16 '[clojure.core
rlm@10 17 clojure.pprint
rlm@10 18 clojure.inspector
rlm@10 19 clojure.set
rlm@10 20 clojure.stacktrace
rlm@10 21 clojure.test
rlm@10 22 clojure.walk
rlm@10 23 clojure.xml
rlm@10 24 clojure.zip
rlm@10 25 clojure.java.io
rlm@10 26 clojure.java.browse
rlm@10 27 clojure.java.javadoc
rlm@10 28 clojure.java.shell
rlm@10 29 clojure.string])
rlm@10 30
rlm@10 31 (doseq [ns public-namespaces]
rlm@10 32 (require ns))
rlm@10 33
rlm@10 34 (def public-vars
rlm@10 35 (mapcat #(vals (ns-publics %)) public-namespaces))
rlm@10 36
rlm@10 37 (def public-vars-with-docstrings
rlm@10 38 (filter (comp :doc meta) public-vars))
rlm@10 39
rlm@10 40 (deftest public-vars-with-docstrings-have-added
rlm@10 41 (is (= [] (remove (comp :added meta) public-vars-with-docstrings))))
rlm@10 42
rlm@10 43 (deftest interaction-of-def-with-metadata
rlm@10 44 (testing "initial def sets metadata"
rlm@10 45 (let [v (eval-in-temp-ns
rlm@10 46 (def ^{:a 1} foo 0)
rlm@10 47 #'foo)]
rlm@10 48 (is (= 1 (-> v meta :a)))))
rlm@10 49 (testing "subsequent declare doesn't overwrite metadata"
rlm@10 50 (let [v (eval-in-temp-ns
rlm@10 51 (def ^{:b 2} bar 0)
rlm@10 52 (declare bar)
rlm@10 53 #'bar)]
rlm@10 54 (is (= 2 (-> v meta :b))))
rlm@10 55 (testing "when compiled"
rlm@10 56 (let [v (eval-in-temp-ns
rlm@10 57 (def ^{:c 3} bar 0)
rlm@10 58 (defn declare-bar []
rlm@10 59 (declare bar))
rlm@10 60 (declare-bar)
rlm@10 61 #'bar)]
rlm@10 62 (is (= 3 (-> v meta :c))))))
rlm@10 63 (testing "subsequent def with init-expr *does* overwrite metadata"
rlm@10 64 (let [v (eval-in-temp-ns
rlm@10 65 (def ^{:d 4} quux 0)
rlm@10 66 (def quux 1)
rlm@10 67 #'quux)]
rlm@10 68 (is (nil? (-> v meta :d))))
rlm@10 69 (testing "when compiled"
rlm@10 70 (let [v (eval-in-temp-ns
rlm@10 71 (def ^{:e 5} quux 0)
rlm@10 72 (defn def-quux []
rlm@10 73 (def quux 1))
rlm@10 74 (def-quux)
rlm@10 75 #'quux)]
rlm@10 76 (is (nil? (-> v meta :e)))))))