/[eiffelstudio]/trunk/eweasel/tests/string001/test_string_32.e
ViewVC logotype

Contents of /trunk/eweasel/tests/string001/test_string_32.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 100591 - (show annotations)
Sat Jul 8 08:14:06 2017 UTC (2 years, 6 months ago) by alexk
File size: 75230 byte(s)
Specified explicit manifest array type to avoid a warning that computed manifest array type does not conform to the target of reattachment.
1 class
2 TEST_STRING_32
3
4 create
5
6 make
7
8 feature {NONE} -- Initialization
9
10 make is
11 -- Execute test.
12 do
13 test_adapt
14 test_adapt_size
15 test_additional_space
16 test_append
17 test_append_boolean
18 test_append_character
19 test_append_double
20 test_append_integer
21 test_append_real
22 test_append_string
23 test_as_lower
24 test_as_upper
25 test_automatic_grow
26 test_center_justify
27 test_character_justify
28 test_copy
29 test_ends_with
30 test_extend
31 test_fill_blank
32 test_fill_character
33 test_fill_with
34 test_from_c
35 test_from_c_substring
36 test_fuzzy_index
37 test_grow
38 test_has
39 test_has_substring
40 test_index_of
41 test_insert_character
42 test_insert_string
43 test_is_boolean
44 test_is_case_insensitive_equal
45 test_is_double
46 test_is_empty
47 test_is_equal
48 test_is_inserted
49 test_is_integer
50 test_is_real
51 test_infix_greater
52 test_infix_greater_or_equal
53 test_infix_less
54 test_infix_less_or_equal
55 test_infix_plus
56 test_keep_head
57 test_keep_tail
58 test_last_index_of
59 test_left_adjust
60 test_left_justify
61 test_linear_representation
62 test_make
63 test_make_empty
64 test_make_filled
65 test_make_from_c
66 test_make_from_string
67 test_max
68 test_min
69 test_mirror
70 test_mirrored
71 test_multiply
72 test_occurrences
73 test_out
74 test_plus
75 test_precede
76 test_prepend
77 test_prepend_boolean
78 test_prepend_character
79 test_prepend_double
80 test_prepend_integer
81 test_prepend_real
82 test_prepend_string
83 test_prunable
84 test_prune
85 test_prune_all
86 test_prune_all_leading
87 test_prune_all_trailing
88 test_put
89 test_remove
90 test_remove_head
91 test_remove_substring
92 test_remove_tail
93 test_replace_blank
94 test_replace_substring
95 test_replace_substring_all
96 test_resizable
97 test_resize
98 test_right_adjust
99 test_right_justify
100 test_same_string
101 test_same_characters
102 test_same_caseless_characters
103 test_same_type
104 test_set
105 test_share
106 test_shared_with
107 test_split
108 test_starts_with
109 test_string
110 test_subcopy
111 test_substring
112 test_substring_index
113 test_substring_index_in_bounds
114 test_tagged_out
115 test_three_way_comparison
116 test_to_c
117 test_to_cil
118 test_to_double
119 test_to_integer
120 test_to_integer_64
121 test_to_lower
122 test_to_real
123 test_to_upper
124 test_trim
125 test_twin
126 test_valid_index
127 test_wipe_out
128 end
129
130 feature {NONE} -- Implementation
131
132 test_adapt is
133 local
134 s, t: STRING_32
135 do
136 t := "1234567890"
137 s := t.adapt (t)
138 check_string_equality ("adapt", s, t)
139 check_equality ("adapt", s.area, t.area)
140 end
141
142 test_adapt_size is
143 local
144 s: STRING_32
145 do
146 create s.make (1000)
147 s.append ("12345")
148 s.adapt_size
149 check_equality ("adapt_size", s.count, 5)
150 end
151
152 test_additional_space is
153 local
154 s: STRING_32
155 i: INTEGER
156 do
157 create s.make (100)
158 i := s.additional_space
159 check_boolean ("additional_space", i >= 1)
160 end
161
162 test_append is
163 local
164 s: STRING_32
165 do
166 create s.make (10)
167 s.append ("12345")
168 check_string_equality ("append", s, "12345")
169
170 s.append (s)
171 check_string_equality ("append", s, "1234512345")
172
173 s.append ("")
174 check_string_equality ("append", s, "1234512345")
175 end
176
177 test_append_boolean is
178 local
179 s: STRING_32
180 do
181 create s.make (10)
182 s.append_boolean (True)
183 check_string_equality ("append_boolean", s, "True")
184
185 s.wipe_out
186 s.append_boolean (False)
187 check_string_equality ("append_boolean", s, "False")
188 end
189
190 test_append_character, test_extend is
191 local
192 s: STRING_32
193 do
194 create s.make (10)
195 s.append_character ('c')
196 check_string_equality ("append_character", s, "c")
197 end
198
199 test_append_double is
200 local
201 s: STRING_32
202 do
203 create s.make (10)
204 s.append_double (5.6)
205 check_string_equality ("append_double", s, "5.5999999999999996")
206 check_equality ("append_double", s.to_double, 5.6)
207 end
208
209 test_append_integer is
210 local
211 s: STRING_32
212 do
213 create s.make (10)
214 s.append_integer (123)
215 check_string_equality ("append_integer", s, "123")
216 check_equality ("append_integer", s.to_integer, 123)
217
218 s.wipe_out
219 s.append_integer (0x80000000)
220 check_string_equality ("append_integer", s, "-2147483648")
221 end
222
223 test_append_real is
224 local
225 s: STRING_32
226 r: REAL
227 do
228 r := {REAL_32} 5.6
229 create s.make (10)
230 s.append_real (r)
231 check_string_equality ("append_real", s, "5.6")
232 check_equality ("append_real", s.to_real, r)
233 end
234
235 test_append_string is
236 local
237 s: STRING_32
238 do
239 create s.make (10)
240 s.append_string ("12345")
241 check_string_equality ("append_string", s, "12345")
242
243 s.append_string (s)
244 check_string_equality ("append_string", s, "1234512345")
245
246 s.append_string ("")
247 check_string_equality ("append_string", s, "1234512345")
248
249 s.append_string (Void)
250 check_string_equality ("append_string", s, "1234512345")
251 end
252
253 test_as_lower is
254 local
255 s, t: STRING_32
256 do
257 create s.make_from_string ("ABcd EF gh I 123 ;")
258 t := s.as_lower
259 check_string_equality ("as_lower", t, "abcd ef gh i 123 ;")
260 check_boolean ("as_lower", t /= s)
261
262 s.to_lower
263 check_equality ("as_lower", t, s)
264 end
265
266 test_as_upper is
267 local
268 s, t: STRING_32
269 do
270 create s.make_from_string ("ABcd EF gh I 123 ;")
271 t := s.as_upper
272 check_string_equality ("as_upper", t, "ABCD EF GH I 123 ;")
273 check_boolean ("as_upper", t /= s)
274
275 s.to_upper
276 check_equality ("as_upper", t, s)
277 end
278
279 test_automatic_grow is
280 local
281 s: STRING_32
282 do
283 create s.make (10)
284 s.append ("123")
285 s.automatic_grow
286 check_string_equality ("automatic_grow", s, "123")
287 check_boolean ("automatic_grow", s.capacity >= 10)
288 end
289
290 test_center_justify is
291 local
292 s: STRING_32
293 do
294 create s.make (20)
295 s.append (" 1234567890 ")
296 s.center_justify
297 check_string_equality ("center_justify", s, " 1234567890 ")
298
299 s.wipe_out
300 s.append (" 1234567890 ")
301 s.center_justify
302 check_string_equality ("center_justify", s, " 1234567890 ")
303
304 s.wipe_out
305 s.append (" 1234567890 ")
306 s.append (" 1234567890 ")
307 s.center_justify
308 check_string_equality ("center_justify", s, " 1234567890 1234567890 ")
309
310 s.wipe_out
311 s.append ("123456")
312 s.center_justify
313 check_string_equality ("center_justify", s, "123456")
314 end
315
316 test_character_justify is
317 local
318 s: STRING_32
319 do
320 create s.make (10)
321 s.append ("1234567890x1234567890")
322 s.character_justify ('x', 3)
323 check_string_equality ("character_justify", s, "90x1234567890 ")
324
325 create s.make (10)
326 s.append ("1234567890x1234567890")
327 s.character_justify ('x', 20)
328 check_string_equality ("character_justify", s, " 1234567890x1234567890")
329
330 s := "1234567890x1234567890"
331 s.character_justify ('s', 1)
332 check_string_equality ("character_justify", s, "1234567890x1234567890")
333 end
334
335 test_copy is
336 local
337 s, t: STRING_32
338 do
339 create s.make (10)
340 s.append ("12345")
341 s.copy (s)
342 check_string_equality ("copy", s, "12345")
343
344 s.copy ("1234567890")
345 check_string_equality ("copy", s, "1234567890")
346
347 create s.make (0)
348 t := "12345"
349 s.copy (t)
350 check_equality ("copy", s, t)
351 check_boolean ("copy", not s.shared_with (t))
352 end
353
354 test_ends_with is
355 local
356 s: STRING_32
357 do
358 s := "1234567890"
359 check_boolean ("Ends with empty%N", s.ends_with (""))
360 check_boolean ("Ends with itself%N", s.ends_with (s))
361 check_boolean ("Ends with its twin%N", s.ends_with (s.twin))
362 check_boolean ("Not ends with itself twice%N", not s.ends_with (s + s))
363 check_boolean ("Not ends with 123%N", not s.ends_with ("123"))
364 check_boolean ("Not ends with 23%N", not s.ends_with ("23"))
365 check_boolean ("Ends with 890%N", s.ends_with ("890"))
366 check_boolean ("Not ends with 89%N", not s.ends_with ("89"))
367 end
368
369 test_fill_blank is
370 local
371 s: STRING_32
372 do
373 create s.make (10)
374 s.fill_blank
375 check_string_equality ("fill_blank", s, " ")
376
377 s.wipe_out
378 s.append ("12345")
379 s.fill_blank
380 check_string_equality ("fill_blank", s, " ")
381 end
382
383 test_fill_character is
384 local
385 s: STRING_32
386 do
387 create s.make (10)
388 s.fill_character ('1')
389 check_string_equality ("fill_character", s, "1111111111")
390
391 s.wipe_out
392 s.append ("12345")
393 s.fill_character ('1')
394 check_string_equality ("fill_character", s, "1111111111")
395 end
396
397 test_fill_with is
398 local
399 s: STRING_32
400 do
401 create s.make (10)
402 s.fill_with ('1')
403 check_string_equality ("fill_with", s, "")
404
405 s.wipe_out
406 s.append ("12345")
407 s.fill_with ('1')
408 check_string_equality ("fill_with", s, "11111")
409 end
410
411 test_from_c is
412 local
413 l_ptr: MANAGED_POINTER
414 s: STRING_32
415 do
416 s := "abcdef"
417 create l_ptr.make_from_array ({ARRAY [NATURAL_8]} << 48, 49, 50, 51, 52, 53, 54, 0 >>)
418 s.from_c (l_ptr.item)
419 check_boolean ("from_c", s.is_equal ("0123456"))
420
421 s := "abcdef"
422 create l_ptr.make_from_array ({ARRAY [NATURAL_8]} << 0, 48, 49, 50, 51, 52, 53, 54, 0 >>)
423 s.from_c (l_ptr.item)
424 check_boolean ("from_c", s.is_empty)
425 end
426
427 test_from_c_substring is
428 local
429 l_ptr: MANAGED_POINTER
430 s: STRING_32
431 do
432 create l_ptr.make_from_array ({ARRAY [NATURAL_8]} <<65,66,67,68>>)
433 create s.make (2)
434
435 s.from_c_substring (l_ptr.item, 3, 3)
436 check_boolean ("from_c_substring", s.is_equal ("C"))
437
438 s.from_c_substring (l_ptr.item, 2, 3)
439 check_boolean ("from_c_substring", s.is_equal ("BC"))
440
441 s.from_c_substring (l_ptr.item, 1, 3)
442 check_boolean ("from_c_substring", s.is_equal ("ABC"))
443
444 s.from_c_substring (l_ptr.item, 1, 4)
445 check_boolean ("from_c_substring", s.is_equal ("ABCD"))
446 end
447
448 test_fuzzy_index is
449 local
450 s: STRING_32
451 i: INTEGER
452 do
453 s := "Eiffel Software Enterprise Edition"
454 i := s.fuzzy_index ("Soltware", 1, 1)
455 check_equality ("fuzzy_index", i, 8)
456
457 i := s.fuzzy_index ("Sotware", 1, 1)
458 check_equality ("fuzzy_index", i, 0)
459
460 i := s.fuzzy_index ("Edataon", 10, 2)
461 check_equality ("fuzzy_index", i, 28)
462
463 i := s.fuzzy_index ("Edataon", 29, 2)
464 check_equality ("fuzzy_index", i, 0)
465
466 i := s.fuzzy_index ("Enterprise", 1, 0)
467 check_equality ("fuzzy_index", i, 17)
468
469 i := s.fuzzy_index ("Entreprise", 1, 0)
470 check_equality ("fuzzy_index", i, 0)
471
472 i := s.fuzzy_index ("Enterprise", 1, 0)
473 check_equality ("fuzzy_index", i, 17)
474 end
475
476 test_grow is
477 local
478 s: STRING_32
479 do
480 s := ""
481 s.grow (0)
482 check_string_equality ("grow", s, "")
483 s.grow (5)
484 check_string_equality ("grow", s, "")
485 s := "12345"
486 s.grow (0)
487 check_string_equality ("grow", s, "12345")
488 s.grow (5)
489 check_string_equality ("grow", s, "12345")
490 s.grow (10)
491 check_string_equality ("grow", s, "12345")
492 end
493
494 test_has is
495 local
496 s: STRING_32
497 do
498 create s.make (10)
499 check_boolean ("has", not s.has ('c'))
500 check_boolean ("has", not s.has ('%U'))
501
502 s.append ("1234c1234")
503 check_boolean ("has", s.has ('c'))
504 check_boolean ("has", not s.has ('9'))
505
506 s.wipe_out
507 check_boolean ("has", not s.has ('c'))
508 check_boolean ("has", not s.has ('9'))
509 end
510
511 test_has_substring is
512 local
513 s: STRING_32
514 do
515 create s.make (10)
516 s.append ("!23")
517 check_boolean ("has_substring", s.has_substring (s))
518 check_boolean ("has_substring", s.has_substring ("23"))
519 check_boolean ("has_substring", not s.has_substring ("12"))
520 check_boolean ("has_substring", not s.has_substring ("!23 "))
521 check_boolean ("has_substring", s.has_substring ("!23"))
522
523 check_boolean ("has_substring", ("").has_substring (""))
524 check_boolean ("has_substring", ("foobar").has_substring ("oo"))
525 check_boolean ("has_substring", not ("foobar").has_substring ("abo"))
526 end
527
528 test_hash_code is
529 -- We do not enforce consistent hashcode values, so we only check
530 -- that it is updated properly. See bug#19258.
531 local
532 s: STRING_32
533 h1, h2: INTEGER
534 do
535 s := {STRING_32} "1234c"
536 h1 := s.hash_code
537 h2 := s.case_insensitive_hash_code
538
539 s.append_string ({STRING_32} "1234")
540 check_boolean ("hash_code", s.hash_code /= h1)
541 check_boolean ("case_insensitive_hash_code", s.case_insensitive_hash_code /= h2)
542 end
543
544 test_index_of is
545 local
546 s: STRING_32
547 i: INTEGER
548 do
549 create s.make (10)
550 s.append ("1234567890")
551 i := s.index_of ('0', 1)
552 check_equality ("index_of", i, 10)
553
554 i := s.index_of ('x', 1)
555 check_equality ("index_of", i , 0)
556
557 i := s.index_of ('5', 4)
558 check_equality ("index_of", i , 5)
559
560 i := s.index_of ('5', 5)
561 check_equality ("index_of", i , 5)
562
563 i := s.index_of ('5', 6)
564 check_equality ("index_of", i , 0)
565 end
566
567 test_insert_character is
568 local
569 s: STRING_32
570 do
571 create s.make (10)
572 s.append ("12345")
573 s.insert_character ('c', 1)
574 check_string_equality ("insert_character", s, "c12345")
575
576 s.wipe_out
577 s.append ("12345")
578 s.insert_character ('c', 2)
579 check_string_equality ("insert_character", s, "1c2345")
580
581 s.wipe_out
582 s.append ("12345")
583 s.insert_character ('c', 3)
584 check_string_equality ("insert_character", s, "12c345")
585
586 s.wipe_out
587 s.append ("12345")
588 s.insert_character ('c', 4)
589 check_string_equality ("insert_character", s, "123c45")
590
591 s.wipe_out
592 s.append ("12345")
593 s.insert_character ('c', 5)
594 check_string_equality ("insert_character", s, "1234c5")
595
596 s.wipe_out
597 s.append ("12345")
598 s.insert_character ('c', 6)
599 check_string_equality ("insert_character", s, "12345c")
600 end
601
602 test_insert_string is
603 local
604 s, t: STRING_32
605 do
606 create s.make (10)
607 s.append ("12345")
608 s.insert_string (s, 1)
609 check_string_equality ("insert_string", s, "1234512345")
610
611 s.wipe_out
612 s.append ("12345")
613 s.insert_string (s, 2)
614 check_string_equality ("insert_string", s, "1123452345")
615
616 s.wipe_out
617 s.append ("12345")
618 s.insert_string (s, 3)
619 check_string_equality ("insert_string", s, "1212345345")
620
621 s.wipe_out
622 s.append ("12345")
623 s.insert_string (s, 4)
624 check_string_equality ("insert_string", s, "1231234545")
625
626 s.wipe_out
627 s.append ("12345")
628 s.insert_string (s, 5)
629 check_string_equality ("insert_string", s, "1234123455")
630
631 s.wipe_out
632 s.append ("12345")
633 s.insert_string (s, 6)
634 check_string_equality ("insert_string", s, "1234512345")
635
636 create s.make (10)
637 t := "12345"
638 s.append ("12345")
639 s.insert_string (t, 1)
640 check_string_equality ("insert_string", s, "1234512345")
641
642 s.wipe_out
643 s.append ("12345")
644 s.insert_string (t, 2)
645 check_string_equality ("insert_string", s, "1123452345")
646
647 s.wipe_out
648 s.append ("12345")
649 s.insert_string (t, 3)
650 check_string_equality ("insert_string", s, "1212345345")
651
652 s.wipe_out
653 s.append ("12345")
654 s.insert_string (t, 4)
655 check_string_equality ("insert_string", s, "1231234545")
656
657 s.wipe_out
658 s.append ("12345")
659 s.insert_string (t, 5)
660 check_string_equality ("insert_string", s, "1234123455")
661
662 s.wipe_out
663 s.append ("12345")
664 s.insert_string (t, 6)
665 check_string_equality ("insert_string", s, "1234512345")
666
667 s := "bar"
668 s.insert_string (s, 2)
669 check_string_equality ("insert_string", s, "bbarar")
670
671 s := "abcdef"
672 s.insert_string (s, 3)
673 check_string_equality ("insert_string", s, "ababcdefcdef")
674
675 s := "bar"
676 s.insert_string ("bar", 2)
677 check_string_equality ("insert_string", s, "bbarar")
678 end
679
680 test_is_boolean is
681 local
682 s: STRING_32
683 do
684 s := "true"
685 check_boolean ("is_boolean", s.is_boolean)
686
687 s := " true "
688 check_boolean ("is_boolean", not s.is_boolean)
689
690 s := "True"
691 check_boolean ("is_boolean", s.is_boolean)
692
693 s := "false"
694 check_boolean ("is_boolean", s.is_boolean)
695
696 s := " false "
697 check_boolean ("is_boolean", not s.is_boolean)
698
699 s := "false"
700 check_boolean ("is_boolean", s.is_boolean)
701
702 s := "TRUE"
703 check_boolean ("is_boolean", s.is_boolean)
704
705 s := "FALSE"
706 check_boolean ("is_boolean", s.is_boolean)
707
708 s := "Tru"
709 check_boolean ("is_boolean", not s.is_boolean)
710
711 s := "tru"
712 check_boolean ("is_boolean", not s.is_boolean)
713
714 s := "Fal"
715 check_boolean ("is_boolean", not s.is_boolean)
716
717 s := "fal"
718 check_boolean ("is_boolean", not s.is_boolean)
719 end
720
721 test_is_case_insensitive_equal is
722 local
723 s: STRING_32
724 do
725 create s.make (10)
726 s.append ("12345")
727 check_boolean ("is_case_insensitive_equal", s.is_case_insensitive_equal (s))
728 check_boolean ("is_case_insensitive_equal", s.is_case_insensitive_equal ("12345"))
729 check_boolean ("is_case_insensitive_equal", not s.is_case_insensitive_equal ("123456"))
730 check_boolean ("is_case_insensitive_equal", not s.is_case_insensitive_equal ("1234"))
731
732 s := "abcdef"
733 check_boolean ("is_case_insensitive_equal", s.is_case_insensitive_equal ("ABCDEF"))
734
735 s := "ABCDEF"
736 check_boolean ("is_case_insensitive_equal", s.is_case_insensitive_equal ("abcdef"))
737
738 s := "ABCdef"
739 check_boolean ("is_case_insensitive_equal", s.is_case_insensitive_equal ("abcDEF"))
740
741 check_boolean ("is_case_insensitive_equal", not s.is_case_insensitive_equal (""))
742 end
743
744 test_is_double is
745 do
746 check_boolean ("is_double", ("5").is_double)
747 check_boolean ("is_double", ("5.5").is_double)
748 check_boolean ("is_double", ("5E4").is_double)
749 check_boolean ("is_double", not ("5 E4").is_double)
750 check_boolean ("is_double", ("5e-4").is_double)
751 check_boolean ("is_double", ("5e5").is_double)
752 check_boolean ("is_double", not ("5e 5").is_double)
753 check_boolean ("is_double", (".0").is_double)
754 check_boolean ("is_double", ("0.1e10").is_double)
755 check_boolean ("is_double", ("-1").is_double)
756 check_boolean ("is_double", ("-1.0").is_double)
757 check_boolean ("is_double", ("-1e1").is_double)
758 check_boolean ("is_double", ("-1e-1").is_double)
759 check_boolean ("is_double", ("-1.0e1").is_double)
760 check_boolean ("is_double", ("-1.0e-1").is_double)
761 check_boolean ("is_double", ("-.1").is_double)
762 check_boolean ("is_double", ("1e5").is_double)
763 check_boolean ("is_double", not ("e5").is_double)
764 check_boolean ("is_double", not (".e1").is_double)
765 check_boolean ("is_double", ("1e").is_double)
766 check_boolean ("is_double", ("1e1").is_double)
767 check_boolean ("is_double", (" 5").is_double)
768 check_boolean ("is_double", ("5 ").is_double)
769 check_boolean ("is_double", not ("%U5").is_double)
770 check_boolean ("is_double", not ("5.6%U").is_double)
771 check_boolean ("is_double", ("1").is_double)
772 end
773
774 test_is_empty is
775 local
776 s: STRING_32
777 do
778 create s.make (10)
779 s.append ("Fds")
780 check_boolean ("is_empty", not s.is_empty)
781
782 s.wipe_out
783 check_boolean ("is_empty", s.is_empty)
784
785 check_boolean ("is_empty", ("").is_empty)
786 end
787
788 test_is_equal is
789 local
790 s: STRING_32
791 do
792 create s.make (10)
793 s.append ("12345")
794 check_boolean ("is_equal", s.is_equal (s))
795 check_boolean ("is_equal", s.is_equal ("12345"))
796 check_boolean ("is_equal", not s.is_equal ("123456"))
797 check_boolean ("is_equal", not s.is_equal ("1234"))
798
799 s := "abcdef"
800 check_boolean ("is_equal", not s.is_equal ("ABCDEF"))
801
802 check_boolean ("is_equal", not s.is_equal (""))
803 end
804
805 test_is_inserted is
806 local
807 s: STRING_32
808 do
809 s := "1234"
810 s.extend ('c')
811 check_boolean ("is_inserted", s.is_inserted ('c'))
812 end
813
814 test_is_integer is
815 do
816 check_boolean ("is_integer", not ("a").is_integer)
817 check_boolean ("is_integer", not ("%U1").is_integer)
818 check_boolean ("is_integer", ("1").is_integer)
819 check_boolean ("is_integer", (" 1").is_integer)
820 check_boolean ("is_integer", ("1 ").is_integer)
821 end
822
823 test_is_real is
824 do
825 check_boolean ("is_real", ("5").is_real)
826 check_boolean ("is_real", ("5.5").is_real)
827 check_boolean ("is_real", ("5E4").is_real)
828 check_boolean ("is_real", not ("5 E4").is_real)
829 check_boolean ("is_real", ("5e-4").is_real)
830 check_boolean ("is_real", ("5e5").is_real)
831 check_boolean ("is_real", not ("5e 5").is_real)
832 check_boolean ("is_real", (".0").is_real)
833 check_boolean ("is_real", ("0.1e10").is_real)
834 check_boolean ("is_real", ("-1").is_real)
835 check_boolean ("is_real", ("-1.0").is_real)
836 check_boolean ("is_real", ("-1e1").is_real)
837 check_boolean ("is_real", ("-1e-1").is_real)
838 check_boolean ("is_real", ("-1.0e1").is_real)
839 check_boolean ("is_real", ("-1.0e-1").is_real)
840 check_boolean ("is_real", ("-.1").is_real)
841 check_boolean ("is_real", ("1e5").is_real)
842 check_boolean ("is_real", not ("e5").is_real)
843 check_boolean ("is_real", not (".e1").is_real)
844 check_boolean ("is_real", ("1e").is_real)
845 check_boolean ("is_real", ("1e1").is_real)
846 check_boolean ("is_real", (" 5").is_real)
847 check_boolean ("is_real", ("5 ").is_real)
848 check_boolean ("is_real", not ("%U5").is_real)
849 check_boolean ("is_real", not ("5.6%U").is_real)
850 end
851
852 test_infix_greater is
853 local
854 s: STRING_32
855 p: STRING_32
856 do
857 s := "12345"
858 p := "12345"
859 check_boolean (">", not (s > s))
860 check_boolean (">", not (s > p))
861 p.append_character ('a')
862 check_boolean (">", not (s > p))
863 check_boolean (">", p > s)
864 p := "12045"
865 check_boolean (">", s > p)
866 check_boolean (">", not (p > s))
867 s := "123"
868 check_boolean (">", s > p)
869 check_boolean (">", not (p > s))
870
871 s := ""
872 p := ""
873 check_boolean (">", not (s > s))
874 check_boolean (">", not (s > p))
875 p.append_character ('a')
876 check_boolean (">", not (s > p))
877 check_boolean (">", p > s)
878 end
879
880 test_infix_greater_or_equal is
881 local
882 s: STRING_32
883 p: STRING_32
884 do
885 s := "12345"
886 p := "12345"
887 check_boolean (">=", s >= s)
888 check_boolean (">=", s >= p)
889 p.append_character ('a')
890 check_boolean (">=", not (s >= p))
891 check_boolean (">=", p >= s)
892 p := "12045"
893 check_boolean (">=", s >= p)
894 check_boolean (">=", not (p >= s))
895 s := "123"
896 check_boolean (">=", s >= p)
897 check_boolean (">=", not (p >= s))
898
899 s := ""
900 p := ""
901 check_boolean (">=", s >= s)
902 check_boolean (">=", s >= p)
903 p.append_character ('a')
904 check_boolean (">=", not (s >= p))
905 check_boolean (">=", p >= s)
906 end
907
908 test_infix_less is
909 local
910 s: STRING_32
911 p: STRING_32
912 do
913 s := "12345"
914 p := "12345"
915 check_boolean ("<", not (s < s))
916 check_boolean ("<", not (s < p))
917 p.append_character ('a')
918 check_boolean ("<", s < p)
919 check_boolean ("<", not (p < s))
920 p := "12045"
921 check_boolean ("<", not (s < p))
922 check_boolean ("<", p < s)
923 s := "123"
924 check_boolean ("<", not (s < p))
925 check_boolean ("<", p < s)
926
927 s := ""
928 p := ""
929 check_boolean ("<", not (s < s))
930 check_boolean ("<", not (s < p))
931 p.append_character ('a')
932 check_boolean ("<", s < p)
933 check_boolean ("<", not (p < s))
934 end
935
936 test_infix_less_or_equal is
937 local
938 s: STRING_32
939 p: STRING_32
940 do
941 s := "12345"
942 p := "12345"
943 check_boolean ("<=", s <= s)
944 check_boolean ("<=", s <= p)
945 p.append_character ('a')
946 check_boolean ("<=", s <= p)
947 check_boolean ("<=", not (p <= s))
948 p := "12045"
949 check_boolean ("<=", not (s <= p))
950 check_boolean ("<=", p <= s)
951 s := "123"
952 check_boolean ("<=", not (s <= p))
953 check_boolean ("<=", p <= s)
954
955 s := ""
956 p := ""
957 check_boolean ("<=", s <= s)
958 check_boolean ("<=", s <= p)
959 p.append_character ('a')
960 check_boolean ("<=", s <= p)
961 check_boolean ("<=", not (p <= s))
962 end
963
964 test_infix_plus is
965 local
966 s: STRING_32
967 do
968 s := "12345"
969 check_string_equality ("+", s + s, "1234512345")
970 check_string_equality ("+", "" + "", "")
971 check_string_equality ("+", "" + s, "12345")
972 check_string_equality ("+", s + "", "12345")
973 end
974
975 test_keep_head is
976 local
977 s: STRING_32
978 do
979 s := ""
980 s.keep_head (0)
981 check_string_equality ("keep_head", s, "")
982
983 s := ""
984 s.keep_head (1)
985 check_string_equality ("keep_head", s, "")
986
987 s := "12345"
988 s.keep_head (0)
989 check_string_equality ("keep_head", s, "")
990
991 s := "12345"
992 s.keep_head (1)
993 check_string_equality ("keep_head", s, "1")
994
995 s := "12345"
996 s.keep_head (2)
997 check_string_equality ("keep_head", s, "12")
998
999 s := "12345"
1000 s.keep_head (3)
1001 check_string_equality ("keep_head", s, "123")
1002
1003 s := "12345"
1004 s.keep_head (4)
1005 check_string_equality ("keep_head", s, "1234")
1006
1007 s := "12345"
1008 s.keep_head (5)
1009 check_string_equality ("keep_head", s, "12345")
1010
1011 s := "12345"
1012 s.keep_head (6)
1013 check_string_equality ("keep_head", s, "12345")
1014
1015 s := "12345"
1016 s.keep_head (100)
1017 check_string_equality ("keep_head", s, "12345")
1018 end
1019
1020 test_keep_tail is
1021 local
1022 s: STRING_32
1023 do
1024 s := ""
1025 s.keep_tail (0)
1026 check_string_equality ("keep_tail", s, "")
1027
1028 s := ""
1029 s.keep_tail (1)
1030 check_string_equality ("keep_tail", s, "")
1031
1032 s := "12345"
1033 s.keep_tail (0)
1034 check_string_equality ("keep_tail", s, "")
1035
1036 s := "12345"
1037 s.keep_tail (1)
1038 check_string_equality ("keep_tail", s, "5")
1039
1040 s := "12345"
1041 s.keep_tail (2)
1042 check_string_equality ("keep_tail", s, "45")
1043
1044 s := "12345"
1045 s.keep_tail (3)
1046 check_string_equality ("keep_tail", s, "345")
1047
1048 s := "12345"
1049 s.keep_tail (4)
1050 check_string_equality ("keep_tail", s, "2345")
1051
1052 s := "12345"
1053 s.keep_tail (5)
1054 check_string_equality ("keep_tail", s, "12345")
1055
1056 s := "12345"
1057 s.keep_tail (6)
1058 check_string_equality ("keep_tail", s, "12345")
1059
1060 s := "12345"
1061 s.keep_tail (100)
1062 check_string_equality ("keep_tail", s, "12345")
1063 end
1064
1065 test_last_index_of is
1066 local
1067 s: STRING_32
1068 do
1069 s := "a"
1070 check_equality ("last_boolean", s.last_index_of ('a', 1), 1)
1071 check_equality ("last_boolean", s.last_index_of ('b', 1), 0)
1072
1073 s := "1234554321"
1074 check_equality ("last_boolean", s.last_index_of ('3', 10), 8)
1075 check_equality ("last_boolean", s.last_index_of ('3', 5), 3)
1076 check_equality ("last_boolean", s.last_index_of ('3', 3), 3)
1077 check_equality ("last_boolean", s.last_index_of ('3', 2), 0)
1078 check_equality ("last_boolean", s.last_index_of ('X', 10), 0)
1079 end
1080
1081 test_left_adjust is
1082 local
1083 s: STRING_32
1084 do
1085 s := "12345"
1086 s.left_adjust
1087 check_string_equality ("left_adjust", s, "12345")
1088
1089 s := " %T%T12345"
1090 s.left_adjust
1091 check_string_equality ("left_adjust", s, "12345")
1092
1093 s := "%N %T12345"
1094 s.left_adjust
1095 check_string_equality ("left_adjust", s, "12345")
1096
1097 s := "a 12345"
1098 s.left_adjust
1099 check_string_equality ("left_adjust", s, "a 12345")
1100
1101 s := ""
1102 s.left_adjust
1103 check_string_equality ("left_adjust", s, "")
1104
1105 s := " "
1106 s.left_adjust
1107 check_string_equality ("left_adjust", s, "")
1108
1109 s := "%T"
1110 s.left_adjust
1111 check_string_equality ("left_adjust", s, "")
1112
1113 s := "%N"
1114 s.left_adjust
1115 check_string_equality ("left_adjust", s, "")
1116
1117 s := " %T%N"
1118 s.left_adjust
1119 check_string_equality ("left_adjust", s, "")
1120
1121 s := "%N%T "
1122 s.left_adjust
1123 check_string_equality ("left_adjust", s, "")
1124 end
1125
1126 test_left_justify is
1127 local
1128 s: STRING_32
1129 do
1130 s := "12345"
1131 s.left_justify
1132 check_string_equality ("left_justify", s, "12345")
1133
1134 s := "12345 "
1135 s.left_justify
1136 check_string_equality ("left_justify", s, "12345 ")
1137
1138 s := " 12345 "
1139 s.left_justify
1140 check_string_equality ("left_justify", s, "12345 ")
1141
1142 s := " 12345"
1143 s.left_justify
1144 check_string_equality ("left_justify", s, "12345 ")
1145
1146 s := ""
1147 s.left_justify
1148 check_string_equality ("left_justify", s, "")
1149 end
1150
1151 test_linear_representation is
1152 local
1153 s: STRING_32
1154 l_c: LINEAR [CHARACTER_32]
1155 i: INTEGER
1156 do
1157 s := "12345"
1158 l_c := s.linear_representation
1159 check_boolean ("linear_representation", l_c /= s.linear_representation)
1160 check_boolean ("linear_representation", not s.linear_representation.is_empty)
1161 from
1162 l_c.start
1163 until
1164 l_c.off
1165 loop
1166 i := i + 1
1167 check_boolean ("linear_representation", l_c.item = s.item (i))
1168 l_c.forth
1169 end
1170 check_boolean ("linear_representation", i = 5)
1171 end
1172
1173 test_make is
1174 local
1175 s: STRING_32
1176 p: SPECIAL [CHARACTER_32]
1177 do
1178 s := "1234567890"
1179 p := s.area
1180 s.make (2)
1181 check_boolean ("make", s.is_empty)
1182 check_boolean ("make", s.count = 0)
1183 check_boolean ("make", s.capacity >= 2)
1184 check_boolean ("make", s.area /= p)
1185
1186 create s.make (2)
1187 check_boolean ("make", s.is_empty)
1188 check_boolean ("make", s.count = 0)
1189 check_boolean ("make", s.capacity >= 2)
1190 -- Extra check that there are no aliasing within a STRING_32 creation
1191 check_boolean ("make", s.area /= p)
1192 end
1193
1194 test_make_empty is
1195 local
1196 s: STRING_32
1197 p: SPECIAL [CHARACTER_32]
1198 do
1199 s := "1234567890"
1200 p := s.area
1201 s.make_empty
1202 check_boolean ("make_empty", s.is_empty)
1203 check_boolean ("make_empty", s.count = 0)
1204 check_boolean ("make_empty", s.capacity >= 0)
1205 check_boolean ("make_empty", s.area /= p)
1206
1207 create s.make_empty
1208 check_boolean ("make_empty", s.is_empty)
1209 check_boolean ("make_empty", s.count = 0)
1210 check_boolean ("make_empty", s.capacity >= 0)
1211 -- Extra check that there are no aliasing within a STRING_32 creation
1212 check_boolean ("make_empty", s.area /= p)
1213 end
1214
1215 test_make_filled is
1216 local
1217 s: STRING_32
1218 do
1219 create s.make_filled (' ', 10)
1220 check_boolean ("make_filled", s.count = 10)
1221 check_boolean ("make_filled", s.capacity >= 10)
1222 check_boolean ("make_filled", s.occurrences (' ') = 10)
1223 check_boolean ("make_filled", s.occurrences ('x') = 0)
1224 check_boolean ("make_filled", s.is_equal (" "))
1225
1226 create s.make_filled ('a', 10)
1227 check_boolean ("make_filled", s.count = 10)
1228 check_boolean ("make_filled", s.capacity >= 10)
1229 check_boolean ("make_filled", s.occurrences (' ') = 0)
1230 check_boolean ("make_filled", s.occurrences ('x') = 0)
1231 check_boolean ("make_filled", s.occurrences ('a') = 10)
1232 check_boolean ("make_filled", s.is_equal ("aaaaaaaaaa"))
1233 end
1234
1235 test_make_from_c is
1236 local
1237 l_ptr: MANAGED_POINTER
1238 s: STRING_32
1239 do
1240 create l_ptr.make_from_array ({ARRAY [NATURAL_8]} << 48, 49, 50, 51, 52, 53, 54, 0 >>)
1241 create s.make_from_c (l_ptr.item)
1242 check_boolean ("make_from_c", s.is_equal ("0123456"))
1243
1244 s := "abcdef"
1245 s.make_from_c (l_ptr.item)
1246 check_boolean ("make_from_c", s.is_equal ("0123456"))
1247
1248 create l_ptr.make_from_array ({ARRAY [NATURAL_8]} << 0, 48, 49, 50, 51, 52, 53, 54, 0 >>)
1249 create s.make_from_c (l_ptr.item)
1250 check_boolean ("make_from_c", s.is_empty)
1251
1252 s := "abcdef"
1253 s.make_from_c (l_ptr.item)
1254 check_boolean ("make_from_c", s.is_empty)
1255 end
1256
1257 test_make_from_string is
1258 local
1259 s, p: STRING_32
1260 do
1261 p := "12345"
1262 s := p
1263 s.make_from_string (p)
1264 check_boolean ("make_from_string", s.area = p.area)
1265 check_boolean ("make_from_string", s.count = p.count)
1266
1267 create s.make_from_string (p)
1268 check_boolean ("make_from_string", s.is_equal ("12345"))
1269 check_boolean ("make_from_string", s.area /= p.area)
1270 end
1271
1272 test_max is
1273 local
1274 s: STRING_32
1275 p: STRING_32
1276 do
1277 s := "12345"
1278 p := "12345"
1279 check_boolean ("max", s.max (s) = s)
1280 check_boolean ("max", s.max (p) = s)
1281 check_boolean ("max", p.max (s) = p)
1282 p.append_character ('a')
1283 check_boolean ("max", s.max (p) = p)
1284 check_boolean ("max", p.max (s) = p)
1285 p := "12045"
1286 check_boolean ("max", s.max (p) = s)
1287 check_boolean ("max", p.max (s) = s)
1288
1289 s := ""
1290 p := ""
1291 check_boolean ("max", s.max (s) = s)
1292 check_boolean ("max", s.max (p) = s)
1293 check_boolean ("max", p.max (s) = p)
1294 p.append_character ('a')
1295 check_boolean ("max", s.max (p) = p)
1296 check_boolean ("max", p.max (s) = p)
1297 end
1298
1299 test_min is
1300 local
1301 s: STRING_32
1302 p: STRING_32
1303 do
1304 s := "12345"
1305 p := "12345"
1306 check_boolean ("min", s.min (s) = s)
1307 check_boolean ("min", s.min (p) = s)
1308 check_boolean ("min", p.min (s) = p)
1309 p.append_character ('a')
1310 check_boolean ("min", s.min (p) = s)
1311 check_boolean ("min", p.min (s) = s)
1312 p := "12045"
1313 check_boolean ("min", s.min (p) = p)
1314 check_boolean ("min", p.min (s) = p)
1315
1316 s := ""
1317 p := ""
1318 check_boolean ("min", s.min (s) = s)
1319 check_boolean ("min", s.min (p) = s)
1320 check_boolean ("min", p.min (s) = p)
1321 p.append_character ('a')
1322 check_boolean ("min", s.min (p) = s)
1323 check_boolean ("min", p.min (s) = s)
1324 end
1325
1326 test_mirror is
1327 local
1328 s: STRING_32
1329 do
1330 s := ""
1331 s.mirror
1332 check_string_equality ("mirror", s, "")
1333 s := "a"
1334 s.mirror
1335 check_string_equality ("mirror", s, "a")
1336 s := "ab"
1337 s.mirror
1338 check_string_equality ("mirror", s, "ba")
1339 s := "abc"
1340 s.mirror
1341 check_string_equality ("mirror", s, "cba")
1342 s := "abcd"
1343 s.mirror
1344 check_string_equality ("mirror", s, "dcba")
1345 s := "abcde"
1346 s.mirror
1347 check_string_equality ("mirror", s, "edcba")
1348 end
1349
1350 test_mirrored is
1351 local
1352 s: STRING_32
1353 p: STRING_32
1354 do
1355 s := ""
1356 p := s.mirrored
1357 check_string_equality ("mirrored", s, "")
1358 check_string_equality ("mirrored", p, "")
1359 s := "a"
1360 p := s.mirrored
1361 check_string_equality ("mirrored", s, "a")
1362 check_string_equality ("mirrored", p, "a")
1363 s := "ab"
1364 p := s.mirrored
1365 check_string_equality ("mirrored", s, "ab")
1366 check_string_equality ("mirrored", p, "ba")
1367 s := "abc"
1368 p := s.mirrored
1369 check_string_equality ("mirrored", s, "abc")
1370 check_string_equality ("mirrored", p, "cba")
1371 s := "abcd"
1372 p := s.mirrored
1373 check_string_equality ("mirrored", s, "abcd")
1374 check_string_equality ("mirrored", p, "dcba")
1375 s := "abcde"
1376 p := s.mirrored
1377 check_string_equality ("mirrored", s, "abcde")
1378 check_string_equality ("mirrored", p, "edcba")
1379 end
1380
1381 test_multiply is
1382 local
1383 s: STRING_32
1384 do
1385 s := ""
1386 s.multiply (1)
1387 check_string_equality ("multiply", s, "")
1388 s.multiply (2)
1389 check_string_equality ("multiply", s, "")
1390 s.multiply (3)
1391 check_string_equality ("multiply", s, "")
1392
1393 s := "a"
1394 s.multiply (1)
1395 check_string_equality ("multiply", s, "a")
1396 s := "a"
1397 s.multiply (2)
1398 check_string_equality ("multiply", s, "aa")
1399 s := "a"
1400 s.multiply (3)
1401 check_string_equality ("multiply", s, "aaa")
1402
1403 s := "ab"
1404 s.multiply (1)
1405 check_string_equality ("multiply", s, "ab")
1406 s := "ab"
1407 s.multiply (2)
1408 check_string_equality ("multiply", s, "abab")
1409 s := "ab"
1410 s.multiply (3)
1411 check_string_equality ("multiply", s, "ababab")
1412
1413 s := "abc"
1414 s.multiply (1)
1415 check_string_equality ("multiply", s, "abc")
1416 s := "abc"
1417 s.multiply (2)
1418 check_string_equality ("multiply", s, "abcabc")
1419 s := "abc"
1420 s.multiply (3)
1421 check_string_equality ("multiply", s, "abcabcabc")
1422 end
1423
1424 test_occurrences is
1425 do
1426 check_boolean ("occurrences", ("").occurrences ('%U') = 0)
1427 check_boolean ("occurrences", ("").occurrences (' ') = 0)
1428 check_boolean ("occurrences", ("").occurrences ('a') = 0)
1429 check_boolean ("occurrences", ("%U").occurrences ('%U') = 1)
1430 check_boolean ("occurrences", ("%U").occurrences (' ') = 0)
1431 check_boolean ("occurrences", ("%U").occurrences ('a') = 0)
1432 check_boolean ("occurrences", (" ").occurrences ('%U') = 0)
1433 check_boolean ("occurrences", (" ").occurrences (' ') = 1)
1434 check_boolean ("occurrences", (" ").occurrences ('a') = 0)
1435 check_boolean ("occurrences", ("a").occurrences ('%U') = 0)
1436 check_boolean ("occurrences", ("a").occurrences (' ') = 0)
1437 check_boolean ("occurrences", ("a").occurrences ('a') = 1)
1438 check_boolean ("occurrences", ("%U%U").occurrences ('%U') = 2)
1439 check_boolean ("occurrences", ("%U%U").occurrences (' ') = 0)
1440 check_boolean ("occurrences", ("%U%U").occurrences ('a') = 0)
1441 check_boolean ("occurrences", ("%U ").occurrences ('%U') = 1)
1442 check_boolean ("occurrences", ("%U ").occurrences (' ') = 1)
1443 check_boolean ("occurrences", ("%U ").occurrences ('a') = 0)
1444 check_boolean ("occurrences", (" %U").occurrences ('%U') = 1)
1445 check_boolean ("occurrences", (" %U").occurrences (' ') = 1)
1446 check_boolean ("occurrences", (" %U").occurrences ('a') = 0)
1447 check_boolean ("occurrences", (" ").occurrences ('%U') = 0)
1448 check_boolean ("occurrences", (" ").occurrences (' ') = 2)
1449 check_boolean ("occurrences", (" ").occurrences ('a') = 0)
1450 check_boolean ("occurrences", (" a").occurrences ('%U') = 0)
1451 check_boolean ("occurrences", (" a").occurrences (' ') = 1)
1452 check_boolean ("occurrences", (" a").occurrences ('a') = 1)
1453 check_boolean ("occurrences", ("a ").occurrences ('%U') = 0)
1454 check_boolean ("occurrences", ("a ").occurrences (' ') = 1)
1455 check_boolean ("occurrences", ("a ").occurrences ('a') = 1)
1456 check_boolean ("occurrences", ("aa").occurrences ('%U') = 0)
1457 check_boolean ("occurrences", ("aa").occurrences (' ') = 0)
1458 check_boolean ("occurrences", ("aa").occurrences ('a') = 2)
1459 check_boolean ("occurrences", ("%U%U%U").occurrences ('%U') = 3)
1460 check_boolean ("occurrences", ("%U%U%U").occurrences (' ') = 0)
1461 check_boolean ("occurrences", ("%U%U%U").occurrences ('a') = 0)
1462 check_boolean ("occurrences", (" %U%U").occurrences ('%U') = 2)
1463 check_boolean ("occurrences", (" %U%U").occurrences (' ') = 1)
1464 check_boolean ("occurrences", (" %U%U").occurrences ('a') = 0)
1465 check_boolean ("occurrences", ("%U %U").occurrences ('%U') = 2)
1466 check_boolean ("occurrences", ("%U %U").occurrences (' ') = 1)
1467 check_boolean ("occurrences", ("%U %U").occurrences ('a') = 0)
1468 check_boolean ("occurrences", ("%U%U ").occurrences ('%U') = 2)
1469 check_boolean ("occurrences", ("%U%U ").occurrences (' ') = 1)
1470 check_boolean ("occurrences", ("%U%U ").occurrences ('a') = 0)
1471 check_boolean ("occurrences", ("%U ").occurrences ('%U') = 1)
1472 check_boolean ("occurrences", ("%U ").occurrences (' ') = 2)
1473 check_boolean ("occurrences", ("%U ").occurrences ('a') = 0)
1474 check_boolean ("occurrences", (" %U ").occurrences ('%U') = 1)
1475 check_boolean ("occurrences", (" %U ").occurrences (' ') = 2)
1476 check_boolean ("occurrences", (" %U ").occurrences ('a') = 0)
1477 check_boolean ("occurrences", (" %U").occurrences ('%U') = 1)
1478 check_boolean ("occurrences", (" %U").occurrences (' ') = 2)
1479 check_boolean ("occurrences", (" %U").occurrences ('a') = 0)
1480 check_boolean ("occurrences", (" ").occurrences ('%U') = 0)
1481 check_boolean ("occurrences", (" ").occurrences (' ') = 3)
1482 check_boolean ("occurrences", (" ").occurrences ('a') = 0)
1483 end
1484
1485 test_out is
1486 do
1487 check_string_equality ("out", ("").out, "")
1488 check_string_equality ("out", ("1").out, "1")
1489 check_string_equality ("out", ("12").out, "12")
1490 check_string_equality ("out", ("123").out, "123")
1491 check_string_equality ("out", ("1234").out, "1234")
1492 check_string_equality ("out", ("12345").out, "12345")
1493 end
1494
1495 test_plus is
1496 local
1497 is_32: IMMUTABLE_STRING_32
1498 is_8: IMMUTABLE_STRING_8
1499 s_32: STRING_32
1500 s_8: STRING_8
1501 do
1502 is_32 := "12345"
1503 s_32 := "12345"
1504 is_8 := "67890"
1505 s_8 := "67890"
1506 check_string_equality ("plus", s_32.plus (is_32), "1234512345")
1507 check_string_equality ("plus", s_32.plus (s_32), "1234512345")
1508 check_string_equality ("plus", s_32.plus (is_8), "1234567890")
1509 check_string_equality ("plus", s_32.plus (s_8), "1234567890")
1510 check_string_equality ("plus", s_32.plus (""), "12345")
1511
1512 s_32 := ""
1513 check_string_equality ("plus", s_32.plus (is_32), "12345")
1514 check_string_equality ("plus", s_32.plus (s_32), "")
1515 check_string_equality ("plus", s_32.plus (is_8), "67890")
1516 check_string_equality ("plus", s_32.plus (s_8), "67890")
1517 check_string_equality ("plus", s_32.plus (""), "")
1518
1519 is_32 := ""
1520 is_8 := ""
1521 s_8 := ""
1522 check_string_equality ("plus", s_32.plus (is_32), "")
1523 check_string_equality ("plus", s_32.plus (s_32), "")
1524 check_string_equality ("plus", s_32.plus (is_8), "")
1525 check_string_equality ("plus", s_32.plus (s_8), "")
1526 check_string_equality ("plus", s_32.plus (""), "")
1527 end
1528
1529 test_precede is
1530 local
1531 s: STRING_32
1532 do
1533 s := ""
1534 s.precede ('%U')
1535 check_string_equality ("precede", s, "%U")
1536 s.precede ('a')
1537 check_string_equality ("precede", s, "a%U")
1538 s.precede ('%N')
1539 check_string_equality ("precede", s, "%Na%U")
1540 end
1541
1542 test_prepend is
1543 -- Perform test on `prepend'.
1544 local
1545 s: STRING_32
1546 do
1547 s := ""
1548 s.prepend (s)
1549 check_string_equality ("prepend", s, "")
1550 s.prepend ("")
1551 check_string_equality ("prepend", s, "")
1552 s.prepend ("abc")
1553 check_string_equality ("prepend", s, "abc")
1554 s.prepend ("")
1555 check_string_equality ("prepend", s, "abc")
1556
1557 s := "bar"
1558 s.prepend (s)
1559 check_string_equality ("prepend", s, "barbar")
1560
1561 s := "bar"
1562 s.prepend ("bar")
1563 check_string_equality ("prepend", s, "barbar")
1564 end
1565
1566 test_prepend_boolean is
1567 local
1568 s: STRING_32
1569 do
1570 s := ""
1571 s.prepend_boolean (true)
1572 check_string_equality ("prepend_boolean", s, "True")
1573 s := ""
1574 s.prepend_boolean (false)
1575 check_string_equality ("prepend_boolean", s, "False")
1576 s.prepend_boolean (true)
1577 check_string_equality ("prepend_boolean", s, "TrueFalse")
1578 s.prepend_boolean (false)
1579 check_string_equality ("prepend_boolean", s, "FalseTrueFalse")
1580 end
1581
1582 test_prepend_character is
1583 local
1584 s: STRING_32
1585 do
1586 s := ""
1587 s.prepend_character ('%U')
1588 check_string_equality ("prepend_character", s, "%U")
1589 s.prepend_character ('a')
1590 check_string_equality ("prepend_character", s, "a%U")
1591 s.prepend_character (' ')
1592 check_string_equality ("prepend_character", s, " a%U")
1593 s.prepend_character ('%N')
1594 check_string_equality ("prepend_character", s, "%N a%U")
1595 end
1596
1597 test_prepend_double is
1598 local
1599 s: STRING_32
1600 do
1601 s := ""
1602 s.prepend_double (0)
1603 check_string_equality ("prepend_double", s, "0")
1604 s.prepend_double (1)
1605 check_string_equality ("prepend_double", s, "10")
1606 s.prepend_double (0.5)
1607 check_string_equality ("prepend_double", s, "0.510")
1608 s.prepend_double (-0.5)
1609 check_string_equality ("prepend_double", s, "-0.50.510")
1610 end
1611
1612 test_prepend_integer is
1613 local
1614 s: STRING_32
1615 do
1616 s := ""
1617 s.prepend_integer (0)
1618 check_string_equality ("prepend_integer", s, "0")
1619 s.prepend_integer (1)
1620 check_string_equality ("prepend_integer", s, "10")
1621 s.prepend_integer (-0x8000_0000)
1622 check_string_equality ("prepend_integer", s, "-214748364810")
1623 s.prepend_integer (-0x7FFF_FFFF)
1624 check_string_equality ("prepend_integer", s, "-2147483647-214748364810")
1625 s.prepend_integer (0x7FFF_FFFF)
1626 check_string_equality ("prepend_integer", s, "2147483647-2147483647-214748364810")
1627 end
1628
1629 test_prepend_real is
1630 local
1631 s: STRING_32
1632 do
1633 s := ""
1634 s.prepend_real (0)
1635 check_string_equality ("prepend_real", s, "0")
1636 s.prepend_real (1)
1637 check_string_equality ("prepend_real", s, "10")
1638 s.prepend_real ({REAL_32} 0.5)
1639 check_string_equality ("prepend_real", s, "0.510")
1640 s.prepend_real ({REAL_32} -0.5)
1641 check_string_equality ("prepend_real", s, "-0.50.510")
1642 end
1643
1644
1645 test_prepend_string is
1646 local
1647 s: STRING_32
1648 do
1649 s := ""
1650 s.prepend (s)
1651 check_string_equality ("prepend", s, "")
1652 s.prepend ("")
1653 check_string_equality ("prepend", s, "")
1654 s.prepend ("abc")
1655 check_string_equality ("prepend", s, "abc")
1656 s.prepend ("")
1657 check_string_equality ("prepend", s, "abc")
1658
1659 s := "bar"
1660 s.prepend (s)
1661 check_string_equality ("prepend", s, "barbar")
1662
1663 s := "bar"
1664 s.prepend ("bar")
1665 check_string_equality ("prepend", s, "barbar")
1666 end
1667
1668 test_prunable is
1669 do
1670 check_boolean ("prunable", ("").prunable)
1671 check_boolean ("prunable", ("%U").prunable)
1672 check_boolean ("prunable", ("abc").prunable)
1673 end
1674
1675 test_prune is
1676 local
1677 s: STRING_32
1678 do
1679 s := ""
1680 s.prune ('%U')
1681 check_string_equality ("prune", s, "")
1682 s.prune ('a')
1683 check_string_equality ("prune", s, "")
1684 s := "%Ua%Ua%Na%U"
1685 s.prune ('%U')
1686 check_string_equality ("prune", s, "a%Ua%Na%U")
1687 s.prune ('%U')
1688 check_string_equality ("prune", s, "aa%Na%U")
1689 s.prune ('%U')
1690 check_string_equality ("prune", s, "aa%Na")
1691 s.prune ('%U')
1692 check_string_equality ("prune", s, "aa%Na")
1693 s := "%Ua%Ua%Na%U"
1694 s.prune ('a')
1695 check_string_equality ("prune", s, "%U%Ua%Na%U")
1696 s.prune ('a')
1697 check_string_equality ("prune", s, "%U%U%Na%U")
1698 s.prune ('a')
1699 check_string_equality ("prune", s, "%U%U%N%U")
1700 s.prune ('a')
1701 check_string_equality ("prune", s, "%U%U%N%U")
1702 s := "%Ua%Ua%Na%U"
1703 s.prune ('%N')
1704 check_string_equality ("prune", s, "%Ua%Uaa%U")
1705 s.prune ('%N')
1706 check_string_equality ("prune", s, "%Ua%Uaa%U")
1707 end
1708
1709 test_prune_all is
1710 local
1711 s: STRING_32
1712 do
1713 s := ""
1714 s.prune_all ('%U')
1715 check_string_equality ("prune_all", s, "")
1716 s.prune_all ('a')
1717 check_string_equality ("prune_all", s, "")
1718 s := "%Ua%Ua%Na%U"
1719 s.prune_all ('%U')
1720 check_string_equality ("prune_all", s, "aa%Na")
1721 s.prune_all ('%U')
1722 check_string_equality ("prune_all", s, "aa%Na")
1723 s := "%Ua%Ua%Na%U"
1724 s.prune_all ('a')
1725 check_string_equality ("prune_all", s, "%U%U%N%U")
1726 s.prune_all ('a')
1727 check_string_equality ("prune_all", s, "%U%U%N%U")
1728 s := "%Ua%Ua%Na%U"
1729 s.prune_all ('%N')
1730 check_string_equality ("prune_all", s, "%Ua%Uaa%U")
1731 s.prune_all ('%N')
1732 check_string_equality ("prune_all", s, "%Ua%Uaa%U")
1733 end
1734
1735 test_prune_all_leading is
1736 local
1737 s: STRING_32
1738 do
1739 s := ""
1740 s.prune_all_leading ('%U')
1741 check_string_equality ("prune_all_leading", s, "")
1742 s.prune_all_leading ('a')
1743 check_string_equality ("prune_all_leading", s, "")
1744 s := "%U%U%U"
1745 s.prune_all_leading ('a')
1746 check_string_equality ("prune_all_leading", s, "%U%U%U")
1747 s.prune_all_leading ('%U')
1748 check_string_equality ("prune_all_leading", s, "")
1749 s := "aaa"
1750 s.prune_all_leading ('%U')
1751 check_string_equality ("prune_all_leading", s, "aaa")
1752 s.prune_all_leading ('a')
1753 check_string_equality ("prune_all_leading", s, "")
1754 s := "%U%Ua%Ua%Na%U"
1755 s.prune_all_leading ('a')
1756 check_string_equality ("prune_all_leading", s, "%U%Ua%Ua%Na%U")
1757 s.prune_all_leading ('%U')
1758 check_string_equality ("prune_all_leading", s, "a%Ua%Na%U")
1759 s.prune_all_leading ('%U')
1760 check_string_equality ("prune_all_leading", s, "a%Ua%Na%U")
1761 s.prune_all_leading ('a')
1762 check_string_equality ("prune_all_leading", s, "%Ua%Na%U")
1763 end
1764
1765 test_prune_all_trailing is
1766 local
1767 s: STRING_32
1768 do
1769 s := ""
1770 s.prune_all_trailing ('%U')
1771 check_string_equality ("prune_all_trailing", s, "")
1772 s.prune_all_trailing ('a')
1773 check_string_equality ("prune_all_trailing", s, "")
1774 s := "%U%U%U"
1775 s.prune_all_trailing ('a')
1776 check_string_equality ("prune_all_trailing", s, "%U%U%U")
1777 s.prune_all_trailing ('%U')
1778 check_string_equality ("prune_all_trailing", s, "")
1779 s := "aaa"
1780 s.prune_all_trailing ('%U')
1781 check_string_equality ("prune_all_trailing", s, "aaa")
1782 s.prune_all_trailing ('a')
1783 check_string_equality ("prune_all_trailing", s, "")
1784 s := "%U%Ua%Ua%Na%U%U"
1785 s.prune_all_trailing ('a')
1786 check_string_equality ("prune_all_trailing", s, "%U%Ua%Ua%Na%U%U")
1787 s.prune_all_trailing ('%U')
1788 check_string_equality ("prune_all_trailing", s, "%U%Ua%Ua%Na")
1789 s.prune_all_trailing ('%U')
1790 check_string_equality ("prune_all_trailing", s, "%U%Ua%Ua%Na")
1791 s.prune_all_trailing ('a')
1792 check_string_equality ("prune_all_trailing", s, "%U%Ua%Ua%N")
1793 end
1794
1795 test_put is
1796 local
1797 s: STRING_32
1798 do
1799 s := "a"
1800 s.put ('%U', 1)
1801 check_string_equality ("put", s, "%U")
1802 s := "12345"
1803 s.put ('c', 3)
1804 s.put ('b', 2)
1805 s.put ('e', 5)
1806 s.put ('d', 4)
1807 s.put ('a', 1)
1808 check_string_equality ("put", s, "abcde")
1809 s.put ('%U', 3)
1810 check_string_equality ("put", s, "ab%Ude")
1811 s.put ('3', 3)
1812 check_string_equality ("put", s, "ab3de")
1813 end
1814
1815 test_remove is
1816 local
1817 s: STRING_32
1818 do
1819 s := "12345"
1820 s.remove (3)
1821 check_string_equality ("remove", s, "1245")
1822 s.remove (4)
1823 check_string_equality ("remove", s, "124")
1824 s.remove (1)
1825 check_string_equality ("remove", s, "24")
1826 s.remove (2)
1827 check_string_equality ("remove", s, "2")
1828 s.remove (1)
1829 check_string_equality ("remove", s, "")
1830 end
1831
1832 test_remove_head is
1833 local
1834 s: STRING_32
1835 do
1836 s := ""
1837 s.remove_head (2)
1838 check_string_equality ("remove_head", s, "")
1839 s := "12345"
1840 s.remove_head (1)
1841 check_string_equality ("remove_head", s, "2345")
1842 s.remove_head (2)
1843 check_string_equality ("remove_head", s, "45")
1844 s.remove_head (3)
1845 check_string_equality ("remove_head", s, "")
1846 s := "12345"
1847 s.remove_head (5)
1848 check_string_equality ("remove_head", s, "")
1849 end
1850
1851 test_remove_substring is
1852 local
1853 s: STRING_32
1854 do
1855 s := ""
1856 s.remove_substring (1, 0)
1857 check_string_equality ("remove_substring", s, "")
1858 s := "12345"
1859 s.remove_substring (1, 0)
1860 check_string_equality ("remove_substring", s, "12345")
1861 s.remove_substring (2, 1)
1862 check_string_equality ("remove_substring", s, "12345")
1863 s.remove_substring (5, 4)
1864 check_string_equality ("remove_substring", s, "12345")
1865 s.remove_substring (6, 5)
1866 check_string_equality ("remove_substring", s, "12345")
1867 s.remove_substring (1, 1)
1868 check_string_equality ("remove_substring", s, "2345")
1869 s.remove_substring (1, 2)
1870 check_string_equality ("remove_substring", s, "45")
1871 s.remove_substring (1, 2)
1872 check_string_equality ("remove_substring", s, "")
1873 s := "12345"
1874 s.remove_substring (2, 2)
1875 check_string_equality ("remove_substring", s, "1345")
1876 s.remove_substring (2, 4)
1877 check_string_equality ("remove_substring", s, "1")
1878 s.remove_substring (1, 1)
1879 check_string_equality ("remove_substring", s, "")
1880 end
1881
1882 test_remove_tail is
1883 local
1884 s: STRING_32
1885 do
1886 s := ""
1887 s.remove_tail (2)
1888 check_string_equality ("remove_tail", s, "")
1889 s := "12345"
1890 s.remove_tail (1)
1891 check_string_equality ("remove_tail", s, "1234")
1892 s.remove_tail (2)
1893 check_string_equality ("remove_tail", s, "12")
1894 s.remove_tail (3)
1895 check_string_equality ("remove_tail", s, "")
1896 s := "12345"
1897 s.remove_tail (5)
1898 check_string_equality ("remove_tail", s, "")
1899 end
1900
1901 test_replace_blank is
1902 local
1903 s: STRING_32
1904 do
1905 s := ""
1906 s.replace_blank
1907 check_string_equality ("replace_blank", s, "")
1908 s := "1"
1909 s.replace_blank
1910 check_string_equality ("replace_blank", s, " ")
1911 s := "a%Ub%Uc%U"
1912 s.replace_blank
1913 check_string_equality ("replace_blank", s, " ")
1914 end
1915
1916 test_replace_substring is
1917 -- Perform test on `replace_substring'.
1918 local
1919 s: STRING_32
1920 do
1921 s := "foobar"
1922 s.replace_substring (s, 4, 6)
1923 check_string_equality ("replace_substring", s, "foofoobar")
1924
1925 s := "foobar"
1926 s.replace_substring ("foobar", 4, 6)
1927 check_string_equality ("replace_substring", s, "foofoobar")
1928 end
1929
1930 test_replace_substring_all is
1931 local
1932 s: STRING_32
1933 do
1934 s := "EiffelSoftware Entreprise Edition_5.5"
1935 s.replace_substring_all (" ", "_")
1936 check_string_equality ("replace_substring_all", s, "EiffelSoftware_ Entreprise Edition_5.5")
1937
1938 s := " EiffelSoftware Entreprise Edition_5.5 "
1939 s.replace_substring_all (" ", "_")
1940 check_string_equality ("replace_substring_all", s, "_ EiffelSoftware_ Entreprise_ Edition_5.5_ ")
1941
1942 s := " EiffelSoftware Entreprise Edition_5.5 "
1943 s.replace_substring_all (" ", "___")
1944 check_string_equality ("replace_substring_all", s, "_________EiffelSoftware_________Entreprise_________Edition_5.5_________")
1945 end
1946
1947 test_resizable is
1948 do
1949 check_boolean ("resizable", ("").resizable)
1950 check_boolean ("resizable", ("1").resizable)
1951 check_boolean ("resizable", ("12").resizable)
1952 check_boolean ("resizable", ("123").resizable)
1953 end
1954
1955 test_resize is
1956 local
1957 s: STRING_32
1958 do
1959 s := ""
1960 s.resize (0)
1961 check_string_equality ("resize", s, "")
1962 s.resize (5)
1963 check_string_equality ("resize", s, "")
1964 s := "12345"
1965 s.resize (5)
1966 check_string_equality ("resize", s, "12345")
1967 s.resize (10)
1968 check_string_equality ("resize", s, "12345")
1969 end
1970
1971 test_right_adjust is
1972 local
1973 s: STRING_32
1974 do
1975 s := ""
1976 s.right_adjust
1977 check_string_equality ("right_adjust", s, "")
1978 s := "%/9/%/10/%/11/%/12/%/13/ "
1979 s.right_adjust
1980 check_string_equality ("right_adjust", s, "")
1981 s := "abc%/9/%/10/%/11/%/12/%/13/ "
1982 s.right_adjust
1983 check_string_equality ("right_adjust", s, "abc")
1984 s := "%/9/%/10/%/11/%/12/%/13/ abc"
1985 s.right_adjust
1986 check_string_equality ("right_adjust", s, "%/9/%/10/%/11/%/12/%/13/ abc")
1987 end
1988
1989 test_right_justify is
1990 local
1991 s: STRING_32
1992 do
1993 s := ""
1994 s.right_justify
1995 check_string_equality ("right_justify", s, "")
1996 s := "12345"
1997 s.right_justify
1998 check_string_equality ("right_justify", s, "12345")
1999 s := "abc%/9/%/10/%/11/%/12/%/13/ "
2000 s.right_justify
2001 check_string_equality ("right_justify", s, " abc")
2002 s := "%/9/%/10/%/11/%/12/%/13/ abc"
2003 s.right_justify
2004 check_string_equality ("right_justify", s, "%/9/%/10/%/11/%/12/%/13/ abc")
2005 s := "%/9/%/10/%/11/%/12/%/13/ abc%/9/%/10/%/11/%/12/%/13/ "
2006 s.right_justify
2007 check_string_equality ("right_justify", s, " %/9/%/10/%/11/%/12/%/13/ abc")
2008 end
2009
2010 test_same_string is
2011 local
2012 s: STRING_32
2013 do
2014 s := ""
2015 check_boolean ("same_string", s.same_string (s))
2016 check_boolean ("same_string", s.same_string (""))
2017
2018 s := "12345"
2019 check_boolean ("same_string", s.same_string (s))
2020 check_boolean ("same_string", s.same_string ("12345"))
2021 check_boolean ("same_string", not s.same_string ("123456"))
2022 check_boolean ("same_string", not s.same_string ("123"))
2023 check_boolean ("same_string", not s.same_string (""))
2024
2025 s := "abcdef"
2026 check_boolean ("same_string", not s.same_string ("ABCDEF"))
2027 end
2028
2029 test_same_characters is
2030 local
2031 s: STRING_32
2032 o: STRING_32
2033 do
2034 s := "12345"
2035 o := "234"
2036 check_boolean ("same_characters", s.same_characters (o, 1, 3, 2))
2037 check_boolean ("same_characters", o.same_characters (s, 2, 4, 1))
2038 o := "432"
2039 check_boolean ("same_characters", not s.same_characters (o, 1, 3, 2))
2040 check_boolean ("same_characters", not o.same_characters (s, 2, 4, 1))
2041
2042 s := "abcdef"
2043 o := "BCD"
2044 check_boolean ("same_characters", not s.same_characters (o, 1, 2, 2))
2045 end
2046
2047 test_same_caseless_characters is
2048 local
2049 s: STRING_32
2050 o: STRING_32
2051 do
2052 s := "12345"
2053 o := "234"
2054 check_boolean ("same_caseless_characters", s.same_caseless_characters (o, 1, 3, 2))
2055 check_boolean ("same_caseless_characters", o.same_caseless_characters (s, 2, 4, 1))
2056 o := "432"
2057 check_boolean ("same_caseless_characters", not s.same_caseless_characters (o, 1, 3, 2))
2058 check_boolean ("same_caseless_characters", not o.same_caseless_characters (s, 2, 4, 1))
2059
2060 s := "abcdef"
2061 o := "BCD"
2062 check_boolean ("same_caseless_characters", s.same_caseless_characters (o, 1, 2, 2))
2063 check_boolean ("same_caseless_characters", not s.same_caseless_characters (o, 1, 2, 3))
2064 end
2065
2066 test_same_type is
2067 do
2068 check_boolean ("same_type", ("").same_type (create {STRING_8}.make_empty))
2069 check_boolean ("same_type", ("").same_type (create {STRING_8}.make (10)))
2070 check_boolean ("same_type", ("").same_type ("12345"))
2071 end
2072
2073 test_set is
2074 local
2075 s: STRING_32
2076 do
2077 s := ""
2078 s.set ("", 1, 0)
2079 check_string_equality ("set", s, "")
2080 s.set ("", 1, 10)
2081 check_string_equality ("set", s, "")
2082 s.set ("", 10, 1000)
2083 check_string_equality ("set", s, "")
2084 s.set ("123", 10, 100)
2085 check_string_equality ("set", s, "")
2086 s.set ("123", 1, 0)
2087 check_string_equality ("set", s, "")
2088 s.set ("123", 1, -120)
2089 check_string_equality ("set", s, "")
2090 s.set ("123", 3, 0)
2091 check_string_equality ("set", s, "")
2092 s.set ("123", 4, 4)
2093 check_string_equality ("set", s, "")
2094 s.set ("123", 2, 2)
2095 check_string_equality ("set", s, "2")
2096 s.set ("12345", -100, 100)
2097 check_string_equality ("set", s, "") -- Current implementation assumes that out-of-range indexes result in empty string
2098 s.set ("12345", 1, 5)
2099 check_string_equality ("set", s, "12345")
2100 s.set ("12345", 1, 3)
2101 check_string_equality ("set", s, "123")
2102 s.set ("12345", 3, 5)
2103 check_string_equality ("set", s, "345")
2104 end
2105
2106 test_share is
2107 local
2108 s: STRING_32
2109 p: STRING_32
2110 do
2111 s := ""
2112 p := "12345"
2113 s.share (p)
2114 check_string_equality ("share", s, "12345")
2115 p.remove_head (5)
2116 check_string_equality ("share", p, "")
2117 check_string_equality ("share", s, "12345")
2118 p.append_string ("abcde")
2119 check_string_equality ("share", p, "abcde")
2120 check_string_equality ("share", s, "abcde")
2121 end
2122
2123 test_shared_with is
2124 local
2125 s: STRING_32
2126 p: STRING_32
2127 do
2128 s := ""
2129 check_boolean ("shared_with", not s.shared_with (""))
2130 p := "12345"
2131 check_boolean ("shared_with", not s.shared_with (p))
2132 s.share (p)
2133 check_boolean ("shared_with", s.shared_with (p))
2134 -- `append_string' does not take sharing into account
2135 -- p.append_string ("abc")
2136 -- check_boolean ("shared_with", s.shared_with (p))
2137 p.make_empty
2138 check_boolean ("shared_with", not s.shared_with (p))
2139 end
2140
2141 test_split is
2142 local
2143 s: STRING_32
2144 l: LIST [STRING_32]
2145 do
2146 s := ""
2147 l := s.split ('%U')
2148 check_equality ("split", l.count, 1)
2149 check_string_equality ("split", l [1], "")
2150 s := "1234543212345"
2151 l := s.split ('%U')
2152 check_equality ("split", l.count, 1)
2153 check_string_equality ("split", l [1], "1234543212345")
2154 l := s.split ('6')
2155 check_equality ("split", l.count, 1)
2156 check_string_equality ("split", l [1], "1234543212345")
2157 l := s.split ('1')
2158 check_equality ("split", l.count, 3)
2159 check_string_equality ("split", l [1], "")
2160 check_string_equality ("split", l [2], "2345432")
2161 check_string_equality ("split", l [3], "2345")
2162 l := s.split ('2')
2163 check_equality ("split", l.count, 4)
2164 check_string_equality ("split", l [1], "1")
2165 check_string_equality ("split", l [2], "34543")
2166 check_string_equality ("split", l [3], "1")
2167 check_string_equality ("split", l [4], "345")
2168 l := s.split ('5')
2169 check_equality ("split", l.count, 3)
2170 check_string_equality ("split", l [1], "1234")
2171 check_string_equality ("split", l [2], "4321234")
2172 check_string_equality ("split", l [3], "")
2173 end
2174
2175 test_starts_with is
2176 local
2177 s: STRING_32
2178 do
2179 s := "1234567890"
2180 check_boolean ("Starts with empty%N", s.starts_with (""))
2181 check_boolean ("Starts with itself%N", s.starts_with (s))
2182 check_boolean ("Starts with its twin%N", s.starts_with (s.twin))
2183 check_boolean ("Not starts with itself twice%N", not s.starts_with (s + s))
2184 check_boolean ("Starts with 123%N", s.starts_with ("123"))
2185 check_boolean ("Not starts with 23%N", not s.starts_with ("23"))
2186 check_boolean ("Not starts with 890%N", not s.starts_with ("890"))
2187 check_boolean ("Not starts with 89%N", not s.starts_with ("89"))
2188 end
2189
2190 test_string is
2191 local
2192 s: STRING_32
2193 do
2194 s := ""
2195 check_boolean ("string", s.string /= s)
2196 check_equality ("string", s.string, s)
2197 check_boolean ("string", not s.string.shared_with (s))
2198 s := "12345"
2199 check_boolean ("string", s.string /= s)
2200 check_equality ("string", s.string, s)
2201 check_boolean ("string", not s.string.shared_with (s))
2202 end
2203
2204 test_subcopy is
2205 -- Perform test on `subcopy'.
2206 local
2207 s: STRING_32
2208 do
2209 s := "foobarfoobar"
2210 s.subcopy (s, 2, 3, 5)
2211 check_string_equality ("subcopy", s, "fooboofoobar")
2212
2213 s := "foobarfoobar"
2214 s.subcopy ("foobarfoobar", 2, 3, 5)
2215 check_string_equality ("subcopy", s, "fooboofoobar")
2216
2217 s := "foobarfoobar"
2218 s.subcopy (s, 4, 6, 7)
2219 check_string_equality ("subcopy", s, "foobarbarbar")
2220
2221 s := "foobarfoobar"
2222 s.subcopy (s, 4, 6, 2)
2223 check_string_equality ("subcopy", s, "fbararfoobar")
2224 end
2225
2226 test_substring is
2227 local
2228 s: STRING_32
2229 do
2230 s := ""
2231 check_string_equality ("substring", s.substring (100, 1000), "")
2232 check_string_equality ("substring", s.substring (-1, 1), "")
2233 check_string_equality ("substring", s.substring (1, 1), "")
2234 check_string_equality ("substring", s.substring (1, 0), "")
2235 s := "12345"
2236 check_string_equality ("substring", s.substring (100, 1000), "")
2237 check_string_equality ("substring", s.substring (-1, 0), "")
2238 check_string_equality ("substring", s.substring (-1, 1), "") -- Current implementation assumes that out-of-range indexes result in empty string
2239 check_string_equality ("substring", s.substring (1, 0), "")
2240 check_string_equality ("substring", s.substring (1, 5), "12345")
2241 check_string_equality ("substring", s.substring (3, 5), "345")
2242 check_string_equality ("substring", s.substring (3, 10), "") -- Current implementation assumes that out-of-range indexes result in empty string
2243 check_string_equality ("substring", s.substring (-100, 100), "") -- Current implementation assumes that out-of-range indexes result in empty string
2244 end
2245
2246 test_substring_index is
2247 -- Perform test on `substring_index'.
2248 local
2249 s: STRING_32
2250 do
2251 s := "foo"
2252 check_equality ("substring_index", s.substring_index ("", 1), 1)
2253 check_equality ("substring_index", s.substring_index ("", 4), 4)
2254
2255 s := "foobarfoobar"
2256 check_equality ("substring_index", s.substring_index ("bar", 1), 4)
2257 check_equality ("substring_index", s.substring_index ("bar", 4), 4)
2258 check_equality ("substring_index", s.substring_index ("bar", 5), 10)
2259 check_equality ("substring_index", s.substring_index ("bar", 11), 0)
2260 end
2261
2262 test_substring_index_in_bounds is
2263 local
2264 s: STRING_32
2265 do
2266 s := "foo"
2267 check_equality ("substring_index_in_bounds", s.substring_index_in_bounds ("f", 1, 1), 1)
2268 check_equality ("substring_index_in_bounds", s.substring_index_in_bounds ("f", 1, 3), 1)
2269 check_equality ("substring_index_in_bounds", s.substring_index_in_bounds ("f", 2, 3), 0)
2270 check_equality ("substring_index_in_bounds", s.substring_index_in_bounds ("o", 1, 3), 2)
2271 check_equality ("substring_index_in_bounds", s.substring_index_in_bounds ("o", 2, 3), 2)
2272 check_equality ("substring_index_in_bounds", s.substring_index_in_bounds ("o", 3, 3), 3)
2273
2274 s := "foobarfoobar"
2275 check_equality ("substring_index_in_bounds", s.substring_index_in_bounds ("bar", 1, 5), 0)
2276 check_equality ("substring_index_in_bounds", s.substring_index_in_bounds ("bar", 1, 6), 4)
2277 check_equality ("substring_index_in_bounds", s.substring_index_in_bounds ("bar", 3, 6), 4)
2278 check_equality ("substring_index_in_bounds", s.substring_index_in_bounds ("bar", 4, 6), 4)
2279 check_equality ("substring_index_in_bounds", s.substring_index_in_bounds ("bar", 4, 10), 4)
2280 check_equality ("substring_index_in_bounds", s.substring_index_in_bounds ("bar", 5, 6), 0)
2281 check_equality ("substring_index_in_bounds", s.substring_index_in_bounds ("bar", 5, 8), 0)
2282 check_equality ("substring_index_in_bounds", s.substring_index_in_bounds ("bar", 5, 11), 0)
2283 check_equality ("substring_index_in_bounds", s.substring_index_in_bounds ("bar", 5, 12), 10)
2284 check_equality ("substring_index_in_bounds", s.substring_index_in_bounds ("bar", 11, 12), 0)
2285 end
2286
2287 test_tagged_out is
2288 do
2289 check_boolean ("tagged_out", ("").tagged_out /= Void)
2290 check_boolean ("tagged_out", not equal (("").tagged_out, ""))
2291 check_boolean ("tagged_out", ("12345").tagged_out /= Void)
2292 check_boolean ("tagged_out", not equal (("12345").tagged_out, ""))
2293 end
2294
2295 test_three_way_comparison is
2296 local
2297 s: STRING_32
2298 p: STRING_32
2299 do
2300 s := "12345"
2301 p := "12345"
2302 check_boolean ("three_way_comparison", s.three_way_comparison (s) = 0)
2303 check_boolean ("three_way_comparison", s.three_way_comparison (p) = 0)
2304 p.append_character ('a')
2305 check_boolean ("three_way_comparison", s.three_way_comparison (p) = -1)
2306 check_boolean ("three_way_comparison", p.three_way_comparison (s) = 1)
2307 p := "12045"
2308 check_boolean ("three_way_comparison", s.three_way_comparison (p) = 1)
2309 check_boolean ("three_way_comparison", p.three_way_comparison (s) = -1)
2310 s := "123"
2311 check_boolean ("three_way_comparison", s.three_way_comparison (p) = 1)
2312 check_boolean ("three_way_comparison", p.three_way_comparison (s) = -1)
2313
2314 s := ""
2315 p := ""
2316 check_boolean ("three_way_comparison", s.three_way_comparison (s) = 0)
2317 check_boolean ("three_way_comparison", s.three_way_comparison (p) = 0)
2318 p.append_character ('a')
2319 check_boolean ("three_way_comparison", s.three_way_comparison (p) = -1)
2320 check_boolean ("three_way_comparison", p.three_way_comparison (s) = 1)
2321 end
2322
2323 test_to_c is
2324 do
2325 if not {PLATFORM}.is_dotnet then
2326 check_boolean ("to_c", ("").to_c /= Void)
2327 check_boolean ("to_c", ("123").to_c /= Void)
2328 end
2329 end
2330
2331 test_to_cil is
2332 do
2333 if {PLATFORM}.is_dotnet then
2334 check_boolean ("to_cil", ("").to_cil /= Void)
2335 check_boolean ("to_cil", ("123").to_cil /= Void)
2336 end
2337 end
2338
2339 test_to_double is
2340 do
2341 check_equality ("to_double", ("0").to_double, {DOUBLE} 0.0)
2342 check_equality ("to_double", ("1").to_double, {DOUBLE} 1.0)
2343 check_equality ("to_double", ("123").to_double, {DOUBLE} 123.0)
2344 check_equality ("to_double", ("0.75").to_double, {DOUBLE} 0.75)
2345 check_equality ("to_double", ("-348.75").to_double, {DOUBLE} -348.75)
2346 check_equality ("to_double", ("62.5e-3").to_double, {DOUBLE} 62.5e-3)
2347 check_equality ("to_double", ("1.e-4").to_double, {DOUBLE} 1.e-4)
2348 check_equality ("to_double", ("1.e-4").to_double, {DOUBLE} 0.0001)
2349 check_equality ("to_double", ("62.5e-3").to_double, {DOUBLE} 62.5e-3)
2350 end
2351
2352 test_to_integer is
2353 do
2354 -- Unsigned integers
2355 check_equality ("to_integer", ("000000").to_integer, 0)
2356 check_equality ("to_integer", ("000000000000000000001").to_integer, 1)
2357 check_equality ("to_integer", ("127").to_integer, 127)
2358 check_equality ("to_integer", ("128").to_integer, 128)
2359 check_equality ("to_integer", ("255").to_integer, 255)
2360 check_equality ("to_integer", ("256").to_integer, 256)
2361 check_equality ("to_integer", ("32767").to_integer, 32767)
2362 check_equality ("to_integer", ("32768").to_integer, 32768)
2363 check_equality ("to_integer", ("65535").to_integer, 65535)
2364 check_equality ("to_integer", ("65536").to_integer, 65536)
2365 check_equality ("to_integer", ("2147483647").to_integer, 2147483647)
2366 -- Positive integers
2367 check_equality ("to_integer", ("+000000").to_integer, 0)
2368 check_equality ("to_integer", ("+000000000000000000001").to_integer, 1)
2369 check_equality ("to_integer", ("+127").to_integer, 127)
2370 check_equality ("to_integer", ("+128").to_integer, 128)
2371 check_equality ("to_integer", ("+255").to_integer, 255)
2372 check_equality ("to_integer", ("+256").to_integer, 256)
2373 check_equality ("to_integer", ("+32767").to_integer, 32767)
2374 check_equality ("to_integer", ("+32768").to_integer, 32768)
2375 check_equality ("to_integer", ("+65535").to_integer, 65535)
2376 check_equality ("to_integer", ("+65536").to_integer, 65536)
2377 check_equality ("to_integer", ("+2147483647").to_integer, 2147483647)
2378 -- Negative integers
2379 check_equality ("to_integer", ("-000000").to_integer, 0)
2380 check_equality ("to_integer", ("-000000000000000000001").to_integer, -1)
2381 check_equality ("to_integer", ("-127").to_integer, -127)
2382 check_equality ("to_integer", ("-128").to_integer, -128)
2383 check_equality ("to_integer", ("-255").to_integer, -255)
2384 check_equality ("to_integer", ("-256").to_integer, -256)
2385 check_equality ("to_integer", ("-32767").to_integer, -32767)
2386 check_equality ("to_integer", ("-32768").to_integer, -32768)
2387 check_equality ("to_integer", ("-65535").to_integer, -65535)
2388 check_equality ("to_integer", ("-65536").to_integer, -65536)
2389 check_equality ("to_integer", ("-2147483647").to_integer, -2147483647)
2390 check_equality ("to_integer", ("-2147483648").to_integer, -2147483648)
2391 end
2392
2393 test_to_integer_64 is
2394 do
2395 -- Unsigned integers
2396 check_equality ("to_integer_64", ("000000").to_integer_64, {INTEGER_64} 0)
2397 check_equality ("to_integer_64", ("000000000000000000001").to_integer_64, {INTEGER_64} 1)
2398 check_equality ("to_integer_64", ("127").to_integer_64, {INTEGER_64} 127)
2399 check_equality ("to_integer_64", ("128").to_integer_64, {INTEGER_64} 128)
2400 check_equality ("to_integer_64", ("255").to_integer_64, {INTEGER_64} 255)
2401 check_equality ("to_integer_64", ("256").to_integer_64, {INTEGER_64} 256)
2402 check_equality ("to_integer_64", ("32767").to_integer_64, {INTEGER_64} 32767)
2403 check_equality ("to_integer_64", ("32768").to_integer_64, {INTEGER_64} 32768)
2404 check_equality ("to_integer_64", ("65535").to_integer_64, {INTEGER_64} 65535)
2405 check_equality ("to_integer_64", ("65536").to_integer_64, {INTEGER_64} 65536)
2406 check_equality ("to_integer_64", ("2147483647").to_integer_64, {INTEGER_64} 2147483647)
2407 check_equality ("to_integer_64", ("2147483648").to_integer_64, {INTEGER_64} 2147483648)
2408 check_equality ("to_integer_64", ("9223372036854775807").to_integer_64, {INTEGER_64} 0x7FFF_FFFF_FFFF_FFFF)
2409 -- Positive integers
2410 check_equality ("to_integer_64", ("+000000").to_integer_64, {INTEGER_64} 0)
2411 check_equality ("to_integer_64", ("+000000000000000000001").to_integer_64, {INTEGER_64} 1)
2412 check_equality ("to_integer_64", ("+127").to_integer_64, {INTEGER_64} 127)
2413 check_equality ("to_integer_64", ("+128").to_integer_64, {INTEGER_64} 128)
2414 check_equality ("to_integer_64", ("+255").to_integer_64, {INTEGER_64} 255)
2415 check_equality ("to_integer_64", ("+256").to_integer_64, {INTEGER_64} 256)
2416 check_equality ("to_integer_64", ("+32767").to_integer_64, {INTEGER_64} 32767)
2417 check_equality ("to_integer_64", ("+32768").to_integer_64, {INTEGER_64} 32768)
2418 check_equality ("to_integer_64", ("+65535").to_integer_64, {INTEGER_64} 65535)
2419 check_equality ("to_integer_64", ("+65536").to_integer_64, {INTEGER_64} 65536)
2420 check_equality ("to_integer_64", ("+2147483647").to_integer_64, {INTEGER_64} 2147483647)
2421 check_equality ("to_integer_64", ("+2147483648").to_integer_64, {INTEGER_64} 2147483648)
2422 check_equality ("to_integer_64", ("+9223372036854775807").to_integer_64, {INTEGER_64} 0x7FFF_FFFF_FFFF_FFFF)
2423 -- Negative integers
2424 check_equality ("to_integer_64", ("-000000").to_integer_64, {INTEGER_64} 0)
2425 check_equality ("to_integer_64", ("-000000000000000000001").to_integer_64, {INTEGER_64} -1)
2426 check_equality ("to_integer_64", ("-127").to_integer_64, {INTEGER_64} -127)
2427 check_equality ("to_integer_64", ("-128").to_integer_64, {INTEGER_64} -128)
2428 check_equality ("to_integer_64", ("-255").to_integer_64, {INTEGER_64} -255)
2429 check_equality ("to_integer_64", ("-256").to_integer_64, {INTEGER_64} -256)
2430 check_equality ("to_integer_64", ("-32767").to_integer_64, {INTEGER_64} -32767)
2431 check_equality ("to_integer_64", ("-32768").to_integer_64, {INTEGER_64} -32768)
2432 check_equality ("to_integer_64", ("-65535").to_integer_64, {INTEGER_64} -65535)
2433 check_equality ("to_integer_64", ("-65536").to_integer_64, {INTEGER_64} -65536)
2434 check_equality ("to_integer_64", ("-2147483647").to_integer_64, {INTEGER_64} -2147483647)
2435 check_equality ("to_integer_64", ("-2147483648").to_integer_64, {INTEGER_64} -2147483648)
2436 check_equality ("to_integer_64", ("-9223372036854775807").to_integer_64, {INTEGER_64} -0x7FFF_FFFF_FFFF_FFFF)
2437 check_equality ("to_integer_64", ("-9223372036854775808").to_integer_64, {INTEGER_64} -0x8000_0000_0000_0000)
2438 end
2439
2440 test_to_lower is
2441 local
2442 s: STRING_32
2443 do
2444 s := ""
2445 s.to_lower
2446 check_string_equality ("to_lower", s, "")
2447 s := "123ABC456"
2448 s.to_lower
2449 check_string_equality ("to_lower", s, "123abc456")
2450 s.to_lower
2451 check_string_equality ("to_lower", s, "123abc456")
2452 s := "ABC %T%U %F DEF"
2453 s.to_lower
2454 check_string_equality ("to_lower", s, "abc %T%U %F def")
2455 s.to_lower
2456 check_string_equality ("to_lower", s, "abc %T%U %F def")
2457 end
2458
2459 test_to_real is
2460 do
2461 check_equality ("to_real", ("0").to_real, {REAL} 0.0)
2462 check_equality ("to_real", ("1").to_real, {REAL} 1.0)
2463 check_equality ("to_real", ("123").to_real, {REAL} 123.0)
2464 check_equality ("to_real", ("0.75").to_real, {REAL} 0.75)
2465 check_equality ("to_real", ("-348.75").to_real, {REAL} -348.75)
2466 check_equality ("to_real", ("62.5e-3").to_real, {REAL} 62.5e-3)
2467 end
2468
2469 test_to_upper is
2470 local
2471 s: STRING_32
2472 do
2473 s := ""
2474 s.to_upper
2475 check_string_equality ("to_upper", s, "")
2476 s := "123abc456"
2477 s.to_upper
2478 check_string_equality ("to_upper", s, "123ABC456")
2479 s.to_upper
2480 check_string_equality ("to_upper", s, "123ABC456")
2481 s := "abc %T%U %F def"
2482 s.to_upper
2483 check_string_equality ("to_upper", s, "ABC %T%U %F DEF")
2484 s.to_upper
2485 check_string_equality ("to_upper", s, "ABC %T%U %F DEF")
2486 end
2487
2488 test_trim
2489 local
2490 s: STRING_32
2491 count: like {STRING_32}.count
2492 capacity: like {STRING_32}.count
2493 do
2494 s := {STRING_32} ""
2495 s.trim
2496 check_equality ("resize", s, {STRING_32} "")
2497 create s.make (5)
2498 capacity := 5
2499 count := 0
2500 check_equality ("resize", s, {STRING_32} "")
2501 check_equality ("resize", s.count, count)
2502 check_equality ("resize", s.capacity, capacity)
2503 s.trim
2504 capacity := count
2505 check_equality ("resize", s, {STRING_32} "")
2506 check_equality ("resize", s.count, count)
2507 check_equality ("resize", s.capacity, capacity)
2508 create s.make (5)
2509 capacity := 5
2510 s.extend ('1')
2511 s.extend ('2')
2512 count := 2
2513 check_equality ("resize", s, {STRING_32} "12")
2514 check_equality ("resize", s.count, count)
2515 check_equality ("resize", s.capacity, capacity)
2516 s.trim
2517 capacity := count
2518 check_equality ("resize", s, {STRING_32} "12")
2519 check_equality ("resize", s.count, count)
2520 check_equality ("resize", s.capacity, capacity)
2521 create s.make (3)
2522 capacity := 3
2523 s.extend ('1')
2524 s.extend ('2')
2525 s.extend ('3')
2526 count := 3
2527 check_equality ("resize", s, {STRING_32} "123")
2528 check_equality ("resize", s.count, count)
2529 check_equality ("resize", s.capacity, capacity)
2530 s.trim
2531 check_equality ("resize", s, {STRING_32} "123")
2532 check_equality ("resize", s.count, count)
2533 check_equality ("resize", s.capacity, capacity)
2534 end
2535
2536 test_twin is
2537 local
2538 s: STRING_32
2539 do
2540 s := ""
2541 check_string_equality ("twin", s.twin, "")
2542 check_boolean ("twin", s /= s.twin)
2543 check_boolean ("twin", not s.shared_with (s.twin))
2544 s := "12345"
2545 check_string_equality ("twin", s.twin, "12345")
2546 check_boolean ("twin", s /= s.twin)
2547 check_boolean ("twin", not s.shared_with (s.twin))
2548 end
2549
2550 test_valid_index is
2551 do
2552 check_boolean ("valid_index", not ("").valid_index (-1))
2553 check_boolean ("valid_index", not ("").valid_index (0))
2554 check_boolean ("valid_index", not ("").valid_index (1))
2555 check_boolean ("valid_index", not ("").valid_index (2))
2556 check_boolean ("valid_index", not ("123").valid_index (-1))
2557 check_boolean ("valid_index", not ("123").valid_index (0))
2558 check_boolean ("valid_index", ("123").valid_index (1))
2559 check_boolean ("valid_index", ("123").valid_index (2))
2560 check_boolean ("valid_index", ("123").valid_index (3))
2561 check_boolean ("valid_index", not ("123").valid_index (4))
2562 end
2563
2564 test_wipe_out is
2565 local
2566 s: STRING_32
2567 do
2568 s := ""
2569 s.wipe_out
2570 check_string_equality ("wipe_out", s, "")
2571 s := "12345"
2572 s.wipe_out
2573 check_string_equality ("wipe_out", s, "")
2574 end
2575
2576 feature {NONE} -- Checking
2577
2578 check_equality (a_name: STRING; a, b: ANY) is
2579 -- If `a' and `b' are not equal print something on the console.
2580 require
2581 a_name_not_void: a_name /= Void
2582 do
2583 if a /~ b then
2584 io.put_string ("Not OK: " + a_name)
2585 io.put_new_line
2586 end
2587 end
2588
2589 check_string_equality (a_name: STRING; a, b: STRING_32) is
2590 -- If `a' and `b' are not equal print something on the console.
2591 require
2592 a_name_not_void: a_name /= Void
2593 do
2594 if a /~ b then
2595 io.put_string ("Not OK: " + a_name)
2596 io.put_new_line
2597 end
2598 end
2599
2600 check_boolean (a_name: STRING; b: BOOLEAN) is
2601 -- If `a' and `b' are not equal print something on the console.
2602 require
2603 a_name_not_void: a_name /= Void
2604 do
2605 if not b then
2606 io.put_string ("Not OK: " + a_name)
2607 io.put_new_line
2608 end
2609 end
2610
2611 end

Properties

Name Value
svn:eol-style native
svn:keywords Author Date ID Revision

  ViewVC Help
Powered by ViewVC 1.1.23