forked from clojure-emacs/orchard
/
meta_test.clj
123 lines (109 loc) · 4.41 KB
/
meta_test.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
(ns orchard.meta-test
(:require
[clojure.java.io :as io]
[clojure.test :refer :all]
[orchard.clojuredocs :as docs]
[orchard.meta :as m]))
(deftest merge-meta-test
(testing "Always safe and preserves object"
(are [form] (let [x form]
(= x (m/merge-meta x {:random 'meta})))
0 1 1.0 (float 1) (double 1) 1M 1N 1/2
'symbol :keyword
(atom 10) (delay 10)
[1 2 3] '(1 2 3)
{1 2} #{1 2 3}))
(testing "Applies meta"
(are [form] (-> (m/merge-meta form {:random 'meta})
meta :random (= 'meta))
;; Keywords and numbers have no metadata.
;; Atoms and delays are mutable.
'symbol
[1 2 3] '(1 2 3)
{1 2} #{1 2 3})))
(deftest strip-meta-test
(testing "Always safe and preserves object"
(are [form] (let [x form]
(= x (m/strip-meta (m/merge-meta x {:random 'meta}))))
0 1 1.0 (float 1) (double 1) 1M 1N 1/2
'symbol :keyword
(atom 10) (delay 10)
[1 2 3] '(1 2 3)
{1 2} #{1 2 3}))
(testing "Removes meta"
(are [form] (-> (with-meta form {:random 'meta})
m/strip-meta meta :random not)
;; Keywords and numbers have no metadata.
;; Atoms and delays are mutable.
'symbol
[1 2 3] '(1 2 3)
{1 2} #{1 2 3})))
(defn- test-fn "docstring"
([a b] nil)
([a] nil)
([]))
(defmacro test-macro [& x]
`(do ~@x))
(deftest macroexpand-all-test
(is (->> (m/macroexpand-all '(test-macro ^{:random meta} (hi)))
second
meta
:random
(= 'meta))))
(deftest special-sym-meta-test
(with-redefs [docs/test-remote-url (constantly [true])
docs/cache-file-name "target/clojuredocs/export.edn"
docs/default-edn-file-url (io/resource "clojuredocs/export.edn")]
(testing "Names are correct for `&`, `catch`, `finally`"
(is (= '& (:name (m/special-sym-meta '&))))
(is (= 'catch (:name (m/special-sym-meta 'catch))))
(is (= 'finally (:name (m/special-sym-meta 'finally)))))
(testing ":see-also metadata is attached"
(is (not-empty (:see-also (m/special-sym-meta 'if)))))
(testing "Name is correct for `clojure.core/import*`"
;; Only compiler special to be namespaced
(is (= 'clojure.core/import* (:name (m/special-sym-meta 'clojure.core/import*)))))
(testing "No ns for &, which uses fn's info"
(is (nil? (:ns (m/special-sym-meta '&)))))
(testing "Returns nil for unknown symbol"
(is (nil? (m/special-sym-meta 'unknown))))))
(deftest special-sym-meta-without-see-also-test
(with-redefs [docs/test-remote-url (constantly [false (Exception. "dummy")])
docs/cache-file-name "target/clojuredocs/export.edn"]
(docs/clean-cache!)
(testing "Attaching see-also is skipped"
(is (empty? (:see-also (m/special-sym-meta 'if)))))))
(deftest var-meta-test
(with-redefs [docs/test-remote-url (constantly [true])
docs/cache-file-name "target/clojuredocs/export.edn"
docs/default-edn-file-url (io/resource "clojuredocs/export.edn")]
;; Test files can't be found on the class path.
(is (:file (m/var-meta #'m/var-meta)))
(testing "Includes spec information"
(is (or (contains? (m/var-meta (resolve 'let)) :spec)
(nil? (resolve 'clojure.spec.alpha/spec)))))
(testing "Includes see-also information from clojure docs"
(is (contains? (m/var-meta (resolve 'clojure.set/union)) :see-also)))
(is (re-find #"string\.clj"
(:file (#'m/maybe-add-file
{:ns (find-ns 'clojure.string)}))))
(is (not (re-find #"/form-init[^/]*$"
(:file (m/var-meta
(eval '(do (in-ns 'clojure.string)
(def pok 10))))))))))
(deftest var-meta-without-see-also-test
(with-redefs [docs/test-remote-url (constantly [false (Exception. "dummy")])
docs/cache-file-name "target/clojuredocs/export.edn"]
(docs/clean-cache!)
(testing "Including see-also is skipped"
(is (not (contains? (m/var-meta (resolve 'clojure.set/union)) :see-also))))))
(deftest ns-meta-test
(testing "Includes a non-nil :file"
(is (some-> 'orchard.test-ns-dep
(find-ns)
(m/ns-meta)
:file))
(is (some-> 'orchard.test-no-defs ;; issue #75
(find-ns)
(m/ns-meta)
:file))))