File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 1+ (ns clojure.core-test.when-first
2+ (:require [clojure.test :as t :refer [deftest testing is are]]
3+ [clojure.core-test.portability #?(:cljs :refer-macros :default :refer ) [when-var-exists ]]))
4+
5+
6+ (when-var-exists when-first
7+ (deftest test-when-first
8+ (testing " Basic single-binding tests using vectors or nil"
9+ (is (= 0 (when-first [x [0 1 2 3 4 ] ] x)))
10+ (is (nil? (when-first [x [nil ]] x)))
11+ (is (nil? (when-first [x []] x)))
12+ (is (nil? (when-first [x nil ] x))))
13+ (testing " Basic single-binding tests using seqs"
14+ (is (= 0 (when-first [x (range 5 ) ] x)))
15+ (is (nil? (when-first [x (repeat nil )] x))))
16+ (testing " Seq only called once"
17+ (let [calls (atom 0 )
18+ seq-fn (fn s [] (lazy-seq
19+ (swap! calls inc)
20+ (cons 1 (s ))))
21+ s (seq-fn )]
22+ (is (= 1 (when-first [x s] x)))
23+ (is (= @calls 1 ))))))
You can’t perform that action at this time.
0 commit comments