More acknowledgements.
[iolib.git] / tests / ustrings.lisp
blob76183f29e56e26318dfd4799a736d1efe79e83bd
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: nil -*-
2 ;;;
3 ;;; --- ustrings test suite.
4 ;;;
6 (in-package :iolib-tests)
8 (in-suite :iolib.base.ustrings)
9 \f
11 (test make-ustring.1
12 (is-true (typep (make-ustring 1) '(ustring 1))))
14 (test make-ustring.2
15 (is-true (eql 0 (aref (make-ustring 1) 0))))
17 (test make-ustring.3
18 (is-true (eql 40 (aref (make-ustring 1 :initial-element 40) 0))))
20 (test make-ustring.error.1
21 (signals type-error
22 (make-ustring -1 :initial-element 40)))
24 (test make-ustring.error.2
25 (signals type-error
26 (make-ustring 1 :initial-element -1)))
28 (test make-ustring.error.3
29 (signals type-error
30 (make-ustring 1 :initial-element uchar-code-limit)))
32 (test make-ustring.error.3
33 (signals type-error
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))))
50 (test ustring.1
51 (is (equalp #(97) (ustring (make-ustring 1 :initial-element 97)))))
53 (test ustring.2
54 (is (equalp #(97) (ustring 97))))
56 (test ustring.3
57 (is (equalp #(97) (ustring #(97)))))
59 (test ustring.4
60 (is (equalp #(97) (ustring "a"))))
62 (test ustring.5
63 (is (equalp #(97) (ustring #\a))))
65 (test ustring.6
66 (is (equalp #(65) (ustring 'a))))
68 (test ustring.7
69 (is-true
70 (let ((ustring (make-ustring 1 :initial-element 100)))
71 (eq ustring (ustring ustring :new nil)))))
73 (test ustring.8
74 (is-false
75 (let ((ustring (make-ustring 1 :initial-element 100)))
76 (eq ustring (ustring ustring :new t)))))
78 (test ustring.error.1
79 (signals type-error
80 (ustring (make-hash-table))))
83 (test ustringp.1
84 (is-true (ustringp (make-ustring 1))))
86 (test ustringp.error.1
87 (is-false (ustringp "string")))
90 (test ustring=.1
91 (is-true (ustring= "" "")))
93 (test ustring=.2
94 (is-true (ustring= "a" "a")))
96 (test ustring=.3
97 (is-true (ustring= "bac" "acb" :start1 1 :end2 2)))
99 (test ustring=.4
100 (is-false (ustring= "a" "b")))
102 (test ustring=.5
103 (is-false (ustring= "bac" "")))
105 (test ustring=.6
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)))
134 (test ustring/=.1
135 (is-false (ustring/= "" "")))
137 (test ustring/=.2
138 (is (eql 0 (ustring/= "" "a"))))
140 (test ustring/=.3
141 (is (eql 0 (ustring/= "a" "b"))))
143 (test ustring/=.4
144 (is-false (ustring/= "bac" "acb" :start1 1 :end2 2)))
146 (test ustring/=.5
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"))))
175 (test ustring<.1
176 (is-false (ustring< "" "")))
178 (test ustring<.2
179 (is (eql 0 (ustring< "" "a"))))
181 (test ustring<.3
182 (is-false (ustring< "a" "")))
184 (test ustring<.4
185 (is (eql 0 (ustring< "a" "b"))))
187 (test ustring<.5
188 (is-false (ustring< "b" "a")))
190 (test ustring<.6
191 (is-false (ustring< "bac" "acb" :start1 1 :end2 2)))
193 (test ustring<.7
194 (is-false (ustring< "acb" "bac" :start1 1 :end2 2)))
196 (test ustring<.8
197 (is (eql 1 (ustring< "abc" "acb"))))
199 (test ustring<.9
200 (is-false (ustring< "acb" "abc")))
202 (test ustring<.10
203 (is-false (ustring< "a" "a")))
205 (test ustring<.11
206 (is-false (ustring< "a" "A")))
208 (test ustring<.12
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")))
249 (test ustring>.1
250 (is-false (ustring> "" "")))
252 (test ustring>.2
253 (is-false (ustring> "" "a")))
255 (test ustring>.3
256 (is (eql 0 (ustring> "a" ""))))
258 (test ustring>.4
259 (is-false (ustring> "a" "b")))
261 (test ustring>.5
262 (is (eql 0 (ustring> "b" "a"))))
264 (test ustring>.6
265 (is-false (ustring> "bac" "acb" :start1 1 :end2 2)))
267 (test ustring>.7
268 (is (eql 1 (ustring> "acb" "bac" :start1 1 :end2 2))))
270 (test ustring>.8
271 (is-false (ustring> "abc" "acb")))
273 (test ustring>.9
274 (is (eql 1 (ustring> "acb" "abc"))))
276 (test ustring>.10
277 (is-false (ustring> "a" "a")))
279 (test ustring>.11
280 (is (eql 0 (ustring> "a" "A"))))
282 (test ustring>.12
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")))
323 (test ustring<=.1
324 (is (eql 0 (ustring<= "" ""))))
326 (test ustring<=.2
327 (is (eql 0 (ustring<= "" "a"))))
329 (test ustring<=.3
330 (is-false (ustring<= "a" "")))
332 (test ustring<=.4
333 (is (eql 0 (ustring<= "a" "b"))))
335 (test ustring<=.5
336 (is-false (ustring<= "b" "a")))
338 (test ustring<=.6
339 (is (eql 3 (ustring<= "bac" "acb" :start1 1 :end2 2))))
341 (test ustring<=.7
342 (is-false (ustring<= "acb" "bac" :start1 1 :end2 2)))
344 (test ustring<=.8
345 (is (eql 1 (ustring<= "abc" "acb"))))
347 (test ustring<=.9
348 (is-false (ustring<= "acb" "abc")))
350 (test ustring<=.10
351 (is (eql 1 (ustring<= "a" "a"))))
353 (test ustring<=.11
354 (is-false (ustring<= "a" "A")))
356 (test ustring<=.12
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"))))
397 (test ustring>=.1
398 (is (eql 0 (ustring>= "" ""))))
400 (test ustring>=.2
401 (is-false (ustring>= "" "a")))
403 (test ustring>=.3
404 (is (eql 0 (ustring>= "a" ""))))
406 (test ustring>=.4
407 (is-false (ustring>= "a" "b")))
409 (test ustring>=.5
410 (is (eql 0 (ustring>= "b" "a"))))
412 (test ustring>=.6
413 (is (eql 3 (ustring>= "bac" "acb" :start1 1 :end2 2))))
415 (test ustring>=.7
416 (is (eql 1 (ustring>= "acb" "bac" :start1 1 :end2 2))))
418 (test ustring>=.8
419 (is-false (ustring>= "abc" "acb")))
421 (test ustring>=.9
422 (is (eql 1 (ustring>= "acb" "abc"))))
424 (test ustring>=.10
425 (is (eql 1 (ustring>= "a" "a"))))
427 (test ustring>=.11
428 (is (eql 0 (ustring>= "a" "A"))))
430 (test ustring>=.12
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
482 (signals type-error
483 (ustring-upcase 5)))
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
497 (signals type-error
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
512 (signals type-error
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
527 (signals type-error
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
542 (signals type-error
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
557 (signals type-error
558 (nustring-capitalize 5)))
561 (test ustring-trim.1
562 (is (ustring= "aha" (ustring-trim "kekahakek" "ke"))))
564 (test ustring-trim.2
565 (is (ustring= "aha" (ustring-trim "kekahakek" '(#\k #\e)))))
567 (test ustring-trim.3
568 (is (ustring= "" (ustring-left-trim "aha" "ah"))))
570 (test ustring-trim.4
571 (is-false (let ((ustring (ustring "aha")))
572 (eql ustring (ustring-trim ustring "z")))))
574 (test ustring-trim.error.1
575 (signals type-error
576 (ustring-trim "kekahakek" 5)))
578 (test ustring-trim.error.2
579 (signals type-error
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
597 (signals type-error
598 (ustring-left-trim "kekahakek" 5)))
600 (test ustring-left-trim.error.2
601 (signals type-error
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
619 (signals type-error
620 (ustring-right-trim "kekahakek" 5)))
622 (test ustring-right-trim.error.2
623 (signals type-error
624 (ustring-right-trim (make-hash-table) '(#\k #\e))))