From 831dab044cf7b2a9f99333dae40fd2e912245296 Mon Sep 17 00:00:00 2001 From: Chris Badahdah Date: Sun, 18 Oct 2026 12:27:30 -0700 Subject: [PATCH 1/4] Add `clojure.string-test.split` --- test/clojure/string_test/split.cljc | 94 +++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 test/clojure/string_test/split.cljc diff --git a/test/clojure/string_test/split.cljc b/test/clojure/string_test/split.cljc new file mode 100644 index 00000000..38cfb68c --- /dev/null +++ b/test/clojure/string_test/split.cljc @@ -0,0 +1,94 @@ +(ns clojure.string-test.split + (:require [clojure.string :as str] + [clojure.test :as t :refer [deftest testing is]] + [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists] :as p])) + +(when-var-exists str/split + (deftest test-split + (testing "basic input" + (is (= [] (str/split "a" #"a"))) + (is (= ["" " "] (str/split "a " #"a"))) + (is (= [" "] (str/split " a" #"a"))) + (is (= [" " " "] (str/split " a " #"a"))) + (is (= ["a"] (str/split "a" #"b")))) + + (testing "positive limit" + (is (= [""] (str/split "" #"" 1))) + (is (= ["aaaaaaaaaa"] (str/split "aaaaaaaaaa" #"" 1)))) + + (testing "negative limit" + (is (= ["a" "" ""] + (str/split "a\n\n" #"\n" -1)))) + + #?(:cljs + (testing "dialect quirks - cljs" + (testing "basic input" + (is (= [] (str/split "" #""))) + (is (= ["" "a"] (str/split "a" #"")))) + (testing "positive limit" + (is (= ["" ""] (str/split "" #"" 10))) + (is (= ["" "a" "a" "a" "a" "a" "a" "a" "a" "aa"] + (str/split "aaaaaaaaaa" #"" 10))))) + + :default + (testing "dialect quirks - default" + (testing "basic input" + (is (= [""] (str/split "" #""))) + (is (= ["a"] (str/split "a" #"")))) + (testing "positive limit" + (is (= [""] (str/split "" #"" 10))) + (is (= ["a" "a" "a" "a" "a" "a" "a" "a" "a" "a"] + (str/split "aaaaaaaaaa" #"" 10)))))) + + (testing "Examples from https://clojuredocs.org/clojure.string/split" + (is (= ["Clojure" "is" "awesome!"] + (str/split "Clojure is awesome!" #" "))) + + (is (= ["q" "w" "e" "r" "t" "y" "u" "i" "o" "p"] + (str/split "q1w2e3r4t5y6u7i8o9p0" #"\d+"))) + (is (= ["q" "w" "e" "r" "t5y6u7i8o9p0"] + (str/split "q1w2e3r4t5y6u7i8o9p0" #"\d+" 5))) + (is (= #?(:cljs ["" " " "q" "1" "w" "2" " "] + :default [" " "q" "1" "w" "2" " "]) + (str/split " q1w2 " #""))) + + (is (= [" something and " "A" "Camel" "Name "] + (str/split " something and ACamelName " #"(?=[A-Z])"))) + + (is (= ["a"] (str/split "a" #"b"))) + (is (= [" "] (str/split " " #"b"))) + (is (= [""] (str/split "" #"b"))) + (is (= [] (str/split "a" #"a"))) + (is (= [] (str/split "aaa" #"a"))) + (is (= #?(:cljs [] :default [""]) (str/split "" #""))) + + (is (= ["Some" "words" "to" "split"] + (str/split "Some words to split" #"\s+"))) + + (is (= ["Some" "words" "with" "other" "whitespace"] + (str/split "Some words with\tother whitespace \n" #"\s+"))) + + (is (= ["" "Leading" "whitespace" "causes" "empty" "first" "string"] + (str/split " Leading whitespace causes empty first string" #"\s+"))) + + (is (= ["root" "*" "0" "0" "admin" "/var/root" "/bin/sh"] + (str/split "root:*:0:0:admin:/var/root:/bin/sh" #":"))) + (is (= ["root" "" "0" "0" "" "/var/root" "/bin/sh"] + (str/split "root::0:0::/var/root:/bin/sh" #":"))) + (is (= ["root" "" "0" "0" "admin" "/var/root"] + (str/split "root::0:0:admin:/var/root:" #":"))) + (is (= ["root" "" "0" "0" "admin"] + (str/split "root::0:0:admin::" #":"))) + (is (= ["root" "" "0" "0" "admin" "/var/root" ""] + (str/split "root::0:0:admin:/var/root:" #":" -1))) + (is (= ["root" "" "0" "0" "admin" "" ""] + (str/split "root::0:0:admin::" #":" -1))) + + (is (= ["root" ":0:0:admin:/var/root:"] + (str/split "root::0:0:admin:/var/root:" #":" 2))) + (is (= ["root" "" "0:0:admin:/var/root:"] + (str/split "root::0:0:admin:/var/root:" #":" 3))) + (is (= ["root" "" "0" "0:admin:/var/root:"] + (str/split "root::0:0:admin:/var/root:" #":" 4))) + (is (= ["root" "" "0" "0" "admin" "/var/root" ""] + (str/split "root::0:0:admin:/var/root:" #":" 15)))))) \ No newline at end of file From 8bb0f585d974aacaf2ad470458ed4f26656d36ee Mon Sep 17 00:00:00 2001 From: Chris Badahdah Date: Sun, 18 Oct 2026 12:56:37 -0700 Subject: [PATCH 2/4] Address CLR quirks --- test/clojure/string_test/split.cljc | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/test/clojure/string_test/split.cljc b/test/clojure/string_test/split.cljc index 38cfb68c..00336ece 100644 --- a/test/clojure/string_test/split.cljc +++ b/test/clojure/string_test/split.cljc @@ -30,6 +30,16 @@ (is (= ["" "a" "a" "a" "a" "a" "a" "a" "a" "aa"] (str/split "aaaaaaaaaa" #"" 10))))) + :cljr + (testing "dialect quirks - default" + (testing "basic input" + (is (= [] (str/split "" #""))) + (is (= ["" "a"] (str/split "a" #"")))) + (testing "positive limit" + (is (= ["" ""] (str/split "" #"" 10))) + (is (= ["" "a" "a" "a" "a" "a" "a" "a" "a" "aa"] + (str/split "aaaaaaaaaa" #"" 10))))) + :default (testing "dialect quirks - default" (testing "basic input" @@ -49,6 +59,7 @@ (is (= ["q" "w" "e" "r" "t5y6u7i8o9p0"] (str/split "q1w2e3r4t5y6u7i8o9p0" #"\d+" 5))) (is (= #?(:cljs ["" " " "q" "1" "w" "2" " "] + :cljr ["" " " "q" "1" "w" "2" " "] :default [" " "q" "1" "w" "2" " "]) (str/split " q1w2 " #""))) @@ -57,10 +68,10 @@ (is (= ["a"] (str/split "a" #"b"))) (is (= [" "] (str/split " " #"b"))) - (is (= [""] (str/split "" #"b"))) + (is (= #?(:cljr [] :default [""]) (str/split "" #"b"))) (is (= [] (str/split "a" #"a"))) (is (= [] (str/split "aaa" #"a"))) - (is (= #?(:cljs [] :default [""]) (str/split "" #""))) + (is (= #?(:cljs [] :cljr [] :default [""]) (str/split "" #""))) (is (= ["Some" "words" "to" "split"] (str/split "Some words to split" #"\s+"))) From e052f41bf5ae15fb2e4c29c33b90bf59507bbee9 Mon Sep 17 00:00:00 2001 From: Chris Badahdah Date: Sun, 25 Oct 2026 13:16:06 -0700 Subject: [PATCH 3/4] Add more examples --- test/clojure/string_test/split.cljc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/clojure/string_test/split.cljc b/test/clojure/string_test/split.cljc index 00336ece..b0bcc969 100644 --- a/test/clojure/string_test/split.cljc +++ b/test/clojure/string_test/split.cljc @@ -14,6 +14,8 @@ (testing "positive limit" (is (= [""] (str/split "" #"" 1))) + (is (= ["a"] (str/split "a" #"a" 1))) + (is (= ["" ""] (str/split "a" #"a" 2))) (is (= ["aaaaaaaaaa"] (str/split "aaaaaaaaaa" #"" 1)))) (testing "negative limit" @@ -31,7 +33,7 @@ (str/split "aaaaaaaaaa" #"" 10))))) :cljr - (testing "dialect quirks - default" + (testing "dialect quirks - cljr" (testing "basic input" (is (= [] (str/split "" #""))) (is (= ["" "a"] (str/split "a" #"")))) From f4053739acbceb52cbe230786e25c5d0b603b83b Mon Sep 17 00:00:00 2001 From: Chris Badahdah Date: Mon, 26 Oct 2026 12:23:32 -0700 Subject: [PATCH 4/4] Add more examples --- test/clojure/string_test/split.cljc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/clojure/string_test/split.cljc b/test/clojure/string_test/split.cljc index b0bcc969..dbe606e0 100644 --- a/test/clojure/string_test/split.cljc +++ b/test/clojure/string_test/split.cljc @@ -20,7 +20,11 @@ (testing "negative limit" (is (= ["a" "" ""] - (str/split "a\n\n" #"\n" -1)))) + (str/split "a\n\n" #"\n" -1))) + (is (= ["a" "" ""] + (str/split "a\n\n" #"\n" -10))) + (is (= ["a" "" ""] + (str/split "a\n\n" #"\n" -100)))) #?(:cljs (testing "dialect quirks - cljs"