diff --git a/test/clojure/core_test/subs.cljc b/test/clojure/core_test/subs.cljc index 1c83480..58bc039 100644 --- a/test/clojure/core_test/subs.cljc +++ b/test/clojure/core_test/subs.cljc @@ -4,12 +4,26 @@ (when-var-exists clojure.core/subs (deftest test-subs + (is (= "abcde" (subs "abcde" 0))) + (is (= "abcde" (subs "abcde" 0 5))) + (is (= "ab֎de" (subs "ab֎de" 0))) + (is (= "ab֎de" (subs "ab֎de" 0 5))) (is (= "bcde" (subs "abcde" 1))) + (is (= "bcde" (subs "֎bcde" 1))) (is (= "bcd" (subs "abcde" 1 4))) + (is (= "bcd" (subs "֎bcde" 1 4))) (is (= "abc" (subs "abcde" 0 3))) + (is (= "ab֎" (subs "ab֎de" 0 3))) + (is (= "" (subs "" 0 0))) + (is (= "" (subs "" 0))) (is (= "" (subs "abcde" 0 0))) + (is (= "" (subs "֎bcde" 0 0))) (is (= "" (subs "abcde" 5))) + (is (= "" (subs "abcd֎" 5))) (is (= "" (subs "abcde" 5 5))) + (is (= "" (subs "abcd֎" 5 5))) + (is (= "" (subs "abcde" 4 4))) + (is (= "" (subs "abc֎e" 4 4))) #?@(:cljs [(is (= "b" (subs "abcde" 2 1))) (is (= "bcde" (subs "abcde" 1 6))) diff --git a/test/clojure/string_test/blank_qmark.cljc b/test/clojure/string_test/blank_qmark.cljc new file mode 100644 index 0000000..52f6e25 --- /dev/null +++ b/test/clojure/string_test/blank_qmark.cljc @@ -0,0 +1,28 @@ +(ns clojure.string-test.blank-qmark + (:require [clojure.string :as str] + [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) + +(when-var-exists str/blank? + (deftest test-blank? + (is (true? (str/blank? ""))) + (is (true? (str/blank? nil))) + (is (false? (str/blank? "֎"))) + (testing "U+2007" + (is (#?(:cljs true? :default false?) (str/blank? " "))) + (is (#?(:cljs true? :default false?) (str/blank? "\u2007")))) + (is (true? (str/blank? " "))) + (is (true? (str/blank? " \t "))) + #?(:cljs (do (is (true? (str/blank? (symbol "")))) + (is (false? (str/blank? 'a)))) + :default (is (thrown? #?(:clj Exception) (str/blank? (symbol ""))))) + #?(:cljs (do (is (false? (str/blank? (keyword "")))) + (is (false? (str/blank? :a)))) + :default (is (thrown? #?(:clj Exception) (str/blank? (keyword ""))))) + #?(:cljs (is (false? (str/blank? 1))) + :default (is (thrown? #?(:clj Exception) (str/blank? 1)))) + #?(:cljs (do (is (true? (str/blank? \space))) + (is (false? (str/blank? \a)))) + :default (is (thrown? #?(:clj Exception) (str/blank? \space)))) + (is (false? (str/blank? "nil"))) + (is (false? (str/blank? " as df "))))) diff --git a/test/clojure/string_test/capitalize.cljc b/test/clojure/string_test/capitalize.cljc new file mode 100644 index 0000000..e48d0a4 --- /dev/null +++ b/test/clojure/string_test/capitalize.cljc @@ -0,0 +1,23 @@ +(ns clojure.string-test.capitalize + (:require [clojure.string :as str] + [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) + +(when-var-exists str/capitalize + (deftest test-capitalize + (is (thrown? #?(:cljs :default :clj Exception) (str/capitalize nil))) + #?(:cljs (do (is (thrown? :default (str/capitalize 1))) + (is (thrown? :default (str/capitalize 'a))) + (is (thrown? :default (str/capitalize 'a/a))) + (is (thrown? :default (str/capitalize :a))) + (is (thrown? :default (str/capitalize :a/a)))) + :default (do (is (= "1" (str/capitalize 1))) + (is (= "Asdf" (str/capitalize 'Asdf))) + (is (= "Asdf/asdf" (str/capitalize 'asDf/aSdf))) + (is (= ":asdf/asdf" (str/capitalize :asDf/aSdf))))) + (is (= "" (str/capitalize ""))) + (is (= "A" (str/capitalize "a"))) + (is (= "֎" (str/capitalize "֎"))) + (is (= "A thing" (str/capitalize "a Thing"))) + (is (= "A thing" (str/capitalize "A THING"))) + (is (= "A thing" (str/capitalize "A thing"))))) diff --git a/test/clojure/string_test/ends_with_qmark.cljc b/test/clojure/string_test/ends_with_qmark.cljc new file mode 100644 index 0000000..249c764 --- /dev/null +++ b/test/clojure/string_test/ends_with_qmark.cljc @@ -0,0 +1,26 @@ +(ns clojure.string-test.ends-with-qmark + (:require [clojure.string :as str] + [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) + +(when-var-exists str/ends-with? + (deftest test-ends-with? + (is (true? (str/ends-with? "" ""))) + (is (thrown? #?(:cljs :default :clj Exception) (str/ends-with? "" nil))) + (is (thrown? #?(:cljs :default :clj Exception) (str/ends-with? nil ""))) + #?(:cljs (do (is (false? (str/ends-with? "ab" :b))) + (is (false? (str/ends-with? "ab" :a)))) + :default (is (thrown? #?(:clj Exception) (str/ends-with? "ab" :b)))) + #?(:cljs (is (false? (str/ends-with? "ab" 'b))) + :default (is (thrown? #?(:clj Exception) (str/ends-with? "ab" 'b)))) + (is (#?(:cljs false? :default true?) (str/ends-with? 'ab "b"))) + (is (false? (str/ends-with? 'ab "a"))) + (is (#?(:cljs false? :default true?) (str/ends-with? :ab "b"))) + (is (false? (str/ends-with? :ab "a"))) + (is (false? (str/ends-with? "" "a"))) + (is (true? (str/ends-with? "a-test" ""))) + (is (true? (str/ends-with? "a-test֎" "֎"))) + (is (true? (str/ends-with? "a-test" "t"))) + (is (true? (str/ends-with? "a-test" "a-test"))) + (is (false? (str/ends-with? "a-test" "s"))) + (is (false? (str/ends-with? "a-test" "a"))))) diff --git a/test/clojure/string_test/escape.cljc b/test/clojure/string_test/escape.cljc new file mode 100644 index 0000000..654fc2d --- /dev/null +++ b/test/clojure/string_test/escape.cljc @@ -0,0 +1,17 @@ +(ns clojure.string-test.escape + (:require [clojure.string :as str] + [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) + +(when-var-exists str/escape + (deftest test-escape + (is (= "" (str/escape "" {}))) + (is (= "" (str/escape "" {\c "C_C"}))) + (is (= "A_Abc" (str/escape "abc" {\a "A_A"}))) + (is (= "A_AbC_C" (str/escape "abc" {\a "A_A" \c "C_C"}))) + (is (= "A_AbC_C" (str/escape "abc" {\a "A_A" \c "C_C" (int \a) 1 nil 'junk :garbage 42.42}))) + (is (= "A_AbC_C" (str/escape "abc" {\a "A_A" \c "C_C"}))) + (is (thrown? #?(:cljs :default :clj Exception) (str/escape nil {\a "A_A" \c "C_C"}))) + (is (thrown? #?(:cljs :default :clj Exception) (str/escape 1 {\a "A_A" \c "C_C"}))) + (is (thrown? #?(:cljs :default :clj Exception) (str/escape 'a {\a "A_A" \c "C_C"}))) + (is (thrown? #?(:cljs :default :clj Exception) (str/escape :a {\a "A_A" \c "C_C"}))))) diff --git a/test/clojure/string_test/lower_case.cljc b/test/clojure/string_test/lower_case.cljc new file mode 100644 index 0000000..1f922e2 --- /dev/null +++ b/test/clojure/string_test/lower_case.cljc @@ -0,0 +1,21 @@ +(ns clojure.string-test.lower-case + (:require [clojure.string :as str] + [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) + +(when-var-exists str/lower-case + (deftest test-lower-case + (is (thrown? #?(:cljs :default :clj Exception) (str/lower-case nil))) + (is (= "" (str/lower-case ""))) + (is (= "֎" (str/lower-case "֎"))) + (is (= "asdf" (str/lower-case "AsdF"))) + (is (= "asdf" (str/lower-case "asdf"))) + (let [s "ASDF"] + (is (= "asdf" (str/lower-case "ASDF"))) + (is (= "ASDF" s) "original string mutated")) + #?(:cljs (is (thrown? :default (str/lower-case :ASDF))) + :default (is (= ":asdf" (str/lower-case :ASDF)))) + #?(:cljs (is (thrown? :default (str/lower-case :ASDF/ASDF))) + :default (is (= ":asdf/asdf" (str/lower-case :ASDF/ASDF)))) + #?(:cljs (is (thrown? :default (str/lower-case 'ASDF))) + :default (is (= "asdf" (str/lower-case 'ASDF)))))) diff --git a/test/clojure/string_test/reverse.cljc b/test/clojure/string_test/reverse.cljc new file mode 100644 index 0000000..5b0730a --- /dev/null +++ b/test/clojure/string_test/reverse.cljc @@ -0,0 +1,15 @@ +(ns clojure.string-test.reverse + (:require [clojure.string :as str] + [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) + +(when-var-exists str/reverse + (deftest test-reverse + (is (= "" (str/reverse ""))) + (is (= "֎" (str/reverse "֎"))) + (is (= "a֎" (str/reverse "֎a"))) + (is (= "tset-a" (str/reverse "a-test"))) + (is (thrown? #?(:cljs :default :clj Exception) (str/reverse nil))) + (is (thrown? #?(:cljs :default :clj Exception) (str/reverse 1))) + (is (thrown? #?(:cljs :default :clj Exception) (str/reverse 'a-test))) + (is (thrown? #?(:cljs :default :clj Exception) (str/reverse :a-test))))) diff --git a/test/clojure/string_test/starts_with_qmark.cljc b/test/clojure/string_test/starts_with_qmark.cljc new file mode 100644 index 0000000..2290aaa --- /dev/null +++ b/test/clojure/string_test/starts_with_qmark.cljc @@ -0,0 +1,38 @@ +(ns clojure.string-test.starts-with-qmark + (:require [clojure.string :as str] + [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) + +(when-var-exists str/starts-with? + (deftest test-starts-with? + (is (true? (str/starts-with? "" ""))) + #?(:cljs (is (false? (str/starts-with? "" nil))) + :default (is (thrown? #?(:clj Exception) (str/starts-with? "" nil)))) + (is (thrown? #?(:cljs :default :clj Exception) (str/starts-with? nil ""))) + #?(:cljs (do (is (false? (str/starts-with? "ab" :a))) + (is (true? (str/starts-with? ":ab" :a))) + (is (false? (str/starts-with? "ab" :b)))) + :default (is (thrown? #?(:clj Exception) (str/starts-with? "ab" :a)))) + #?(:cljs (is (true? (str/starts-with? "ab" 'a))) + :default (is (thrown? #?(:clj Exception) (str/starts-with? "a" 'a)))) + (is (false? (str/starts-with? "" "a"))) + (is (true? (str/starts-with? "a-test" ""))) + (is (true? (str/starts-with? "֎a-test" "֎"))) + (is (true? (str/starts-with? "a-test" "a"))) + (is (true? (str/starts-with? "a-test" "a-test"))) + (is (false? (str/starts-with? "a-test" "-"))) + (is (false? (str/starts-with? "a-test" "t"))) + #?(:cljs (is (thrown? :default (str/starts-with? 'ab ":a"))) + :default (do (is (false? (str/starts-with? 'ab "b"))) + (is (true? (str/starts-with? 'ab "a"))))) + #?(:cljs (is (thrown? :default (str/starts-with? :ab ":a"))) + :default (do (is (false? (str/starts-with? :ab "b"))) + (is (false? (str/starts-with? :ab "a"))) + (is (true? (str/starts-with? :ab ":a"))))) + #?(:cljs (is (thrown? :default (str/starts-with? 'a/b ":a"))) + :default (do (is (false? (str/starts-with? 'a/b "b"))) + (is (true? (str/starts-with? 'a/b "a"))))) + #?(:cljs (is (thrown? :default (str/starts-with? :a/b ":a"))) + :default (do (is (false? (str/starts-with? :a/b "b"))) + (is (false? (str/starts-with? :a/b "a"))) + (is (true? (str/starts-with? :a/b ":a"))))))) diff --git a/test/clojure/string_test/upper_case.cljc b/test/clojure/string_test/upper_case.cljc new file mode 100644 index 0000000..6150999 --- /dev/null +++ b/test/clojure/string_test/upper_case.cljc @@ -0,0 +1,23 @@ +(ns clojure.string-test.upper-case + (:require [clojure.string :as str] + [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) + +(when-var-exists str/upper-case + (deftest test-upper-case + (is (thrown? #?(:cljs :default :clj Exception) (str/upper-case nil))) + (is (= "" (str/upper-case ""))) + (is (= "֎" (str/upper-case "֎"))) + (is (= "ASDF" (str/upper-case "aSDf"))) + (is (= "ASDF" (str/upper-case "ASDF"))) + (let [s "asdf"] + (is (= "ASDF" (str/upper-case "asdf"))) + (is (= "asdf" s) "original string mutated")) + #?(:cljs (is (thrown? :default (str/upper-case :asdf))) + :default (is (= ":ASDF" (str/upper-case :asdf)))) + #?(:cljs (is (thrown? :default (str/upper-case :asdf/asdf))) + :default (is (= ":ASDF/ASDF" (str/upper-case :asdf/asdf)))) + #?(:cljs (is (thrown? :default (str/upper-case 'asdf))) + :default (is (= "ASDF" (str/upper-case 'asdf)))) + #?(:cljs (is (thrown? :default (str/upper-case 'asdf/asdf))) + :default (is (= "ASDF/ASDF" (str/upper-case 'asdf/asdf))))))