Browse files

CLJS-2300: Delegate clojure.string/capitalize to goog.string/capitalize

  • Loading branch information...
mfikes authored and swannodette committed Aug 5, 2017
1 parent 9778b34 commit 9c2ec8b56a8516540b54e2a4fc6d942f9c05699c
@@ -1,7 +1,8 @@
(ns cljs.benchmark-runner
(:refer-clojure :exclude [println])
(:require [cljs.reader :as reader]
[clojure.core.reducers :as r]))
[clojure.core.reducers :as r]
[clojure.string :as string]))
(def println print)
@@ -408,6 +409,11 @@
(simple-benchmark [] (str "1" "2") 1000000)
(simple-benchmark [] (str "1" "2" "3") 1000000)
(println "\n")
(println ";;; clojure.string")
(simple-benchmark [s "a" f clojure.string/capitalize] (f s) 1000000)
(simple-benchmark [s "aBcDeF" f clojure.string/capitalize] (f s) 1000000)
(println ";; printing of numbers and handling of ##Nan, ##Inf, ##-Inf")
(simple-benchmark [x true] (pr-str x) 1000000)
(simple-benchmark [x 10] (pr-str x) 1000000)
@@ -101,10 +101,7 @@
"Converts first character of the string to upper-case, all other
characters to lower-case."
(if (< (count s) 2)
(upper-case s)
(str (upper-case (subs s 0 1))
(lower-case (subs s 1)))))
(gstring/capitalize s))
;; The JavaScript split function takes a limit argument but the return
;; value is not the same as the Java split function.
@@ -9,6 +9,10 @@
(ns clojure.string-test
(:require [cljs.test :as test
:refer-macros [deftest is testing]]
[clojure.test.check :as tc]
[clojure.test.check.clojure-test :refer-macros [defspec]]
[clojure.test.check.generators :as gen]
[ :as prop :include-macros true]
[clojure.string :as s]))
(deftest test-api
@@ -149,6 +153,22 @@
(is (s/includes? sb "Applied"))
(is (not (s/includes? sb "Living"))))))
(defspec test-cljs-2300
;; The reference implementation is the implementation prior to the change.
;; Since some JavaScript implementations fail to properly change case for
;; some characters (for example, the upper case of "ß" is "SS"), we limit
;; this test to strings comprising only printable ASCII characters.
(let [ref-impl (fn [s]
(if (< (count s) 2)
(s/upper-case s)
(str (s/upper-case (subs s 0 1))
(s/lower-case (subs s 1)))))
char-codes->string (fn [xs]
(apply (.-fromCharCode js/String) xs))]
(prop/for-all [s (gen/fmap char-codes->string
(gen/not-empty (gen/vector (gen/choose 0x20 0x7E))))]
(= (ref-impl s) (s/capitalize s)))))
(deftest char-sequence-handling

0 comments on commit 9c2ec8b

Please sign in to comment.