From 8e3552b2025829314c942c5b47245026201dc7e9 Mon Sep 17 00:00:00 2001 From: alysbrooks Date: Sat, 21 Feb 2026 22:30:21 -0600 Subject: [PATCH 1/2] Add tests for when-some, plus one for when-let. when-some and when-let behave very similarly. This adds the opposite case of one of these tests to when-let. --- test/clojure/core_test/when_let.cljc | 2 ++ test/clojure/core_test/when_some.cljc | 32 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 test/clojure/core_test/when_some.cljc 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..4bd43e9f --- /dev/null +++ b/test/clojure/core_test/when_some.cljc @@ -0,0 +1,32 @@ + +(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 "seq is only called once" + (let [calls (atom 0) + seq-fn (fn s [] (lazy-seq + (swap! calls inc) + (cons 1 (s)))) + s (take 5 (seq-fn))] + (is (= '(1 1 1 1 1) (when-some [x s] x))) + (is (= @calls 5)))) + (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]])))))) From e22e9d65090e11e0f70a77cd0376cae48512e51d Mon Sep 17 00:00:00 2001 From: alysbrooks Date: Thu, 30 Apr 2026 23:16:17 -0500 Subject: [PATCH 2/2] Remove test for seq only being called once. PR feedback was that this is not in fact testing seq is only called once due to seq returning itself when you call it multiple times so I dropped it. --- test/clojure/core_test/when_some.cljc | 8 -------- 1 file changed, 8 deletions(-) diff --git a/test/clojure/core_test/when_some.cljc b/test/clojure/core_test/when_some.cljc index 4bd43e9f..ae1aeff6 100644 --- a/test/clojure/core_test/when_some.cljc +++ b/test/clojure/core_test/when_some.cljc @@ -18,14 +18,6 @@ (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 "seq is only called once" - (let [calls (atom 0) - seq-fn (fn s [] (lazy-seq - (swap! calls inc) - (cons 1 (s)))) - s (take 5 (seq-fn))] - (is (= '(1 1 1 1 1) (when-some [x s] x))) - (is (= @calls 5)))) (testing "without a body, truth doesn't matter" (is (nil? (when-some [x nil]))) (is (nil? (when-some [x [false]])))