1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: nil -*-
3 ;;; --- ustrings test suite.
6 (in-package :iolib-tests
)
8 (in-suite :iolib.base.ustrings
)
12 (is-true (typep (make-ustring 1) '(ustring 1))))
15 (is-true (eql 0 (aref (make-ustring 1) 0))))
18 (is-true (eql 40 (aref (make-ustring 1 :initial-element
40) 0))))
20 (test make-ustring.error
.1
22 (make-ustring -
1 :initial-element
40)))
24 (test make-ustring.error
.2
26 (make-ustring 1 :initial-element -
1)))
28 (test make-ustring.error
.3
30 (make-ustring 1 :initial-element uchar-code-limit
)))
32 (test make-ustring.error
.3
34 (make-ustring 1 :initial-element
#\a)))
37 (test string-to-ustring
.1
38 (is-true (typep (string-to-ustring "a") '(ustring 1))))
40 (test string-to-ustring
.2
41 (is (equalp #(97) (string-to-ustring "a"))))
43 (test string-to-ustring
.3
44 (is (equalp #(97) (string-to-ustring #\a))))
46 (test string-to-ustring
.4
47 (is (equalp #(65) (string-to-ustring 'a
))))
51 (is (equalp #(97) (ustring (make-ustring 1 :initial-element
97)))))
54 (is (equalp #(97) (ustring 97))))
57 (is (equalp #(97) (ustring #(97)))))
60 (is (equalp #(97) (ustring "a"))))
63 (is (equalp #(97) (ustring #\a))))
66 (is (equalp #(65) (ustring 'a
))))
70 (let ((ustring (make-ustring 1 :initial-element
100)))
71 (eq ustring
(ustring ustring
:new nil
)))))
75 (let ((ustring (make-ustring 1 :initial-element
100)))
76 (eq ustring
(ustring ustring
:new t
)))))
80 (ustring (make-hash-table))))
84 (is-true (ustringp (make-ustring 1))))
86 (test ustringp.error
.1
87 (is-false (ustringp "string")))
91 (is-true (ustring= "" "")))
94 (is-true (ustring= "a" "a")))
97 (is-true (ustring= "bac" "acb" :start1
1 :end2
2)))
100 (is-false (ustring= "a" "b")))
103 (is-false (ustring= "bac" "")))
106 (is-false (ustring= "bac" "bac" :end1
0)))
109 (test ustring-equal
.1
110 (is-true (ustring-equal "" "")))
112 (test ustring-equal
.2
113 (is-true (ustring-equal "a" "a")))
115 (test ustring-equal
.3
116 (is-true (ustring-equal "a" "A")))
118 (test ustring-equal
.4
119 (is-true (ustring-equal "bac" "acb" :start1
1 :end2
2)))
121 (test ustring-equal
.5
122 (is-true (ustring-equal "bac" "ACB" :start1
1 :end2
2)))
124 (test ustring-equal
.6
125 (is-false (ustring-equal "a" "b")))
127 (test ustring-equal
.7
128 (is-false (ustring-equal "bac" "")))
130 (test ustring-equal
.8
131 (is-false (ustring-equal "bac" "bac" :end1
0)))
135 (is-false (ustring/= "" "")))
138 (is (eql 0 (ustring/= "" "a"))))
141 (is (eql 0 (ustring/= "a" "b"))))
144 (is-false (ustring/= "bac" "acb" :start1
1 :end2
2)))
147 (is (eql 1 (ustring/= "abc" "acb"))))
150 (test ustring-not-equal
.1
151 (is-false (ustring-not-equal "" "")))
153 (test ustring-not-equal
.2
154 (is (eql 0 (ustring-not-equal "" "a"))))
156 (test ustring-not-equal
.3
157 (is (eql 0 (ustring-not-equal "a" "b"))))
159 (test ustring-not-equal
.4
160 (is-false (ustring-not-equal "a" "A")))
162 (test ustring-not-equal
.5
163 (is-false (ustring-not-equal "bac" "acb" :start1
1 :end2
2)))
165 (test ustring-not-equal
.6
166 (is-false (ustring-not-equal "bac" "ACB" :start1
1 :end2
2)))
168 (test ustring-not-equal
.7
169 (is (eql 1 (ustring-not-equal "abc" "acb"))))
171 (test ustring-not-equal
.8
172 (is (eql 1 (ustring-not-equal "abc" "ACB"))))
176 (is-false (ustring< "" "")))
179 (is (eql 0 (ustring< "" "a"))))
182 (is-false (ustring< "a" "")))
185 (is (eql 0 (ustring< "a" "b"))))
188 (is-false (ustring< "b" "a")))
191 (is-false (ustring< "bac" "acb" :start1
1 :end2
2)))
194 (is-false (ustring< "acb" "bac" :start1
1 :end2
2)))
197 (is (eql 1 (ustring< "abc" "acb"))))
200 (is-false (ustring< "acb" "abc")))
203 (is-false (ustring< "a" "a")))
206 (is-false (ustring< "a" "A")))
209 (is (eql 0 (ustring< "A" "a"))))
212 (test ustring-lessp
.1
213 (is-false (ustring-lessp "" "")))
215 (test ustring-lessp
.2
216 (is (eql 0 (ustring-lessp "" "a"))))
218 (test ustring-lessp
.3
219 (is-false (ustring-lessp "a" "")))
221 (test ustring-lessp
.4
222 (is (eql 0 (ustring-lessp "a" "b"))))
224 (test ustring-lessp
.5
225 (is-false (ustring-lessp "b" "a")))
227 (test ustring-lessp
.6
228 (is-false (ustring-lessp "bac" "acb" :start1
1 :end2
2)))
230 (test ustring-lessp
.7
231 (is-false (ustring-lessp "acb" "bac" :start1
1 :end2
2)))
233 (test ustring-lessp
.8
234 (is (eql 1 (ustring-lessp "abc" "acb"))))
236 (test ustring-lessp
.9
237 (is-false (ustring-lessp "acb" "abc")))
239 (test ustring-lessp
.10
240 (is-false (ustring-lessp "a" "a")))
242 (test ustring-lessp
.11
243 (is-false (ustring-lessp "a" "A")))
245 (test ustring-lessp
.12
246 (is-false (ustring-lessp "A" "a")))
250 (is-false (ustring> "" "")))
253 (is-false (ustring> "" "a")))
256 (is (eql 0 (ustring> "a" ""))))
259 (is-false (ustring> "a" "b")))
262 (is (eql 0 (ustring> "b" "a"))))
265 (is-false (ustring> "bac" "acb" :start1
1 :end2
2)))
268 (is (eql 1 (ustring> "acb" "bac" :start1
1 :end2
2))))
271 (is-false (ustring> "abc" "acb")))
274 (is (eql 1 (ustring> "acb" "abc"))))
277 (is-false (ustring> "a" "a")))
280 (is (eql 0 (ustring> "a" "A"))))
283 (is-false (ustring> "A" "a")))
286 (test ustring-greaterp
.1
287 (is-false (ustring-greaterp "" "")))
289 (test ustring-greaterp
.2
290 (is-false (ustring-greaterp "" "a")))
292 (test ustring-greaterp
.3
293 (is (eql 0 (ustring-greaterp "a" ""))))
295 (test ustring-greaterp
.4
296 (is-false (ustring-greaterp "a" "b")))
298 (test ustring-greaterp
.5
299 (is (eql 0 (ustring-greaterp "b" "a"))))
301 (test ustring-greaterp
.6
302 (is-false (ustring-greaterp "bac" "acb" :start1
1 :end2
2)))
304 (test ustring-greaterp
.7
305 (is (eql 1 (ustring-greaterp "acb" "bac" :start1
1 :end2
2))))
307 (test ustring-greaterp
.8
308 (is-false (ustring-greaterp "abc" "acb")))
310 (test ustring-greaterp
.9
311 (is (eql 1 (ustring-greaterp "acb" "abc"))))
313 (test ustring-greaterp
.10
314 (is-false (ustring-greaterp "a" "a")))
316 (test ustring-greaterp
.11
317 (is-false (ustring-greaterp "a" "A")))
319 (test ustring-greaterp
.12
320 (is-false (ustring-greaterp "A" "a")))
324 (is (eql 0 (ustring<= "" ""))))
327 (is (eql 0 (ustring<= "" "a"))))
330 (is-false (ustring<= "a" "")))
333 (is (eql 0 (ustring<= "a" "b"))))
336 (is-false (ustring<= "b" "a")))
339 (is (eql 3 (ustring<= "bac" "acb" :start1
1 :end2
2))))
342 (is-false (ustring<= "acb" "bac" :start1
1 :end2
2)))
345 (is (eql 1 (ustring<= "abc" "acb"))))
348 (is-false (ustring<= "acb" "abc")))
351 (is (eql 1 (ustring<= "a" "a"))))
354 (is-false (ustring<= "a" "A")))
357 (is (eql 0 (ustring<= "A" "a"))))
360 (test ustring-not-greaterp
.1
361 (is (eql 0 (ustring-not-greaterp "" ""))))
363 (test ustring-not-greaterp
.2
364 (is (eql 0 (ustring-not-greaterp "" "a"))))
366 (test ustring-not-greaterp
.3
367 (is-false (ustring-not-greaterp "a" "")))
369 (test ustring-not-greaterp
.4
370 (is (eql 0 (ustring-not-greaterp "a" "b"))))
372 (test ustring-not-greaterp
.5
373 (is-false (ustring-not-greaterp "b" "a")))
375 (test ustring-not-greaterp
.6
376 (is (eql 3 (ustring-not-greaterp "bac" "acb" :start1
1 :end2
2))))
378 (test ustring-not-greaterp
.7
379 (is-false (ustring-not-greaterp "acb" "bac" :start1
1 :end2
2)))
381 (test ustring-not-greaterp
.8
382 (is (eql 1 (ustring-not-greaterp "abc" "acb"))))
384 (test ustring-not-greaterp
.9
385 (is-false (ustring-not-greaterp "acb" "abc")))
387 (test ustring-not-greaterp
.10
388 (is (eql 1 (ustring-not-greaterp "a" "a"))))
390 (test ustring-not-greaterp
.11
391 (is (eql 1 (ustring-not-greaterp "a" "A"))))
393 (test ustring-not-greaterp
.12
394 (is (eql 1 (ustring-not-greaterp "A" "a"))))
398 (is (eql 0 (ustring>= "" ""))))
401 (is-false (ustring>= "" "a")))
404 (is (eql 0 (ustring>= "a" ""))))
407 (is-false (ustring>= "a" "b")))
410 (is (eql 0 (ustring>= "b" "a"))))
413 (is (eql 3 (ustring>= "bac" "acb" :start1
1 :end2
2))))
416 (is (eql 1 (ustring>= "acb" "bac" :start1
1 :end2
2))))
419 (is-false (ustring>= "abc" "acb")))
422 (is (eql 1 (ustring>= "acb" "abc"))))
425 (is (eql 1 (ustring>= "a" "a"))))
428 (is (eql 0 (ustring>= "a" "A"))))
431 (is-false (ustring>= "A" "a")))
434 (test ustring-not-lessp
.1
435 (is (eql 0 (ustring-not-lessp "" ""))))
437 (test ustring-not-lessp
.2
438 (is-false (ustring-not-lessp "" "a")))
440 (test ustring-not-lessp
.3
441 (is (eql 0 (ustring-not-lessp "a" ""))))
443 (test ustring-not-lessp
.4
444 (is-false (ustring-not-lessp "a" "b")))
446 (test ustring-not-lessp
.5
447 (is (eql 0 (ustring-not-lessp "b" "a"))))
449 (test ustring-not-lessp
.6
450 (is (eql 3 (ustring-not-lessp "bac" "acb" :start1
1 :end2
2))))
452 (test ustring-not-lessp
.7
453 (is (eql 1 (ustring-not-lessp "acb" "bac" :start1
1 :end2
2))))
455 (test ustring-not-lessp
.8
456 (is-false (ustring-not-lessp "abc" "acb")))
458 (test ustring-not-lessp
.9
459 (is (eql 1 (ustring-not-lessp "acb" "abc"))))
461 (test ustring-not-lessp
.10
462 (is (eql 1 (ustring-not-lessp "a" "a"))))
464 (test ustring-not-lessp
.11
465 (is (eql 1 (ustring-not-lessp "a" "A"))))
467 (test ustring-not-lessp
.12
468 (is (eql 1 (ustring-not-lessp "A" "a"))))
471 (test ustring-upcase
.1
472 (is (ustring= "AHA" (ustring-upcase "aha"))))
474 (test ustring-upcase
.2
475 (is (ustring= "" (ustring-upcase ""))))
477 (test ustring-upcase
.3
478 (is-false (let ((ustring (ustring "AHA")))
479 (eql ustring
(ustring-upcase ustring
)))))
481 (test ustring-upcase.error
.1
486 (test nustring-upcase
.1
487 (is (ustring= "AHA" (nustring-upcase (ustring "aha")))))
489 (test nustring-upcase
.2
490 (is (ustring= "" (nustring-upcase (ustring "")))))
492 (test nustring-upcase
.3
493 (is-true (let ((ustring (ustring "AHA")))
494 (eql ustring
(nustring-upcase ustring
)))))
496 (test nustring-upcase.error
.1
498 (nustring-upcase 5)))
501 (test ustring-downcase
.1
502 (is (ustring= "aha" (ustring-downcase "AHA"))))
504 (test ustring-downcase
.2
505 (is (ustring= "" (ustring-downcase ""))))
507 (test ustring-downcase
.3
508 (is-false (let ((ustring (ustring "aha")))
509 (eql ustring
(ustring-downcase ustring
)))))
511 (test ustring-downcase.error
.1
513 (ustring-downcase 5)))
516 (test nustring-downcase
.1
517 (is (ustring= "aha" (nustring-downcase (ustring "AHA")))))
519 (test nustring-downcase
.2
520 (is (ustring= "" (nustring-downcase (ustring "")))))
522 (test nustring-downcase
.3
523 (is-true (let ((ustring (ustring "aha")))
524 (eql ustring
(nustring-downcase ustring
)))))
526 (test nustring-downcase.error
.1
528 (nustring-downcase 5)))
531 (test ustring-capitalize
.1
532 (is (ustring= "Hak Mak" (ustring-capitalize "hak mak"))))
534 (test ustring-capitalize
.2
535 (is (ustring= "" (ustring-capitalize ""))))
537 (test ustring-capitalize
.3
538 (is-false (let ((ustring (ustring "Hak Mak")))
539 (eql ustring
(ustring-capitalize ustring
)))))
541 (test ustring-capitalize.error
.1
543 (ustring-capitalize 5)))
546 (test nustring-capitalize
.1
547 (is (ustring= "Hak Mak" (nustring-capitalize (ustring "hak mak")))))
549 (test nustring-capitalize
.2
550 (is (ustring= "" (nustring-capitalize (ustring "")))))
552 (test nustring-capitalize
.3
553 (is-true (let ((ustring (ustring "Hak Mak")))
554 (eql ustring
(nustring-capitalize ustring
)))))
556 (test nustring-capitalize.error
.1
558 (nustring-capitalize 5)))
562 (is (ustring= "aha" (ustring-trim "kekahakek" "ke"))))
565 (is (ustring= "aha" (ustring-trim "kekahakek" '(#\k
#\e
)))))
568 (is (ustring= "" (ustring-left-trim "aha" "ah"))))
571 (is-false (let ((ustring (ustring "aha")))
572 (eql ustring
(ustring-trim ustring
"z")))))
574 (test ustring-trim.error
.1
576 (ustring-trim "kekahakek" 5)))
578 (test ustring-trim.error
.2
580 (ustring-trim (make-hash-table) '(#\k
#\e
))))
583 (test ustring-left-trim
.1
584 (is (ustring= "ahakek" (ustring-left-trim "kekahakek" "ke"))))
586 (test ustring-left-trim
.2
587 (is (ustring= "ahakek" (ustring-left-trim "kekahakek" '(#\k
#\e
)))))
589 (test ustring-left-trim
.3
590 (is (ustring= "" (ustring-left-trim "aha" "ah"))))
592 (test ustring-left-trim
.4
593 (is-false (let ((ustring (ustring "aha")))
594 (eql ustring
(ustring-left-trim ustring
"z")))))
596 (test ustring-left-trim.error
.1
598 (ustring-left-trim "kekahakek" 5)))
600 (test ustring-left-trim.error
.2
602 (ustring-left-trim (make-hash-table) '(#\k
#\e
))))
605 (test ustring-right-trim
.1
606 (is (ustring= "kekaha" (ustring-right-trim "kekahakek" "ke"))))
608 (test ustring-right-trim
.2
609 (is (ustring= "kekaha" (ustring-right-trim "kekahakek" '(#\k
#\e
)))))
611 (test ustring-right-trim
.3
612 (is (ustring= "" (ustring-left-trim "aha" "ah"))))
614 (test ustring-right-trim
.4
615 (is-false (let ((ustring (ustring "aha")))
616 (eql ustring
(ustring-right-trim ustring
"z")))))
618 (test ustring-right-trim.error
.1
620 (ustring-right-trim "kekahakek" 5)))
622 (test ustring-right-trim.error
.2
624 (ustring-right-trim (make-hash-table) '(#\k
#\e
))))