diff --git a/test/clojure/core_test/when_let.cljc b/test/clojure/core_test/when_let.cljc index ef7e21f9..257b74fa 100644 --- a/test/clojure/core_test/when_let.cljc +++ b/test/clojure/core_test/when_let.cljc @@ -11,6 +11,8 @@ (is (nil? (when-let [x nil] x)))) (testing "basic single-binding tests using seqs" (is (= '(0 1 2 3 4) (when-let [x (range 5)] x)))) + (testing "unlike when-some, we're looking for logical truth, so false doesn't evaluate" + (is (nil? (when-let [x false] x)))) (testing "seq is only called once" (let [calls (atom 0) seq-fn (fn s [] (lazy-seq diff --git a/test/clojure/core_test/when_some.cljc b/test/clojure/core_test/when_some.cljc new file mode 100644 index 00000000..ae1aeff6 --- /dev/null +++ b/test/clojure/core_test/when_some.cljc @@ -0,0 +1,24 @@ + +(ns clojure.core-test.when-some + (:require [clojure.test :as t :refer [deftest is testing]] + [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) + + +(when-var-exists when-some + (deftest test-when-some + (testing "basic single-binding tests using vectors or nil" + (is (= [0 1 2 3 4] (when-some [x [0 1 2 3 4]] x))) + (is (some? (when-some [x [nil]] x))) + (is (= [] (when-some [x []] x)))) + (testing "side effects don't get evaluated" + (let [test-atom (atom nil)] + (is (nil? (when-some [x nil] (reset! test-atom 1) x))) + (is (nil? @test-atom)))) + (testing "basic single-binding tests using seqs" + (is (= '(0 1 2 3 4) (when-some [x (range 5)] x)))) + (testing "unlike when-let, we're looking for not-nil specifically, so false evaluates" + (is (= false (when-some [x false] x)))) + (testing "without a body, truth doesn't matter" + (is (nil? (when-some [x nil]))) + (is (nil? (when-some [x [false]]))) + (is (nil? (when-some [x [true]]))))))