aboutsummaryrefslogtreecommitdiff
path: root/src/clojure/contrib/test_contrib
diff options
context:
space:
mode:
authorStuart Halloway <stu@thinkrelevance.com>2009-08-23 12:22:49 -0400
committerStuart Halloway <stu@thinkrelevance.com>2009-08-23 12:22:49 -0400
commit6b763062af9568c1b069d5f86c8d5481a3fdfeea (patch)
treef83f33e12cd5eb07244563eb5ccd2d08c4db8eb1 /src/clojure/contrib/test_contrib
parent07eef46b22f27a61784c11be03ff0159fac50b38 (diff)
parent835bfe2a02c70c150f2354f8ef9e866f3e2fd180 (diff)
Merge branch 'master' of git@github.com:richhickey/clojure-contrib
Diffstat (limited to 'src/clojure/contrib/test_contrib')
-rw-r--r--src/clojure/contrib/test_contrib/java_utils.clj10
-rw-r--r--src/clojure/contrib/test_contrib/str_utils2.clj83
2 files changed, 89 insertions, 4 deletions
diff --git a/src/clojure/contrib/test_contrib/java_utils.clj b/src/clojure/contrib/test_contrib/java_utils.clj
new file mode 100644
index 00000000..44901ad1
--- /dev/null
+++ b/src/clojure/contrib/test_contrib/java_utils.clj
@@ -0,0 +1,10 @@
+(ns clojure.contrib.test-contrib.java-utils
+ (:use clojure.test clojure.contrib.java-utils))
+
+(deftest t-as-str
+ (is (= "foo" (as-str "foo")))
+ (is (= "foo" (as-str 'foo)))
+ (is (= "foo" (as-str :foo)))
+ (is (= "[1 2 3]" (as-str [1 2 3])))
+ (is (= "Hello, World!" (as-str "Hello, " :World \!)))
+ (is (= (str {:foo :bar}) (as-str {:foo :bar}))))
diff --git a/src/clojure/contrib/test_contrib/str_utils2.clj b/src/clojure/contrib/test_contrib/str_utils2.clj
index dac0893a..ee6aa68e 100644
--- a/src/clojure/contrib/test_contrib/str_utils2.clj
+++ b/src/clojure/contrib/test_contrib/str_utils2.clj
@@ -2,6 +2,18 @@
(:require [clojure.contrib.str-utils2 :as s])
(:use clojure.test))
+(deftest t-codepoints
+ (is (= (list 102 111 111 65536 98 97 114)
+ (s/codepoints "foo\uD800\uDC00bar"))
+ "Handles Unicode supplementary characters"))
+
+(deftest t-escape
+ (is (= "&lt;foo&amp;bar&gt;"
+ (s/escape "<foo&bar>" {\& "&amp;" \< "&lt;" \> "&gt;"})))
+ (is (= " \\\"foo\\\" "
+ (s/escape " \"foo\" " {\" "\\\""})))
+ (is (= "faabor" (s/escape "foobar" {\a \o, \o \a}))))
+
(deftest t-blank
(is (s/blank? nil))
(is (s/blank? ""))
@@ -29,6 +41,12 @@
(is (= "foobar" (s/tail "foobar" 9)))
(is (= "" (s/tail "foobar" 0))))
+(deftest t-repeat
+ (is (= "foofoofoo" (s/repeat "foo" 3))))
+
+(deftest t-reverse
+ (is (= "tab" (s/reverse "bat"))))
+
(deftest t-replace
(is (= "faabar" (s/replace "foobar" \o \a)))
(is (= "barbarbar" (s/replace "foobarfoo" "foo" "bar")))
@@ -38,7 +56,64 @@
(is (= "barbarfoo" (s/replace-first "foobarfoo" #"foo" "bar")))
(is (= "FOObarfoo" (s/replace-first "foobarfoo" #"foo" s/upper-case))))
-(deftest t-codepoints
- (is (= (list 102 111 111 65536 98 97 114)
- (s/codepoints "foo\uD800\uDC00bar"))
- "Handles Unicode supplementary characters")))
+(deftest t-partition
+ (is (= (list "" "abc" "123" "def")
+ (s/partition "abc123def" #"[a-z]+"))))
+
+(deftest t-join
+ (is (= "1,2,3" (s/join \, [1 2 3])))
+ (is (= "" (s/join \, [])))
+ (is (= "1 and-a 2 and-a 3" (s/join " and-a " [1 2 3]))))
+
+(deftest t-chop
+ (is (= "fo" (s/chop "foo")))
+ (is (= "") (s/chop "f"))
+ (is (= "") (s/chop "")))
+
+(deftest t-chomp
+ (is (= "foo" (s/chomp "foo\n")))
+ (is (= "foo" (s/chomp "foo\r\n")))
+ (is (= "foo" (s/chomp "foo")))
+ (is (= "" (s/chomp ""))))
+
+(deftest t-swap-case
+ (is (= "fOO!bAR" (s/swap-case "Foo!Bar")))
+ (is (= "" (s/swap-case ""))))
+
+(deftest t-capitalize
+ (is (= "Foobar" (s/capitalize "foobar")))
+ (is (= "Foobar" (s/capitalize "FOOBAR"))))
+
+(deftest t-ltrim
+ (is (= "foo " (s/ltrim " foo ")))
+ (is (= "" (s/ltrim " "))))
+
+(deftest t-rtrim
+ (is (= " foo" (s/rtrim " foo ")))
+ (is (= "" (s/rtrim " "))))
+
+(deftest t-split-lines
+ (is (= (list "one" "two" "three")
+ (s/split-lines "one\ntwo\r\nthree")))
+ (is (= (list "foo") (s/split-lines "foo"))))
+
+(deftest t-upper-case
+ (is (= "FOOBAR" (s/upper-case "Foobar"))))
+
+(deftest t-lower-case
+ (is (= "foobar" (s/lower-case "FooBar"))))
+
+(deftest t-trim
+ (is (= "foo" (s/trim " foo \r\n"))))
+
+(deftest t-contains
+ (is (s/contains? "foobar" "foo"))
+ (is (not (s/contains? "foobar" "baz"))))
+
+(deftest t-get
+ (is (= \o (s/get "foo" 1))))
+
+(deftest t-partial
+ (is (= "bar" ((s/partial s/drop 3) "foobar")))
+ (is (= "ooba" ((comp (s/partial s/take 4)
+ (s/partial s/drop 1)) "foobar"))))