From 051ff8ab5d3e4026ceb90926e33409f7e365a713 Mon Sep 17 00:00:00 2001 From: rafonsecad Date: Fri, 13 Jun 2025 15:24:39 -0500 Subject: [PATCH 1/3] Add tests for ffirst, fnext, last, nfirst, and nnext --- test/clojure/core_test/ffirst.cljc | 31 +++++++++++++++++++++++++++++ test/clojure/core_test/fnext.cljc | 32 ++++++++++++++++++++++++++++++ test/clojure/core_test/last.cljc | 24 ++++++++++++++++++++++ test/clojure/core_test/nfirst.cljc | 32 ++++++++++++++++++++++++++++++ test/clojure/core_test/nnext.cljc | 16 +++++++++++++++ 5 files changed, 135 insertions(+) create mode 100644 test/clojure/core_test/ffirst.cljc create mode 100644 test/clojure/core_test/fnext.cljc create mode 100644 test/clojure/core_test/last.cljc create mode 100644 test/clojure/core_test/nfirst.cljc create mode 100644 test/clojure/core_test/nnext.cljc diff --git a/test/clojure/core_test/ffirst.cljc b/test/clojure/core_test/ffirst.cljc new file mode 100644 index 0000000..7d11589 --- /dev/null +++ b/test/clojure/core_test/ffirst.cljc @@ -0,0 +1,31 @@ +(ns clojure.core-test.ffirst + (:require clojure.core + [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) + +(when-var-exists clojure.core/ffirst + (deftest test-ffirst + (testing "common" + (is (= nil (ffirst '()))) + (is (= nil (ffirst []))) + (is (= nil (ffirst {}))) + (is (= nil (ffirst #{}))) + (is (= nil (ffirst nil))) + (is (= :a (ffirst {:a :b}))) + (is (= 0 (ffirst [[0 1] [2 3]]))) + (is (= 0 (ffirst '([0 1] [2 3])))) + (is (= \a (ffirst ["ab" "cd"]))) + (is (= \a (ffirst ["abcd"]))) + (is (= \a (ffirst #{"abcd"})))) + + (testing "exceptions" + #?@(:clj + [(is (thrown? Exception (ffirst (range 0 10)))) + (is (thrown? Exception (ffirst (range)))) ; infinite lazy seq + (is (thrown? Exception (ffirst [:a :b :c]))) + (is (thrown? Exception (ffirst '(:a :b :c))))] + :cljs + [(is (thrown? js/Error (ffirst (range 0 10)))) + (is (thrown? js/Error (ffirst (range)))) ; infinite lazy seq + (is (thrown? js/Error (ffirst [:a :b :c]))) + (is (thrown? js/Error (ffirst '(:a :b :c))))])))) diff --git a/test/clojure/core_test/fnext.cljc b/test/clojure/core_test/fnext.cljc new file mode 100644 index 0000000..b2dbc6b --- /dev/null +++ b/test/clojure/core_test/fnext.cljc @@ -0,0 +1,32 @@ +(ns clojure.core-test.fnext + (:require clojure.core + [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) + +(when-var-exists clojure.core/fnext + (deftest test-fnext + (testing "section name" + (is (= nil (fnext '()))) + (is (= nil (fnext []))) + (is (= nil (fnext {}))) + (is (= nil (fnext #{}))) + (is (= nil (fnext nil))) + (is (= nil (fnext ""))) + (is (= nil (fnext "a"))) + (is (= nil (fnext {:a :b}))) + (is (= :b (fnext [:a :b]))) + (is (= 1 (fnext (range 0 10)))) + (is (= 1 (fnext (range)))) ; infinite lazy seq + (is (= [2 3] (fnext [[0 1] [2 3]]))) + (is (= '(2 3) (fnext '([0 1] [2 3])))) + (is (= \b (fnext "abcd"))) + (is (= "cd" (fnext ["ab" "cd"]))) + (is (= nil (fnext ["abcd"]))) + (is (= nil (fnext #{"abcd"})))) + + (testing "exceptions" + #?@(:clj + [(is (thrown? Exception (fnext 0))) + (is (thrown? Exception (fnext \a )))] + :cljs + [(is (thrown? js/Error (fnext 0)))])))) diff --git a/test/clojure/core_test/last.cljc b/test/clojure/core_test/last.cljc new file mode 100644 index 0000000..82f278a --- /dev/null +++ b/test/clojure/core_test/last.cljc @@ -0,0 +1,24 @@ +(ns clojure.core-test.last + (:require clojure.core + [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) + +(when-var-exists clojure.core/last + (deftest test-last + (testing "common" + (is (= 9 (last (range 0 10)))) + (is (= :c (last [:a :b :c]))) + (is (= :c (last '(:a :b :c)))) + (is (= \d (last "abcd"))) + (is (= \a (last "a"))) + (is (= nil (last '()))) + (is (= nil (last []))) + (is (= nil (last #{}))) + (is (= nil (last nil)))) + + (testing "exceptions" + #?@(:clj + [(is (thrown? Exception (last \a))) + (is (thrown? Exception (last 0)))] + :cljs + [(is (thrown? js/Error (last 0)))])))) diff --git a/test/clojure/core_test/nfirst.cljc b/test/clojure/core_test/nfirst.cljc new file mode 100644 index 0000000..107dc05 --- /dev/null +++ b/test/clojure/core_test/nfirst.cljc @@ -0,0 +1,32 @@ +(ns clojure.core-test.nfirst + (:require clojure.core + [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) + +(when-var-exists clojure.core/nfirst + (deftest test-nfirst + (testing "common" + (is (= nil (nfirst '()))) + (is (= nil (nfirst []))) + (is (= nil (nfirst {}))) + (is (= nil (nfirst #{}))) + (is (= nil (nfirst nil))) + (is (= nil (nfirst ""))) + (is (= '(:b) (nfirst {:a :b}))) + (is (= '(1) (nfirst [[0 1] [2 3]]))) + (is (= '(1) (nfirst '([0 1] [2 3])))) + (is (= '(\b) (nfirst ["ab" "cd"]))) + (is (= '(\b \c \d) (nfirst ["abcd"]))) + (is (= '(\b \c \d) (nfirst #{"abcd"})))) + + (testing "exceptions" + #?@(:clj + [(is (thrown? Exception (nfirst (range 0 10)))) + (is (thrown? Exception (nfirst (range)))) ; infinite lazy seq + (is (thrown? Exception (nfirst [:a :b :c]))) + (is (thrown? Exception (nfirst '(:a :b :c))))] + :cljs + [(is (thrown? js/Error (nfirst (range 0 10)))) + (is (thrown? js/Error (nfirst (range)))) ; infinite lazy seq + (is (thrown? js/Error (nfirst [:a :b :c]))) + (is (thrown? js/Error (nfirst '(:a :b :c))))])))) diff --git a/test/clojure/core_test/nnext.cljc b/test/clojure/core_test/nnext.cljc new file mode 100644 index 0000000..d6b65de --- /dev/null +++ b/test/clojure/core_test/nnext.cljc @@ -0,0 +1,16 @@ +(ns clojure.core-test.nnext + (:require clojure.core + [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) + +(when-var-exists clojure.core/nnext + (deftest test-nnext + (testing "common" + (is (= '(2 3 4 5 6 7 8 9) (nnext (range 0 10)))) + (is (= 2 (first (nnext (range))))) ; infinite lazy seq + (is (= '(3) (nnext [1 2 3]))) + (is (= '([:c 3] [:d 4]) (nnext {:a 1, :b 2, :c 3, :d 4}))) + (is (nil? (next nil))) + (is (nil? (next '()))) + (is (nil? (next []))) + (is (nil? (next #{})))))) From 8137dfa50ec9fea280731ea11d335028db3000d8 Mon Sep 17 00:00:00 2001 From: rafonsecad Date: Fri, 13 Jun 2025 15:27:19 -0500 Subject: [PATCH 2/3] Add tests for ffirst, fnext, last, nfirst, and nnext --- test/clojure/core_test/nnext.cljc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/clojure/core_test/nnext.cljc b/test/clojure/core_test/nnext.cljc index d6b65de..e6773aa 100644 --- a/test/clojure/core_test/nnext.cljc +++ b/test/clojure/core_test/nnext.cljc @@ -10,7 +10,7 @@ (is (= 2 (first (nnext (range))))) ; infinite lazy seq (is (= '(3) (nnext [1 2 3]))) (is (= '([:c 3] [:d 4]) (nnext {:a 1, :b 2, :c 3, :d 4}))) - (is (nil? (next nil))) - (is (nil? (next '()))) - (is (nil? (next []))) - (is (nil? (next #{})))))) + (is (nil? (nnext nil))) + (is (nil? (nnext '()))) + (is (nil? (nnext []))) + (is (nil? (nnext #{})))))) From d8759caba7809e8960dea7e307c1376c7297d6b5 Mon Sep 17 00:00:00 2001 From: rafonsecad Date: Fri, 13 Jun 2025 17:17:38 -0500 Subject: [PATCH 3/3] Add tests for ffirst, fnext, last, nfirst, and nnext --- test/clojure/core_test/ffirst.cljc | 2 ++ test/clojure/core_test/nfirst.cljc | 1 + 2 files changed, 3 insertions(+) diff --git a/test/clojure/core_test/ffirst.cljc b/test/clojure/core_test/ffirst.cljc index 7d11589..d24904a 100644 --- a/test/clojure/core_test/ffirst.cljc +++ b/test/clojure/core_test/ffirst.cljc @@ -14,6 +14,8 @@ (is (= :a (ffirst {:a :b}))) (is (= 0 (ffirst [[0 1] [2 3]]))) (is (= 0 (ffirst '([0 1] [2 3])))) + (is (= 0 (ffirst (repeat (range))))) + (is (= 0 (ffirst [(range)]))) (is (= \a (ffirst ["ab" "cd"]))) (is (= \a (ffirst ["abcd"]))) (is (= \a (ffirst #{"abcd"})))) diff --git a/test/clojure/core_test/nfirst.cljc b/test/clojure/core_test/nfirst.cljc index 107dc05..2d43773 100644 --- a/test/clojure/core_test/nfirst.cljc +++ b/test/clojure/core_test/nfirst.cljc @@ -15,6 +15,7 @@ (is (= '(:b) (nfirst {:a :b}))) (is (= '(1) (nfirst [[0 1] [2 3]]))) (is (= '(1) (nfirst '([0 1] [2 3])))) + (is (= '(1 2 3 4) (nfirst (repeat (range 0 5))))) (is (= '(\b) (nfirst ["ab" "cd"]))) (is (= '(\b \c \d) (nfirst ["abcd"]))) (is (= '(\b \c \d) (nfirst #{"abcd"}))))