Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions test/clojure/core_test/var_qmark.cljc
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
(ns clojure.core-test.var-qmark
(:require clojure.core
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think requiring clojure.core is redundant

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's auto-generated by bb new-test

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Emma, I agree this is very odd. Want to update the template and then patch the existing test files?

[clojure.test :as t :refer [deftest testing is are]]
[clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]]))

(def foo :foo)

(def ^:dynamic i-am-dynamic 3.14)

(when-var-exists clojure.core/defmulti
;; This can't be inside `deftest` like `defn` because `defmulti` only returns
;; the var on the first invocation.
(defmulti bar first))

(when-var-exists clojure.core/defprotocol
(defprotocol MyProtocol))

(when-var-exists clojure.core/var?
(deftest test-var?
(testing "things which are vars"
(are [v] (var? v)
#'foo ; locally-defined
#'var? ; clojure.core
#'i-am-dynamic ; dynamic & local
#'*assert* ; dynamic
#?@(; CLJS `def` doesn't necessarily evaluate to the value of the var:
:cljs [],
:default [(def baz)])
#?@(; CLJS `defn` produces a non-var
:cljs [],
:default [(defn qux [] nil)]))

(when-var-exists clojure.core/defmulti
(is (var? #'bar)))

(when-var-exists clojure.core/defprotocol
(is (var? #'MyProtocol))))

(testing "var-adjacent things"
(are [not-a-var] (not (var? not-a-var))
foo
var?
i-am-dynamic
'foo
'var?
'i-am-dynamic
*assert*
#(+ 1 %)
(fn baz [x] x)))

(testing "things which are clearly not vars"
(are [v] (not (var? v))
'sym
`sym
"abc"
999
1.2
#?@(:cljs [], ; most Clojure dialects support ratios - not CLJS
:default [2/3])
\backspace
nil
true
false
:keyword
:namespace/keyword
'(one two three)
[4 5 6]
{:7 "8"}
(zipmap (take 100 (range))
(cycle ['foo 'bar 'baz 'qux]))
#{:a :b "c"}))))