diff 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
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/clojure/test_clojure/metadata.clj	Sat Aug 21 06:25:44 2010 -0400
     1.3 @@ -0,0 +1,76 @@
     1.4 +;   Copyright (c) Rich Hickey. All rights reserved.
     1.5 +;   The use and distribution terms for this software are covered by the
     1.6 +;   Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
     1.7 +;   which can be found in the file epl-v10.html at the root of this distribution.
     1.8 +;   By using this software in any fashion, you are agreeing to be bound by
     1.9 +;   the terms of this license.
    1.10 +;   You must not remove this notice, or any other, from this software.
    1.11 +
    1.12 +; Authors: Stuart Halloway, Frantisek Sodomka
    1.13 +
    1.14 +(ns clojure.test-clojure.metadata
    1.15 +  (:use clojure.test
    1.16 +        [clojure.test-clojure.helpers :only (eval-in-temp-ns)]))
    1.17 +
    1.18 +(def public-namespaces
    1.19 +  '[clojure.core
    1.20 +    clojure.pprint
    1.21 +    clojure.inspector
    1.22 +    clojure.set
    1.23 +    clojure.stacktrace
    1.24 +    clojure.test
    1.25 +    clojure.walk
    1.26 +    clojure.xml
    1.27 +    clojure.zip
    1.28 +    clojure.java.io
    1.29 +    clojure.java.browse
    1.30 +    clojure.java.javadoc
    1.31 +    clojure.java.shell
    1.32 +    clojure.string])
    1.33 +
    1.34 +(doseq [ns public-namespaces]
    1.35 +  (require ns))
    1.36 +
    1.37 +(def public-vars
    1.38 +  (mapcat #(vals (ns-publics %)) public-namespaces))
    1.39 +
    1.40 +(def public-vars-with-docstrings
    1.41 +  (filter (comp :doc meta) public-vars))
    1.42 +
    1.43 +(deftest public-vars-with-docstrings-have-added
    1.44 +  (is (= [] (remove (comp :added meta) public-vars-with-docstrings))))
    1.45 +
    1.46 +(deftest interaction-of-def-with-metadata
    1.47 +  (testing "initial def sets metadata"
    1.48 +    (let [v (eval-in-temp-ns
    1.49 +             (def ^{:a 1} foo 0)
    1.50 +             #'foo)]
    1.51 +      (is (= 1 (-> v meta :a)))))
    1.52 +  (testing "subsequent declare doesn't overwrite metadata"
    1.53 +    (let [v (eval-in-temp-ns
    1.54 +             (def ^{:b 2} bar 0)
    1.55 +             (declare bar)
    1.56 +             #'bar)]
    1.57 +      (is (= 2 (-> v meta :b))))
    1.58 +    (testing "when compiled"
    1.59 +      (let [v (eval-in-temp-ns
    1.60 +               (def ^{:c 3} bar 0)
    1.61 +               (defn declare-bar []
    1.62 +                 (declare bar))
    1.63 +               (declare-bar)
    1.64 +               #'bar)]
    1.65 +        (is (= 3 (-> v meta :c))))))
    1.66 +  (testing "subsequent def with init-expr *does* overwrite metadata"
    1.67 +    (let [v (eval-in-temp-ns
    1.68 +             (def ^{:d 4} quux 0)
    1.69 +             (def quux 1)
    1.70 +             #'quux)]
    1.71 +      (is (nil? (-> v meta :d))))
    1.72 +    (testing "when compiled"
    1.73 +      (let [v (eval-in-temp-ns
    1.74 +               (def ^{:e 5} quux 0)
    1.75 +               (defn def-quux []
    1.76 +                 (def quux 1))
    1.77 +               (def-quux)
    1.78 +               #'quux)]
    1.79 +        (is (nil? (-> v meta :e)))))))