forked from richhickey/clojure
/
metadata.clj
76 lines (68 loc) · 2.3 KB
/
metadata.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
; Copyright (c) Rich Hickey. 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.
; Authors: Stuart Halloway, Frantisek Sodomka
(ns clojure.test-clojure.metadata
(:use clojure.test
[clojure.test-clojure.helpers :only (eval-in-temp-ns)]))
(def public-namespaces
'[clojure.core
clojure.pprint
clojure.inspector
clojure.set
clojure.stacktrace
clojure.test
clojure.walk
clojure.xml
clojure.zip
clojure.java.io
clojure.java.browse
clojure.java.javadoc
clojure.java.shell
clojure.string])
(doseq [ns public-namespaces]
(require ns))
(def public-vars
(mapcat #(vals (ns-publics %)) public-namespaces))
(def public-vars-with-docstrings
(filter (comp :doc meta) public-vars))
(deftest public-vars-with-docstrings-have-added
(is (= [] (remove (comp :added meta) public-vars-with-docstrings))))
(deftest interaction-of-def-with-metadata
(testing "initial def sets metadata"
(let [v (eval-in-temp-ns
(def ^{:a 1} foo 0)
#'foo)]
(is (= 1 (-> v meta :a)))))
(testing "subsequent declare doesn't overwrite metadata"
(let [v (eval-in-temp-ns
(def ^{:b 2} bar 0)
(declare bar)
#'bar)]
(is (= 2 (-> v meta :b))))
(testing "when compiled"
(let [v (eval-in-temp-ns
(def ^{:c 3} bar 0)
(defn declare-bar []
(declare bar))
(declare-bar)
#'bar)]
(is (= 3 (-> v meta :c))))))
(testing "subsequent def with init-expr *does* overwrite metadata"
(let [v (eval-in-temp-ns
(def ^{:d 4} quux 0)
(def quux 1)
#'quux)]
(is (nil? (-> v meta :d))))
(testing "when compiled"
(let [v (eval-in-temp-ns
(def ^{:e 5} quux 0)
(defn def-quux []
(def quux 1))
(def-quux)
#'quux)]
(is (nil? (-> v meta :e)))))))