File tree 3 files changed +28
-5
lines changed
3 files changed +28
-5
lines changed Original file line number Diff line number Diff line change 1
1
(ns cljs.benchmark-runner
2
2
(:refer-clojure :exclude [println])
3
3
(:require [cljs.reader :as reader]
4
- [clojure.core.reducers :as r]))
4
+ [clojure.core.reducers :as r]
5
+ [clojure.string :as string]))
5
6
6
7
(def println print )
7
8
408
409
(simple-benchmark [] (str " 1" " 2" ) 1000000 )
409
410
(simple-benchmark [] (str " 1" " 2" " 3" ) 1000000 )
410
411
412
+ (println " \n " )
413
+ (println " ;;; clojure.string" )
414
+ (simple-benchmark [s " a" f clojure.string/capitalize] (f s) 1000000 )
415
+ (simple-benchmark [s " aBcDeF" f clojure.string/capitalize] (f s) 1000000 )
416
+
411
417
(println " ;; printing of numbers and handling of ##Nan, ##Inf, ##-Inf" )
412
418
(simple-benchmark [x true ] (pr-str x) 1000000 )
413
419
(simple-benchmark [x 10 ] (pr-str x) 1000000 )
Original file line number Diff line number Diff line change 101
101
" Converts first character of the string to upper-case, all other
102
102
characters to lower-case."
103
103
[s]
104
- (if (< (count s) 2 )
105
- (upper-case s)
106
- (str (upper-case (subs s 0 1 ))
107
- (lower-case (subs s 1 )))))
104
+ (gstring/capitalize s))
108
105
109
106
; ; The JavaScript split function takes a limit argument but the return
110
107
; ; value is not the same as the Java split function.
Original file line number Diff line number Diff line change 9
9
(ns clojure.string-test
10
10
(:require [cljs.test :as test
11
11
:refer-macros [deftest is testing]]
12
+ [clojure.test.check :as tc]
13
+ [clojure.test.check.clojure-test :refer-macros [defspec ]]
14
+ [clojure.test.check.generators :as gen]
15
+ [clojure.test.check.properties :as prop :include-macros true ]
12
16
[clojure.string :as s]))
13
17
14
18
(deftest test-api
149
153
(is (s/includes? sb " Applied" ))
150
154
(is (not (s/includes? sb " Living" ))))))
151
155
156
+ (defspec test-cljs-2300
157
+ ; ; The reference implementation is the implementation prior to the change.
158
+ ; ; Since some JavaScript implementations fail to properly change case for
159
+ ; ; some characters (for example, the upper case of "ß" is "SS"), we limit
160
+ ; ; this test to strings comprising only printable ASCII characters.
161
+ (let [ref-impl (fn [s]
162
+ (if (< (count s) 2 )
163
+ (s/upper-case s)
164
+ (str (s/upper-case (subs s 0 1 ))
165
+ (s/lower-case (subs s 1 )))))
166
+ char-codes->string (fn [xs]
167
+ (apply (.-fromCharCode js/String) xs))]
168
+ (prop/for-all [s (gen/fmap char-codes->string
169
+ (gen/not-empty (gen/vector (gen/choose 0x20 0x7E ))))]
170
+ (= (ref-impl s) (s/capitalize s)))))
171
+
152
172
(comment
153
173
154
174
(deftest char-sequence-handling
You can’t perform that action at this time.
0 commit comments