diff options
author | Stuart Sierra <mail@stuartsierra.com> | 2009-08-18 16:59:49 -0400 |
---|---|---|
committer | Stuart Sierra <mail@stuartsierra.com> | 2009-08-18 16:59:49 -0400 |
commit | c20fbee2d68fdcde18c7001f859d32513cf0bde6 (patch) | |
tree | aef2b0e7343d32d01ce3adcbf5da8194a20478cc | |
parent | 3b6d95140393bf78930c9f4045ba2feab36f3946 (diff) |
str_utils2.clj: fix escape so it actually works, add tests
-rw-r--r-- | src/clojure/contrib/str_utils2.clj | 2 | ||||
-rw-r--r-- | src/clojure/contrib/test_contrib/str_utils2.clj | 9 |
2 files changed, 9 insertions, 2 deletions
diff --git a/src/clojure/contrib/str_utils2.clj b/src/clojure/contrib/str_utils2.clj index ec2741ce..26dd849f 100644 --- a/src/clojure/contrib/str_utils2.clj +++ b/src/clojure/contrib/str_utils2.clj @@ -93,7 +93,7 @@ [#^String s cmap] (let [buffer (StringBuilder. (.length s))] (dochars [c s] - (if-let [r (cmap s)] + (if-let [r (cmap c)] (.append buffer r) (.append buffer c))) (.toString buffer))) diff --git a/src/clojure/contrib/test_contrib/str_utils2.clj b/src/clojure/contrib/test_contrib/str_utils2.clj index dac0893a..4b466774 100644 --- a/src/clojure/contrib/test_contrib/str_utils2.clj +++ b/src/clojure/contrib/test_contrib/str_utils2.clj @@ -41,4 +41,11 @@ (deftest t-codepoints (is (= (list 102 111 111 65536 98 97 114) (s/codepoints "foo\uD800\uDC00bar")) - "Handles Unicode supplementary characters"))) + "Handles Unicode supplementary characters")) + +(deftest t-escape + (is (= "<foo&bar>" + (s/escape "<foo&bar>" {\& "&" \< "<" \> ">"}))) + (is (= " \\\"foo\\\" " + (s/escape " \"foo\" " {\" "\\\""}))) + (is (= "faabor" (s/escape "foobar" {\a \o, \o \a})))) |