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
34 changes: 34 additions & 0 deletions test/clojure/core_test/fn_qmark.cljc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
(ns clojure.core-test.fn-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.

Requiring clojure.core here should be 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.

No opinion — see b617559 and

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

(defn foo [x] (str "hello " x))

(when-var-exists clojure.core/fn?
(deftest test-fn?
(testing "`fn?`"
(testing "functions, functions from HOFs, transducers, #() reader macro, `fn`, `defn`"
(is (fn? juxt))
(is (fn? (juxt inc dec)))
(is (fn? (map inc)))
(is (fn? #(str "hello " %)))
(is (fn? (fn [x] (str "hello " x))))
(is (fn? foo)))

;; Note: we intentionally do not test multimethods or protocols, because
;; behavior differs across dialects due to implementation decisions that
;; don't matter for our purposes.

(testing "atomic values are not functions"
(is (not (fn? nil)))
(is (not (fn? 12345678)))
(is (not (fn? "string")))
(is (not (fn? :keyword))) ; note: also IFn
(is (not (fn? 'symbol)))
(is (not (fn? \space))))

(testing "implementing IFn is not the same as implementing Fn"
(is (not (fn? {:a :b})))
(is (not (fn? #{:a :b :c})))
(is (not (fn? [:a :b])))))))