Skip to content

Commit d863fd7

Browse files
authored
test var? (#751)
* test `var?` * nix cruft
1 parent 69a2aad commit d863fd7

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
(ns clojure.core-test.var-qmark
2+
(:require clojure.core
3+
[clojure.test :as t :refer [deftest testing is are]]
4+
[clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]]))
5+
6+
(def foo :foo)
7+
8+
(def ^:dynamic i-am-dynamic 3.14)
9+
10+
(when-var-exists clojure.core/defmulti
11+
;; This can't be inside `deftest` like `defn` because `defmulti` only returns
12+
;; the var on the first invocation.
13+
(defmulti bar first))
14+
15+
(when-var-exists clojure.core/defprotocol
16+
(defprotocol MyProtocol))
17+
18+
(when-var-exists clojure.core/var?
19+
(deftest test-var?
20+
(testing "things which are vars"
21+
(are [v] (var? v)
22+
#'foo ; locally-defined
23+
#'var? ; clojure.core
24+
#'i-am-dynamic ; dynamic & local
25+
#'*assert* ; dynamic
26+
#?@(; CLJS `def` doesn't necessarily evaluate to the value of the var:
27+
:cljs [],
28+
:default [(def baz)])
29+
#?@(; CLJS `defn` produces a non-var
30+
:cljs [],
31+
:default [(defn qux [] nil)]))
32+
33+
(when-var-exists clojure.core/defmulti
34+
(is (var? #'bar)))
35+
36+
(when-var-exists clojure.core/defprotocol
37+
(is (var? #'MyProtocol))))
38+
39+
(testing "var-adjacent things"
40+
(are [not-a-var] (not (var? not-a-var))
41+
foo
42+
var?
43+
i-am-dynamic
44+
'foo
45+
'var?
46+
'i-am-dynamic
47+
*assert*
48+
#(+ 1 %)
49+
(fn baz [x] x)))
50+
51+
(testing "things which are clearly not vars"
52+
(are [v] (not (var? v))
53+
'sym
54+
`sym
55+
"abc"
56+
999
57+
1.2
58+
#?@(:cljs [], ; most Clojure dialects support ratios - not CLJS
59+
:default [2/3])
60+
\backspace
61+
nil
62+
true
63+
false
64+
:keyword
65+
:namespace/keyword
66+
'(one two three)
67+
[4 5 6]
68+
{:7 "8"}
69+
(zipmap (take 100 (range))
70+
(cycle ['foo 'bar 'baz 'qux]))
71+
#{:a :b "c"}))))

0 commit comments

Comments
 (0)