Skip to content

Commit

Permalink
make String an implicit ns like Math. revert char? and clarify docstr…
Browse files Browse the repository at this point in the history
…ing. add unit tests for char?
  • Loading branch information
dnolen committed Oct 19, 2016
1 parent f2ebdd3 commit f6a03a3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/main/cljs/cljs/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
2 changes: 1 addition & 1 deletion src/main/clojure/cljs/analyzer.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
12 changes: 11 additions & 1 deletion src/test/cljs/cljs/primitives_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -950,4 +950,14 @@
(is (= 1 (do #js {:a 1}
1)))
(is (= 1 (aget #js {:a 1} "a")))
(is (= 1 (.-a #js {:a 1})))))
(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")))

0 comments on commit f6a03a3

Please sign in to comment.