From f6a03a3d6eee64be417206d419b3017b09c5ddfd Mon Sep 17 00:00:00 2001 From: dnolen Date: Wed, 19 Oct 2016 13:51:39 -0400 Subject: [PATCH] make String an implicit ns like Math. revert char? and clarify docstring. add unit tests for char? --- src/main/cljs/cljs/core.cljs | 4 ++-- src/main/clojure/cljs/analyzer.cljc | 2 +- src/test/cljs/cljs/primitives_test.cljs | 12 +++++++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/cljs/cljs/core.cljs b/src/main/cljs/cljs/core.cljs index df2fcf30b7..2f93996890 100644 --- a/src/main/cljs/cljs/core.cljs +++ b/src/main/cljs/cljs/core.cljs @@ -229,9 +229,9 @@ (goog/isString x)) (defn ^boolean char? - "Returns true if x is a JavaScript char." + "Returns true if x is a JavaScript string of length one." [x] - (gstring/isUnicodeChar x)) + (and (string? x) (== 1 (.-length x)))) (defn ^boolean any? "Returns true if given any argument." diff --git a/src/main/clojure/cljs/analyzer.cljc b/src/main/clojure/cljs/analyzer.cljc index bf9dd5f8b9..982a6c7f8f 100644 --- a/src/main/clojure/cljs/analyzer.cljc +++ b/src/main/clojure/cljs/analyzer.cljc @@ -648,7 +648,7 @@ (throw (error ~env (.getMessage err#) err#))))))) ;; namespaces implicit to the inclusion of cljs.core -(def implicit-nses '#{goog goog.object goog.string goog.array Math}) +(def implicit-nses '#{goog goog.object goog.string goog.array Math String}) (defn implicit-import? #?(:cljs {:tag boolean}) diff --git a/src/test/cljs/cljs/primitives_test.cljs b/src/test/cljs/cljs/primitives_test.cljs index b0d8083d09..7233288d84 100644 --- a/src/test/cljs/cljs/primitives_test.cljs +++ b/src/test/cljs/cljs/primitives_test.cljs @@ -950,4 +950,14 @@ (is (= 1 (do #js {:a 1} 1))) (is (= 1 (aget #js {:a 1} "a"))) - (is (= 1 (.-a #js {:a 1}))))) \ No newline at end of file + (is (= 1 (.-a #js {:a 1}))))) + +(deftest test-char? + (is (char? "0")) + (is (char? (String/fromCharCode 13))) + (is (char? (String/fromCharCode 10))) + (is (char? \newline)) + (is (char? \space)) + (is (char? "0")) + (is (char? "\u0080")) + (is (char? "\uFFFD"))) \ No newline at end of file