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

Contents of /trunk/eweasel/tests/string001/test_immutable_string_8.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: 47320 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_IMMUTABLE_STRING_8
3
4 create
5
6 make
7
8 feature {NONE} -- Initialization
9
10 make is
11 -- Execute test.
12 do
13 test_as_lower
14 test_as_upper
15 test_ends_with
16 test_fuzzy_index
17 test_has
18 test_hash_code
19 test_has_substring
20 test_index_of
21 test_is_boolean
22 test_is_case_insensitive_equal
23 test_is_double
24 test_is_empty
25 test_is_equal
26 test_is_integer
27 test_is_real
28 test_is_valid_as_string_8
29 test_infix_greater
30 test_infix_greater_or_equal
31 test_infix_less
32 test_infix_less_or_equal
33 test_infix_plus
34 test_item
35 test_code
36 test_last_index_of
37 test_linear_representation
38 test_make
39 test_make_empty
40 test_make_filled
41 test_make_from_c
42 test_make_from_string
43 test_max
44 test_min
45 test_mirrored
46 test_occurrences
47 test_out
48 test_plus
49 test_prunable
50 test_resizable
51 test_same_string
52 test_same_characters
53 test_same_caseless_characters
54 test_same_type
55 test_split
56 test_starts_with
57 test_string
58 test_shared_substring
59 test_substring
60 test_substring_index
61 test_substring_index_in_bounds
62 test_tagged_out
63 test_three_way_comparison
64 test_to_c
65 test_to_cil
66 test_to_double
67 test_to_integer
68 test_to_integer_64
69 test_to_real
70 test_twin
71 test_valid_index
72 end
73
74 feature {NONE} -- Implementation
75
76 test_as_lower is
77 local
78 s, t: IMMUTABLE_STRING_8
79 do
80 create s.make_from_string ("ABcd EF gh I 123 ;")
81 t := s.as_lower
82 check_string_equality ("as_lower", t, "abcd ef gh i 123 ;")
83 check_boolean ("as_lower", t /= s)
84 end
85
86 test_as_upper is
87 local
88 s, t: IMMUTABLE_STRING_8
89 do
90 create s.make_from_string ("ABcd EF gh I 123 ;")
91 t := s.as_upper
92 check_string_equality ("as_upper", t, "ABCD EF GH I 123 ;")
93 check_boolean ("as_upper", t /= s)
94 end
95
96 test_ends_with is
97 local
98 s: IMMUTABLE_STRING_8
99 do
100 s := "1234567890"
101 check_boolean ("Ends with empty%N", s.ends_with (""))
102 check_boolean ("Ends with itself%N", s.ends_with (s))
103 check_boolean ("Ends with its twin%N", s.ends_with (s.twin))
104 check_boolean ("Not ends with itself twice%N", not s.ends_with (s + s))
105 check_boolean ("Not ends with 123%N", not s.ends_with ("123"))
106 check_boolean ("Not ends with 23%N", not s.ends_with ("23"))
107 check_boolean ("Ends with 890%N", s.ends_with ("890"))
108 check_boolean ("Not ends with 89%N", not s.ends_with ("89"))
109 end
110
111 test_fuzzy_index is
112 local
113 s: IMMUTABLE_STRING_8
114 i: INTEGER
115 do
116 s := "Eiffel Software Enterprise Edition"
117 i := s.fuzzy_index ("Soltware", 1, 1)
118 check_equality ("fuzzy_index", i, 8)
119
120 i := s.fuzzy_index ("Sotware", 1, 1)
121 check_equality ("fuzzy_index", i, 0)
122
123 i := s.fuzzy_index ("Edataon", 10, 2)
124 check_equality ("fuzzy_index", i, 28)
125
126 i := s.fuzzy_index ("Edataon", 29, 2)
127 check_equality ("fuzzy_index", i, 0)
128
129 i := s.fuzzy_index ("Enterprise", 1, 0)
130 check_equality ("fuzzy_index", i, 17)
131
132 i := s.fuzzy_index ("Entreprise", 1, 0)
133 check_equality ("fuzzy_index", i, 0)
134
135 i := s.fuzzy_index ("Enterprise", 1, 0)
136 check_equality ("fuzzy_index", i, 17)
137 end
138
139 test_has is
140 local
141 s: IMMUTABLE_STRING_8
142 do
143 create s.make (10)
144 check_boolean ("has", not s.has ('c'))
145 check_boolean ("has", not s.has ('%U'))
146
147 s := "1234c1234"
148 check_boolean ("has", s.has ('c'))
149 check_boolean ("has", not s.has ('9'))
150
151 s := ""
152 check_boolean ("has", not s.has ('c'))
153 check_boolean ("has", not s.has ('9'))
154
155 s := "1234c1234"
156 s := s.shared_substring (2, 4)
157 check_boolean ("has", not s.has ('1'))
158 check_boolean ("has", not s.has ('c'))
159 check_boolean ("has", s.has ('2'))
160 check_boolean ("has", s.has ('3'))
161 check_boolean ("has", s.has ('4'))
162
163 s := s.shared_substring (2, 1)
164 check_boolean ("has", not s.has ('2'))
165 check_boolean ("has", not s.has ('3'))
166 check_boolean ("has", not s.has ('4'))
167 end
168
169 test_hash_code
170 local
171 s: IMMUTABLE_STRING_8
172 l_val: INTEGER
173 do
174 s := "12345"
175 l_val := s.hash_code
176
177 s := "012345"
178 s := s.shared_substring (2, 6)
179 check_boolean ("hash_code", l_val = s.hash_code)
180 end
181
182 test_has_substring is
183 local
184 s: IMMUTABLE_STRING_8
185 do
186 create s.make_from_string ("!23")
187 check_boolean ("has_substring", s.has_substring (s))
188 check_boolean ("has_substring", s.has_substring ("23"))
189 check_boolean ("has_substring", not s.has_substring ("12"))
190 check_boolean ("has_substring", not s.has_substring ("!23 "))
191 check_boolean ("has_substring", s.has_substring ("!23"))
192
193 check_boolean ("has_substring", ("").has_substring (""))
194 check_boolean ("has_substring", ("foobar").has_substring ("oo"))
195 check_boolean ("has_substring", not ("foobar").has_substring ("abo"))
196 end
197
198 test_index_of is
199 local
200 s: IMMUTABLE_STRING_8
201 i: INTEGER
202 do
203 create s.make_from_string ("1234567890")
204 i := s.index_of ('0', 1)
205 check_equality ("index_of", i, 10)
206
207 i := s.index_of ('x', 1)
208 check_equality ("index_of", i , 0)
209
210 i := s.index_of ('5', 4)
211 check_equality ("index_of", i , 5)
212
213 i := s.index_of ('5', 5)
214 check_equality ("index_of", i , 5)
215
216 i := s.index_of ('5', 6)
217 check_equality ("index_of", i , 0)
218
219
220 -- New string is now "567890"
221 s := s.shared_substring (5, 10)
222 i := s.index_of ('x', 1)
223 check_equality ("index_of", i , 0)
224
225 i := s.index_of ('1', 1)
226 check_equality ("index_of", i , 0)
227
228 i := s.index_of ('2', 1)
229 check_equality ("index_of", i , 0)
230
231 i := s.index_of ('9', 5)
232 check_equality ("index_of", i , 5)
233 end
234
235 test_is_boolean is
236 local
237 s: IMMUTABLE_STRING_8
238 do
239 s := "true"
240 check_boolean ("is_boolean", s.is_boolean)
241 s := "1true"
242 s := s.shared_substring (2, 5)
243 check_boolean ("is_boolean", s.is_boolean)
244
245 s := " true "
246 check_boolean ("is_boolean", not s.is_boolean)
247 s := "1 true "
248 s := s.shared_substring (2, 12)
249 check_boolean ("is_boolean", not s.is_boolean)
250
251 s := "True"
252 check_boolean ("is_boolean", s.is_boolean)
253 s := "1True"
254 s := s.shared_substring (2, 5)
255 check_boolean ("is_boolean", s.is_boolean)
256
257 s := "false"
258 check_boolean ("is_boolean", s.is_boolean)
259 s := "1false"
260 s := s.shared_substring (2, 6)
261 check_boolean ("is_boolean", s.is_boolean)
262
263 s := " false "
264 check_boolean ("is_boolean", not s.is_boolean)
265 s := "1 false "
266 s := s.shared_substring (2, 13)
267 check_boolean ("is_boolean", not s.is_boolean)
268
269 s := "False"
270 check_boolean ("is_boolean", s.is_boolean)
271 s := "1False"
272 s := s.shared_substring (2, 6)
273 check_boolean ("is_boolean", s.is_boolean)
274
275 s := "TRUE"
276 check_boolean ("is_boolean", s.is_boolean)
277 s := "1TRUE"
278 s := s.shared_substring (2, 5)
279 check_boolean ("is_boolean", s.is_boolean)
280
281 s := "FALSE"
282 check_boolean ("is_boolean", s.is_boolean)
283 s := "1FALSE"
284 s := s.shared_substring (2, 6)
285 check_boolean ("is_boolean", s.is_boolean)
286
287 s := "Tru"
288 check_boolean ("is_boolean", not s.is_boolean)
289 s := "1Tru"
290 s := s.shared_substring (2, 4)
291 check_boolean ("is_boolean", not s.is_boolean)
292
293 s := "tru"
294 check_boolean ("is_boolean", not s.is_boolean)
295 s := "1tru"
296 s := s.shared_substring (2, 4)
297 check_boolean ("is_boolean", not s.is_boolean)
298
299 s := "Fal"
300 check_boolean ("is_boolean", not s.is_boolean)
301 s := "1Fal"
302 s := s.shared_substring (2, 4)
303 check_boolean ("is_boolean", not s.is_boolean)
304
305 s := "fal"
306 check_boolean ("is_boolean", not s.is_boolean)
307 s := "1fal"
308 s := s.shared_substring (2, 4)
309 check_boolean ("is_boolean", not s.is_boolean)
310 end
311
312 test_is_case_insensitive_equal is
313 local
314 s: IMMUTABLE_STRING_8
315 do
316 create s.make_from_string ("12345")
317 check_boolean ("is_case_insensitive_equal", s.is_case_insensitive_equal (s))
318 check_boolean ("is_case_insensitive_equal", s.is_case_insensitive_equal ("12345"))
319 check_boolean ("is_case_insensitive_equal", not s.is_case_insensitive_equal ("123456"))
320 check_boolean ("is_case_insensitive_equal", not s.is_case_insensitive_equal ("1234"))
321
322 s := "abcdef"
323 check_boolean ("is_case_insensitive_equal", s.is_case_insensitive_equal ("ABCDEF"))
324
325 s := "ABCDEF"
326 check_boolean ("is_case_insensitive_equal", s.is_case_insensitive_equal ("abcdef"))
327
328 s := "ABCdef"
329 check_boolean ("is_case_insensitive_equal", s.is_case_insensitive_equal ("abcDEF"))
330
331 check_boolean ("is_case_insensitive_equal", not s.is_case_insensitive_equal (""))
332
333 s := "ABCdef"
334 s := s.shared_substring (4, 6)
335 check_boolean ("is_case_insensitive_equal", s.is_case_insensitive_equal ("def"))
336 check_boolean ("is_case_insensitive_equal", not s.is_case_insensitive_equal (""))
337 end
338
339 test_is_double is
340 do
341 check_boolean ("is_double", ("5").is_double)
342 check_boolean ("is_double", ("5.5").is_double)
343 check_boolean ("is_double", ("5E4").is_double)
344 check_boolean ("is_double", not ("5 E4").is_double)
345 check_boolean ("is_double", ("5e-4").is_double)
346 check_boolean ("is_double", ("5e5").is_double)
347 check_boolean ("is_double", not ("5e 5").is_double)
348 check_boolean ("is_double", (".0").is_double)
349 check_boolean ("is_double", ("0.1e10").is_double)
350 check_boolean ("is_double", ("-1").is_double)
351 check_boolean ("is_double", ("-1.0").is_double)
352 check_boolean ("is_double", ("-1e1").is_double)
353 check_boolean ("is_double", ("-1e-1").is_double)
354 check_boolean ("is_double", ("-1.0e1").is_double)
355 check_boolean ("is_double", ("-1.0e-1").is_double)
356 check_boolean ("is_double", ("-.1").is_double)
357 check_boolean ("is_double", ("1e5").is_double)
358 check_boolean ("is_double", not ("e5").is_double)
359 check_boolean ("is_double", not (".e1").is_double)
360 check_boolean ("is_double", ("1e").is_double)
361 check_boolean ("is_double", ("1e1").is_double)
362 check_boolean ("is_double", (" 5").is_double)
363 check_boolean ("is_double", ("5 ").is_double)
364 check_boolean ("is_double", not ("%U5").is_double)
365 check_boolean ("is_double", not ("5.6%U").is_double)
366 check_boolean ("is_double", ("1").is_double)
367 end
368
369 test_is_empty is
370 local
371 s: IMMUTABLE_STRING_8
372 do
373 create s.make_from_string ("Fds")
374 check_boolean ("is_empty", not s.is_empty)
375
376 create s.make (10)
377 check_boolean ("is_empty", s.is_empty)
378
379 check_boolean ("is_empty", ("").is_empty)
380 end
381
382 test_is_equal is
383 local
384 s: IMMUTABLE_STRING_8
385 do
386 create s.make_from_string ("12345")
387 check_boolean ("is_equal", s.is_equal (s))
388 check_boolean ("is_equal", s.is_equal ("12345"))
389 check_boolean ("is_equal", not s.is_equal ("123456"))
390 check_boolean ("is_equal", not s.is_equal ("1234"))
391
392 s := "abcdef"
393 check_boolean ("is_equal", not s.is_equal ("ABCDEF"))
394
395 check_boolean ("is_equal", not s.is_equal (""))
396 end
397
398 test_is_integer is
399 do
400 check_boolean ("is_integer", not ("a").is_integer)
401 check_boolean ("is_integer", not ("%U1").is_integer)
402 check_boolean ("is_integer", ("1").is_integer)
403 check_boolean ("is_integer", (" 1").is_integer)
404 check_boolean ("is_integer", ("1 ").is_integer)
405 end
406
407 test_is_real is
408 do
409 check_boolean ("is_real", ("5").is_real)
410 check_boolean ("is_real", ("5.5").is_real)
411 check_boolean ("is_real", ("5E4").is_real)
412 check_boolean ("is_real", not ("5 E4").is_real)
413 check_boolean ("is_real", ("5e-4").is_real)
414 check_boolean ("is_real", ("5e5").is_real)
415 check_boolean ("is_real", not ("5e 5").is_real)
416 check_boolean ("is_real", (".0").is_real)
417 check_boolean ("is_real", ("0.1e10").is_real)
418 check_boolean ("is_real", ("-1").is_real)
419 check_boolean ("is_real", ("-1.0").is_real)
420 check_boolean ("is_real", ("-1e1").is_real)
421 check_boolean ("is_real", ("-1e-1").is_real)
422 check_boolean ("is_real", ("-1.0e1").is_real)
423 check_boolean ("is_real", ("-1.0e-1").is_real)
424 check_boolean ("is_real", ("-.1").is_real)
425 check_boolean ("is_real", ("1e5").is_real)
426 check_boolean ("is_real", not ("e5").is_real)
427 check_boolean ("is_real", not (".e1").is_real)
428 check_boolean ("is_real", ("1e").is_real)
429 check_boolean ("is_real", ("1e1").is_real)
430 check_boolean ("is_real", (" 5").is_real)
431 check_boolean ("is_real", ("5 ").is_real)
432 check_boolean ("is_real", not ("%U5").is_real)
433 check_boolean ("is_real", not ("5.6%U").is_real)
434 end
435
436 test_is_valid_as_string_8
437 local
438 s: IMMUTABLE_STRING_8
439 do
440 s := "12345"
441 check_boolean ("is_valid_as_string_8", s.is_valid_as_string_8)
442 end
443
444 test_infix_greater is
445 local
446 s: IMMUTABLE_STRING_8
447 p: IMMUTABLE_STRING_8
448 do
449 s := "12345"
450 p := "12345"
451 check_boolean (">", not (s > s))
452 check_boolean (">", not (s > p))
453 p := "12345a"
454 check_boolean (">", not (s > p))
455 check_boolean (">", p > s)
456 p := "12045"
457 check_boolean (">", s > p)
458 check_boolean (">", not (p > s))
459 s := "123"
460 check_boolean (">", s > p)
461 check_boolean (">", not (p > s))
462
463 s := ""
464 p := ""
465 check_boolean (">", not (s > s))
466 check_boolean (">", not (s > p))
467 p := "a"
468 check_boolean (">", not (s > p))
469 check_boolean (">", p > s)
470 end
471
472 test_infix_greater_or_equal is
473 local
474 s: IMMUTABLE_STRING_8
475 p: IMMUTABLE_STRING_8
476 do
477 s := "12345"
478 p := "12345"
479 check_boolean (">=", s >= s)
480 check_boolean (">=", s >= p)
481 p := "12345a"
482 check_boolean (">=", not (s >= p))
483 check_boolean (">=", p >= s)
484 p := "12045"
485 check_boolean (">=", s >= p)
486 check_boolean (">=", not (p >= s))
487 s := "123"
488 check_boolean (">=", s >= p)
489 check_boolean (">=", not (p >= s))
490
491 s := ""
492 p := ""
493 check_boolean (">=", s >= s)
494 check_boolean (">=", s >= p)
495 p := "a"
496 check_boolean (">=", not (s >= p))
497 check_boolean (">=", p >= s)
498 end
499
500 test_infix_less is
501 local
502 s: IMMUTABLE_STRING_8
503 p: IMMUTABLE_STRING_8
504 do
505 s := "12345"
506 p := "12345"
507 check_boolean ("<", not (s < s))
508 check_boolean ("<", not (s < p))
509 p := "12345a"
510 check_boolean ("<", s < p)
511 check_boolean ("<", not (p < s))
512 p := "12045"
513 check_boolean ("<", not (s < p))
514 check_boolean ("<", p < s)
515 s := "123"
516 check_boolean ("<", not (s < p))
517 check_boolean ("<", p < s)
518
519 s := ""
520 p := ""
521 check_boolean ("<", not (s < s))
522 check_boolean ("<", not (s < p))
523 p := "a"
524 check_boolean ("<", s < p)
525 check_boolean ("<", not (p < s))
526 end
527
528 test_infix_less_or_equal is
529 local
530 s: IMMUTABLE_STRING_8
531 p: IMMUTABLE_STRING_8
532 do
533 s := "12345"
534 p := "12345"
535 check_boolean ("<=", s <= s)
536 check_boolean ("<=", s <= p)
537 p := "12345a"
538 check_boolean ("<=", s <= p)
539 check_boolean ("<=", not (p <= s))
540 p := "12045"
541 check_boolean ("<=", not (s <= p))
542 check_boolean ("<=", p <= s)
543 s := "123"
544 check_boolean ("<=", not (s <= p))
545 check_boolean ("<=", p <= s)
546
547 s := ""
548 p := ""
549 check_boolean ("<=", s <= s)
550 check_boolean ("<=", s <= p)
551 p := "a"
552 check_boolean ("<=", s <= p)
553 check_boolean ("<=", not (p <= s))
554 end
555
556 test_infix_plus is
557 local
558 s: IMMUTABLE_STRING_8
559 do
560 s := "12345"
561 check_string_equality ("+", s + s, "1234512345")
562 check_string_equality ("+", "" + "", "")
563 check_string_equality ("+", "" + s, "12345")
564 check_string_equality ("+", s + "", "12345")
565 end
566
567 test_item
568 local
569 s: IMMUTABLE_STRING_8
570 do
571 s := "12345"
572 check_boolean ("item", s.item (1) = '1')
573 check_boolean ("item", s.item (2) = '2')
574 check_boolean ("item", s.item (3) = '3')
575 check_boolean ("item", s.item (4) = '4')
576 check_boolean ("item", s.item (5) = '5')
577
578 s := s.shared_substring (2, 4)
579 check_boolean ("item", s.item (1) = '2')
580 check_boolean ("item", s.item (2) = '3')
581 check_boolean ("item", s.item (3) = '4')
582 end
583
584 test_code
585 local
586 s: IMMUTABLE_STRING_8
587 do
588 s := "12345"
589 check_boolean ("code", s.code (1) = 49)
590 check_boolean ("code", s.code (2) = 50)
591 check_boolean ("code", s.code (3) = 51)
592 check_boolean ("code", s.code (4) = 52)
593 check_boolean ("code", s.code (5) = 53)
594
595 s := s.shared_substring (2, 4)
596 check_boolean ("code", s.code (1) = 50)
597 check_boolean ("code", s.code (2) = 51)
598 check_boolean ("code", s.code (3) = 52)
599 end
600
601 test_last_index_of is
602 local
603 s: IMMUTABLE_STRING_8
604 do
605 s := "a"
606 check_equality ("last_boolean", s.last_index_of ('a', 1), 1)
607 check_equality ("last_boolean", s.last_index_of ('b', 1), 0)
608
609 s := "1234554321"
610 check_equality ("last_boolean", s.last_index_of ('3', 10), 8)
611 check_equality ("last_boolean", s.last_index_of ('3', 5), 3)
612 check_equality ("last_boolean", s.last_index_of ('3', 3), 3)
613 check_equality ("last_boolean", s.last_index_of ('3', 2), 0)
614 check_equality ("last_boolean", s.last_index_of ('X', 10), 0)
615
616 s := "ba"
617 s := s.shared_substring (2, 2)
618 check_equality ("last_boolean", s.last_index_of ('a', 1), 1)
619 check_equality ("last_boolean", s.last_index_of ('b', 1), 0)
620
621 s := "0001234554321"
622 s := s.shared_substring (4, 13)
623 check_equality ("last_boolean", s.last_index_of ('3', 10), 8)
624 check_equality ("last_boolean", s.last_index_of ('3', 5), 3)
625 check_equality ("last_boolean", s.last_index_of ('3', 3), 3)
626 check_equality ("last_boolean", s.last_index_of ('3', 2), 0)
627 check_equality ("last_boolean", s.last_index_of ('X', 10), 0)
628 end
629
630 test_linear_representation is
631 local
632 s: IMMUTABLE_STRING_8
633 l_c: LINEAR [CHARACTER_8]
634 i: INTEGER
635 do
636 s := "12345"
637 l_c := s.linear_representation
638 check_boolean ("linear_representation", l_c /= s.linear_representation)
639 check_boolean ("linear_representation", not s.linear_representation.is_empty)
640 from
641 l_c.start
642 until
643 l_c.off
644 loop
645 i := i + 1
646 check_boolean ("linear_representation", l_c.item = s.item (i))
647 l_c.forth
648 end
649 check_boolean ("linear_representation", i = 5)
650 end
651
652 test_make is
653 local
654 s: IMMUTABLE_STRING_8
655 do
656 s := "1234567890"
657
658 create s.make (2)
659 check_boolean ("make", s.is_empty)
660 check_boolean ("make", s.count = 0)
661 check_boolean ("make", s.capacity >= 2)
662 end
663
664 test_make_empty is
665 local
666 s: IMMUTABLE_STRING_8
667 do
668 create s.make_empty
669 check_boolean ("make_empty", s.is_empty)
670 check_boolean ("make_empty", s.count = 0)
671 check_boolean ("make_empty", s.capacity >= 0)
672 end
673
674 test_make_filled is
675 local
676 s: IMMUTABLE_STRING_8
677 do
678 create s.make_filled (' ', 10)
679 check_boolean ("make_filled", s.count = 10)
680 check_boolean ("make_filled", s.capacity >= 10)
681 check_boolean ("make_filled", s.occurrences (' ') = 10)
682 check_boolean ("make_filled", s.occurrences ('x') = 0)
683 check_boolean ("make_filled", s.is_equal (" "))
684
685 create s.make_filled ('a', 10)
686 check_boolean ("make_filled", s.count = 10)
687 check_boolean ("make_filled", s.capacity >= 10)
688 check_boolean ("make_filled", s.occurrences (' ') = 0)
689 check_boolean ("make_filled", s.occurrences ('x') = 0)
690 check_boolean ("make_filled", s.occurrences ('a') = 10)
691 check_boolean ("make_filled", s.is_equal ("aaaaaaaaaa"))
692 end
693
694 test_make_from_c is
695 local
696 l_ptr: MANAGED_POINTER
697 s: IMMUTABLE_STRING_8
698 do
699 create l_ptr.make_from_array ({ARRAY [NATURAL_8]} << 48, 49, 50, 51, 52, 53, 54, 0 >>)
700 create s.make_from_c (l_ptr.item)
701 check_boolean ("make_from_c", s.is_equal ("0123456"))
702
703 create l_ptr.make_from_array ({ARRAY [NATURAL_8]} << 0, 48, 49, 50, 51, 52, 53, 54, 0 >>)
704 create s.make_from_c (l_ptr.item)
705 check_boolean ("make_from_c", s.is_empty)
706 end
707
708 test_make_from_string is
709 local
710 s, p: STRING_8
711 do
712 p := "12345"
713 create s.make_from_string (p)
714 check_boolean ("make_from_string", s.is_equal ("12345"))
715 check_boolean ("make_from_string", s.area /= p.area)
716 end
717
718 test_max is
719 local
720 s: IMMUTABLE_STRING_8
721 p: IMMUTABLE_STRING_8
722 do
723 s := "12345"
724 p := "12345"
725 check_boolean ("max", s.max (s) = s)
726 check_boolean ("max", s.max (p) = s)
727 check_boolean ("max", p.max (s) = p)
728 p := "12345a"
729 check_boolean ("max", s.max (p) = p)
730 check_boolean ("max", p.max (s) = p)
731 p := "12045"
732 check_boolean ("max", s.max (p) = s)
733 check_boolean ("max", p.max (s) = s)
734
735 s := ""
736 p := ""
737 check_boolean ("max", s.max (s) = s)
738 check_boolean ("max", s.max (p) = s)
739 check_boolean ("max", p.max (s) = p)
740 p := "a"
741 check_boolean ("max", s.max (p) = p)
742 check_boolean ("max", p.max (s) = p)
743 end
744
745 test_min is
746 local
747 s: IMMUTABLE_STRING_8
748 p: IMMUTABLE_STRING_8
749 do
750 s := "12345"
751 p := "12345"
752 check_boolean ("min", s.min (s) = s)
753 check_boolean ("min", s.min (p) = s)
754 check_boolean ("min", p.min (s) = p)
755 p := "12345a"
756 check_boolean ("min", s.min (p) = s)
757 check_boolean ("min", p.min (s) = s)
758 p := "12045"
759 check_boolean ("min", s.min (p) = p)
760 check_boolean ("min", p.min (s) = p)
761
762 s := ""
763 p := ""
764 check_boolean ("min", s.min (s) = s)
765 check_boolean ("min", s.min (p) = s)
766 check_boolean ("min", p.min (s) = p)
767 p := "a"
768 check_boolean ("min", s.min (p) = s)
769 check_boolean ("min", p.min (s) = s)
770 end
771
772 test_mirrored is
773 local
774 s: IMMUTABLE_STRING_8
775 p: IMMUTABLE_STRING_8
776 do
777 s := ""
778 p := s.mirrored
779 check_string_equality ("mirrored", s, "")
780 check_string_equality ("mirrored", p, "")
781 s := "a"
782 p := s.mirrored
783 check_string_equality ("mirrored", s, "a")
784 check_string_equality ("mirrored", p, "a")
785 s := "ab"
786 p := s.mirrored
787 check_string_equality ("mirrored", s, "ab")
788 check_string_equality ("mirrored", p, "ba")
789 s := "abc"
790 p := s.mirrored
791 check_string_equality ("mirrored", s, "abc")
792 check_string_equality ("mirrored", p, "cba")
793 s := "abcd"
794 p := s.mirrored
795 check_string_equality ("mirrored", s, "abcd")
796 check_string_equality ("mirrored", p, "dcba")
797 s := "abcde"
798 p := s.mirrored
799 check_string_equality ("mirrored", s, "abcde")
800 check_string_equality ("mirrored", p, "edcba")
801 end
802
803 test_occurrences is
804 local
805 s: IMMUTABLE_STRING_8
806 do
807 check_boolean ("occurrences", ("").occurrences ('%U') = 0)
808 check_boolean ("occurrences", ("").occurrences (' ') = 0)
809 check_boolean ("occurrences", ("").occurrences ('a') = 0)
810 check_boolean ("occurrences", ("%U").occurrences ('%U') = 1)
811 check_boolean ("occurrences", ("%U").occurrences (' ') = 0)
812 check_boolean ("occurrences", ("%U").occurrences ('a') = 0)
813 check_boolean ("occurrences", (" ").occurrences ('%U') = 0)
814 check_boolean ("occurrences", (" ").occurrences (' ') = 1)
815 check_boolean ("occurrences", (" ").occurrences ('a') = 0)
816 check_boolean ("occurrences", ("a").occurrences ('%U') = 0)
817 check_boolean ("occurrences", ("a").occurrences (' ') = 0)
818 check_boolean ("occurrences", ("a").occurrences ('a') = 1)
819 check_boolean ("occurrences", ("%U%U").occurrences ('%U') = 2)
820 check_boolean ("occurrences", ("%U%U").occurrences (' ') = 0)
821 check_boolean ("occurrences", ("%U%U").occurrences ('a') = 0)
822 check_boolean ("occurrences", ("%U ").occurrences ('%U') = 1)
823 check_boolean ("occurrences", ("%U ").occurrences (' ') = 1)
824 check_boolean ("occurrences", ("%U ").occurrences ('a') = 0)
825 check_boolean ("occurrences", (" %U").occurrences ('%U') = 1)
826 check_boolean ("occurrences", (" %U").occurrences (' ') = 1)
827 check_boolean ("occurrences", (" %U").occurrences ('a') = 0)
828 check_boolean ("occurrences", (" ").occurrences ('%U') = 0)
829 check_boolean ("occurrences", (" ").occurrences (' ') = 2)
830 check_boolean ("occurrences", (" ").occurrences ('a') = 0)
831 check_boolean ("occurrences", (" a").occurrences ('%U') = 0)
832 check_boolean ("occurrences", (" a").occurrences (' ') = 1)
833 check_boolean ("occurrences", (" a").occurrences ('a') = 1)
834 check_boolean ("occurrences", ("a ").occurrences ('%U') = 0)
835 check_boolean ("occurrences", ("a ").occurrences (' ') = 1)
836 check_boolean ("occurrences", ("a ").occurrences ('a') = 1)
837 check_boolean ("occurrences", ("aa").occurrences ('%U') = 0)
838 check_boolean ("occurrences", ("aa").occurrences (' ') = 0)
839 check_boolean ("occurrences", ("aa").occurrences ('a') = 2)
840 check_boolean ("occurrences", ("%U%U%U").occurrences ('%U') = 3)
841 check_boolean ("occurrences", ("%U%U%U").occurrences (' ') = 0)
842 check_boolean ("occurrences", ("%U%U%U").occurrences ('a') = 0)
843 check_boolean ("occurrences", (" %U%U").occurrences ('%U') = 2)
844 check_boolean ("occurrences", (" %U%U").occurrences (' ') = 1)
845 check_boolean ("occurrences", (" %U%U").occurrences ('a') = 0)
846 check_boolean ("occurrences", ("%U %U").occurrences ('%U') = 2)
847 check_boolean ("occurrences", ("%U %U").occurrences (' ') = 1)
848 check_boolean ("occurrences", ("%U %U").occurrences ('a') = 0)
849 check_boolean ("occurrences", ("%U%U ").occurrences ('%U') = 2)
850 check_boolean ("occurrences", ("%U%U ").occurrences (' ') = 1)
851 check_boolean ("occurrences", ("%U%U ").occurrences ('a') = 0)
852 check_boolean ("occurrences", ("%U ").occurrences ('%U') = 1)
853 check_boolean ("occurrences", ("%U ").occurrences (' ') = 2)
854 check_boolean ("occurrences", ("%U ").occurrences ('a') = 0)
855 check_boolean ("occurrences", (" %U ").occurrences ('%U') = 1)
856 check_boolean ("occurrences", (" %U ").occurrences (' ') = 2)
857 check_boolean ("occurrences", (" %U ").occurrences ('a') = 0)
858 check_boolean ("occurrences", (" %U").occurrences ('%U') = 1)
859 check_boolean ("occurrences", (" %U").occurrences (' ') = 2)
860 check_boolean ("occurrences", (" %U").occurrences ('a') = 0)
861 check_boolean ("occurrences", (" ").occurrences ('%U') = 0)
862 check_boolean ("occurrences", (" ").occurrences (' ') = 3)
863 check_boolean ("occurrences", (" ").occurrences ('a') = 0)
864
865 s := "2211111122"
866 s := s.shared_substring (3, 5)
867 check_boolean ("occurrences", s.occurrences ('2') = 0)
868 check_boolean ("occurrences", s.occurrences ('1') = 3)
869 end
870
871 test_out is
872 do
873 check_string_equality ("out", ("").out, "")
874 check_string_equality ("out", ("1").out, "1")
875 check_string_equality ("out", ("12").out, "12")
876 check_string_equality ("out", ("123").out, "123")
877 check_string_equality ("out", ("1234").out, "1234")
878 check_string_equality ("out", ("12345").out, "12345")
879 end
880
881 test_plus is
882 local
883 is_32: IMMUTABLE_STRING_32
884 is_8: IMMUTABLE_STRING_8
885 s_32: STRING_32
886 s_8: STRING_8
887 do
888 is_32 := "12345"
889 s_32 := "12345"
890 is_8 := "67890"
891 s_8 := "67890"
892 check_string_equality ("plus", is_8.plus (is_32), "6789012345")
893 check_string_equality ("plus", is_8.plus (s_32), "6789012345")
894 check_string_equality ("plus", is_8.plus (is_8), "6789067890")
895 check_string_equality ("plus", is_8.plus (s_8), "6789067890")
896 check_string_equality ("plus", is_8.plus (""), "67890")
897
898 is_8 := ""
899 check_string_equality ("plus", is_8.plus (is_32), "12345")
900 check_string_equality ("plus", is_8.plus (s_32), "12345")
901 check_string_equality ("plus", is_8.plus (is_8), "")
902 check_string_equality ("plus", is_8.plus (s_8), "67890")
903 check_string_equality ("plus", is_8.plus (""), "")
904
905 is_32 := ""
906 s_32 := ""
907 s_8 := ""
908 check_string_equality ("plus", is_8.plus (is_32), "")
909 check_string_equality ("plus", is_8.plus (s_32), "")
910 check_string_equality ("plus", is_8.plus (is_8), "")
911 check_string_equality ("plus", is_8.plus (s_8), "")
912 check_string_equality ("plus", is_8.plus (""), "")
913 end
914
915 test_prunable is
916 do
917 check_boolean ("prunable", ("").prunable)
918 check_boolean ("prunable", ("%U").prunable)
919 check_boolean ("prunable", ("abc").prunable)
920 end
921
922 test_resizable is
923 do
924 check_boolean ("resizable", ("").resizable)
925 check_boolean ("resizable", ("1").resizable)
926 check_boolean ("resizable", ("12").resizable)
927 check_boolean ("resizable", ("123").resizable)
928 end
929
930 test_same_string is
931 local
932 s: IMMUTABLE_STRING_8
933 do
934 s := ""
935 check_boolean ("same_string", s.same_string (s))
936 check_boolean ("same_string", s.same_string (""))
937
938 s := "12345"
939 check_boolean ("same_string", s.same_string (s))
940 check_boolean ("same_string", s.same_string ("12345"))
941 check_boolean ("same_string", not s.same_string ("123456"))
942 check_boolean ("same_string", not s.same_string ("123"))
943 check_boolean ("same_string", not s.same_string (""))
944
945 s := "abcdef"
946 check_boolean ("same_string", not s.same_string ("ABCDEF"))
947 end
948
949 test_same_characters is
950 local
951 s: IMMUTABLE_STRING_8
952 o: IMMUTABLE_STRING_8
953 do
954 s := "12345"
955 o := "234"
956 check_boolean ("same_characters", s.same_characters (o, 1, 3, 2))
957 check_boolean ("same_characters", o.same_characters (s, 2, 4, 1))
958 o := "432"
959 check_boolean ("same_characters", not s.same_characters (o, 1, 3, 2))
960 check_boolean ("same_characters", not o.same_characters (s, 2, 4, 1))
961
962 s := "abcdef"
963 o := "BCD"
964 check_boolean ("same_characters", not s.same_characters (o, 1, 2, 2))
965 end
966
967 test_same_caseless_characters is
968 local
969 s: IMMUTABLE_STRING_8
970 o: IMMUTABLE_STRING_8
971 do
972 s := "12345"
973 o := "234"
974 check_boolean ("same_caseless_characters", s.same_caseless_characters (o, 1, 3, 2))
975 check_boolean ("same_caseless_characters", o.same_caseless_characters (s, 2, 4, 1))
976 o := "432"
977 check_boolean ("same_caseless_characters", not s.same_caseless_characters (o, 1, 3, 2))
978 check_boolean ("same_caseless_characters", not o.same_caseless_characters (s, 2, 4, 1))
979
980 s := "abcdef"
981 o := "BCD"
982 check_boolean ("same_caseless_characters", s.same_caseless_characters (o, 1, 2, 2))
983 check_boolean ("same_caseless_characters", not s.same_caseless_characters (o, 1, 2, 3))
984 end
985
986 test_same_type is
987 do
988 check_boolean ("same_type", (create {IMMUTABLE_STRING_8}.make_empty).same_type (create {IMMUTABLE_STRING_8}.make_empty))
989 check_boolean ("same_type", (create {IMMUTABLE_STRING_8}.make_empty).same_type (create {IMMUTABLE_STRING_8}.make (10)))
990 check_boolean ("same_type", ("").same_type ("12345"))
991 end
992
993 test_split is
994 local
995 s: IMMUTABLE_STRING_8
996 l: LIST [IMMUTABLE_STRING_8]
997 do
998 s := ""
999 l := s.split ('%U')
1000 check_equality ("split", l.count, 1)
1001 check_string_equality ("split", l [1], "")
1002 s := "1234543212345"
1003 l := s.split ('%U')
1004 check_equality ("split", l.count, 1)
1005 check_string_equality ("split", l [1], "1234543212345")
1006 l := s.split ('6')
1007 check_equality ("split", l.count, 1)
1008 check_string_equality ("split", l [1], "1234543212345")
1009 l := s.split ('1')
1010 check_equality ("split", l.count, 3)
1011 check_string_equality ("split", l [1], "")
1012 check_string_equality ("split", l [2], "2345432")
1013 check_string_equality ("split", l [3], "2345")
1014 l := s.split ('2')
1015 check_equality ("split", l.count, 4)
1016 check_string_equality ("split", l [1], "1")
1017 check_string_equality ("split", l [2], "34543")
1018 check_string_equality ("split", l [3], "1")
1019 check_string_equality ("split", l [4], "345")
1020 l := s.split ('5')
1021 check_equality ("split", l.count, 3)
1022 check_string_equality ("split", l [1], "1234")
1023 check_string_equality ("split", l [2], "4321234")
1024 check_string_equality ("split", l [3], "")
1025 end
1026
1027 test_starts_with is
1028 local
1029 s: IMMUTABLE_STRING_8
1030 do
1031 s := "1234567890"
1032 check_boolean ("Starts with empty%N", s.starts_with (""))
1033 check_boolean ("Starts with itself%N", s.starts_with (s))
1034 check_boolean ("Starts with its twin%N", s.starts_with (s.twin))
1035 check_boolean ("Not starts with itself twice%N", not s.starts_with (s + s))
1036 check_boolean ("Starts with 123%N", s.starts_with ("123"))
1037 check_boolean ("Not starts with 23%N", not s.starts_with ("23"))
1038 check_boolean ("Not starts with 890%N", not s.starts_with ("890"))
1039 check_boolean ("Not starts with 89%N", not s.starts_with ("89"))
1040 end
1041
1042 test_string is
1043 local
1044 s: IMMUTABLE_STRING_8
1045 do
1046 s := ""
1047 check_boolean ("string", s.string /= s)
1048 check_string_equality ("string", s.string, s)
1049 check_boolean ("string", not s.string.shared_with (s))
1050 s := "12345"
1051 check_boolean ("string", s.string /= s)
1052 check_string_equality ("string", s.string, s)
1053 check_boolean ("string", not s.string.shared_with (s))
1054 end
1055
1056 test_shared_substring is
1057 local
1058 s: IMMUTABLE_STRING_8
1059 do
1060 s := ""
1061 check_string_equality ("shared_substring", s.shared_substring (100, 1000), "")
1062 check_string_equality ("shared_substring", s.shared_substring (-1, 1), "")
1063 check_string_equality ("shared_substring", s.shared_substring (1, 1), "")
1064 check_string_equality ("shared_substring", s.shared_substring (1, 0), "")
1065
1066 s := "12345"
1067 check_string_equality ("shared_substring", s.shared_substring (100, 1000), "")
1068 check_string_equality ("shared_substring", s.shared_substring (-1, 0), "")
1069 check_string_equality ("shared_substring", s.shared_substring (-1, 1), "") -- Current implementation assumes that out-of-range indexes result in empty string
1070 check_string_equality ("shared_substring", s.shared_substring (1, 0), "")
1071 check_string_equality ("shared_substring", s.shared_substring (1, 5), "12345")
1072 check_string_equality ("shared_substring", s.shared_substring (3, 5), "345")
1073 check_string_equality ("shared_substring", s.shared_substring (3, 10), "") -- Current implementation assumes that out-of-range indexes result in empty string
1074 check_string_equality ("shared_substring", s.shared_substring (-100, 100), "") -- Current implementation assumes that out-of-range indexes result in empty string
1075
1076
1077 s := "1234567890987654321"
1078 s := s.shared_substring (11, 19)
1079 check_string_equality ("shared_substring", s, "987654321")
1080 s := s.shared_substring (5, 9)
1081 check_string_equality ("shared_substring", s, "54321")
1082 s := s.shared_substring (2, 4)
1083 check_string_equality ("shared_substring", s, "432")
1084 s := s.shared_substring (2, 3)
1085 check_string_equality ("shared_substring", s, "32")
1086 s := s.shared_substring (2, 2)
1087 check_string_equality ("shared_substring", s, "2")
1088 end
1089
1090 test_substring is
1091 local
1092 s: IMMUTABLE_STRING_8
1093 do
1094 s := ""
1095 check_string_equality ("substring", s.substring (100, 1000), "")
1096 check_string_equality ("substring", s.substring (-1, 1), "")
1097 check_string_equality ("substring", s.substring (1, 1), "")
1098 check_string_equality ("substring", s.substring (1, 0), "")
1099 s := "12345"
1100 check_string_equality ("substring", s.substring (100, 1000), "")
1101 check_string_equality ("substring", s.substring (-1, 0), "")
1102 check_string_equality ("substring", s.substring (-1, 1), "") -- Current implementation assumes that out-of-range indexes result in empty string
1103 check_string_equality ("substring", s.substring (1, 0), "")
1104 check_string_equality ("substring", s.substring (1, 5), "12345")
1105 check_string_equality ("substring", s.substring (3, 5), "345")
1106 check_string_equality ("substring", s.substring (3, 10), "") -- Current implementation assumes that out-of-range indexes result in empty string
1107 check_string_equality ("substring", s.substring (-100, 100), "") -- Current implementation assumes that out-of-range indexes result in empty string
1108 end
1109
1110 test_substring_index is
1111 -- Perform test on `substring_index'.
1112 local
1113 s: IMMUTABLE_STRING_8
1114 do
1115 s := "foo"
1116 check_equality ("substring_index", s.substring_index ("", 1), 1)
1117 check_equality ("substring_index", s.substring_index ("", 4), 4)
1118
1119 s := "foobarfoobar"
1120 check_equality ("substring_index", s.substring_index ("bar", 1), 4)
1121 check_equality ("substring_index", s.substring_index ("bar", 4), 4)
1122 check_equality ("substring_index", s.substring_index ("bar", 5), 10)
1123 check_equality ("substring_index", s.substring_index ("bar", 11), 0)
1124 end
1125
1126 test_substring_index_in_bounds is
1127 local
1128 s: IMMUTABLE_STRING_8
1129 do
1130 s := "foo"
1131 check_equality ("substring_index_in_bounds", s.substring_index_in_bounds ("f", 1, 1), 1)
1132 check_equality ("substring_index_in_bounds", s.substring_index_in_bounds ("f", 1, 3), 1)
1133 check_equality ("substring_index_in_bounds", s.substring_index_in_bounds ("f", 2, 3), 0)
1134 check_equality ("substring_index_in_bounds", s.substring_index_in_bounds ("o", 1, 3), 2)
1135 check_equality ("substring_index_in_bounds", s.substring_index_in_bounds ("o", 2, 3), 2)
1136 check_equality ("substring_index_in_bounds", s.substring_index_in_bounds ("o", 3, 3), 3)
1137
1138 s := "foobarfoobar"
1139 check_equality ("substring_index_in_bounds", s.substring_index_in_bounds ("bar", 1, 5), 0)
1140 check_equality ("substring_index_in_bounds", s.substring_index_in_bounds ("bar", 1, 6), 4)
1141 check_equality ("substring_index_in_bounds", s.substring_index_in_bounds ("bar", 3, 6), 4)
1142 check_equality ("substring_index_in_bounds", s.substring_index_in_bounds ("bar", 4, 6), 4)
1143 check_equality ("substring_index_in_bounds", s.substring_index_in_bounds ("bar", 4, 10), 4)
1144 check_equality ("substring_index_in_bounds", s.substring_index_in_bounds ("bar", 5, 6), 0)
1145 check_equality ("substring_index_in_bounds", s.substring_index_in_bounds ("bar", 5, 8), 0)
1146 check_equality ("substring_index_in_bounds", s.substring_index_in_bounds ("bar", 5, 11), 0)
1147 check_equality ("substring_index_in_bounds", s.substring_index_in_bounds ("bar", 5, 12), 10)
1148 check_equality ("substring_index_in_bounds", s.substring_index_in_bounds ("bar", 11, 12), 0)
1149 end
1150
1151 test_tagged_out is
1152 do
1153 check_boolean ("tagged_out", ("").tagged_out /= Void)
1154 check_boolean ("tagged_out", not equal (("").tagged_out, ""))
1155 check_boolean ("tagged_out", ("12345").tagged_out /= Void)
1156 check_boolean ("tagged_out", not equal (("12345").tagged_out, ""))
1157 end
1158
1159 test_three_way_comparison is
1160 local
1161 s: IMMUTABLE_STRING_8
1162 p: IMMUTABLE_STRING_8
1163 do
1164 s := "12345"
1165 p := "12345"
1166 check_boolean ("three_way_comparison", s.three_way_comparison (s) = 0)
1167 check_boolean ("three_way_comparison", s.three_way_comparison (p) = 0)
1168 p := "12345a"
1169 check_boolean ("three_way_comparison", s.three_way_comparison (p) = -1)
1170 check_boolean ("three_way_comparison", p.three_way_comparison (s) = 1)
1171 p := "12045"
1172 check_boolean ("three_way_comparison", s.three_way_comparison (p) = 1)
1173 check_boolean ("three_way_comparison", p.three_way_comparison (s) = -1)
1174 s := "123"
1175 check_boolean ("three_way_comparison", s.three_way_comparison (p) = 1)
1176 check_boolean ("three_way_comparison", p.three_way_comparison (s) = -1)
1177
1178 s := ""
1179 p := ""
1180 check_boolean ("three_way_comparison", s.three_way_comparison (s) = 0)
1181 check_boolean ("three_way_comparison", s.three_way_comparison (p) = 0)
1182 p := "a"
1183 check_boolean ("three_way_comparison", s.three_way_comparison (p) = -1)
1184 check_boolean ("three_way_comparison", p.three_way_comparison (s) = 1)
1185 end
1186
1187 test_to_c is
1188 do
1189 if not {PLATFORM}.is_dotnet then
1190 check_boolean ("to_c", ("").to_c /= Void)
1191 check_boolean ("to_c", ("123").to_c /= Void)
1192 end
1193 end
1194
1195 test_to_cil is
1196 do
1197 if {PLATFORM}.is_dotnet then
1198 check_boolean ("to_cil", ("").to_cil /= Void)
1199 check_boolean ("to_cil", ("123").to_cil /= Void)
1200 end
1201 end
1202
1203 test_to_double is
1204 do
1205 check_equality ("to_double", ("0").to_double, {DOUBLE} 0.0)
1206 check_equality ("to_double", ("1").to_double, {DOUBLE} 1.0)
1207 check_equality ("to_double", ("123").to_double, {DOUBLE} 123.0)
1208 check_equality ("to_double", ("0.75").to_double, {DOUBLE} 0.75)
1209 check_equality ("to_double", ("-348.75").to_double, {DOUBLE} -348.75)
1210 check_equality ("to_double", ("62.5e-3").to_double, {DOUBLE} 62.5e-3)
1211 check_equality ("to_double", ("1.e-4").to_double, {DOUBLE} 1.e-4)
1212 check_equality ("to_double", ("1.e-4").to_double, {DOUBLE} 0.0001)
1213 check_equality ("to_double", ("62.5e-3").to_double, {DOUBLE} 62.5e-3)
1214 end
1215
1216 test_to_integer is
1217 do
1218 -- Unsigned integers
1219 check_equality ("to_integer", ("000000").to_integer, 0)
1220 check_equality ("to_integer", ("000000000000000000001").to_integer, 1)
1221 check_equality ("to_integer", ("127").to_integer, 127)
1222 check_equality ("to_integer", ("128").to_integer, 128)
1223 check_equality ("to_integer", ("255").to_integer, 255)
1224 check_equality ("to_integer", ("256").to_integer, 256)
1225 check_equality ("to_integer", ("32767").to_integer, 32767)
1226 check_equality ("to_integer", ("32768").to_integer, 32768)
1227 check_equality ("to_integer", ("65535").to_integer, 65535)
1228 check_equality ("to_integer", ("65536").to_integer, 65536)
1229 check_equality ("to_integer", ("2147483647").to_integer, 2147483647)
1230 -- Positive integers
1231 check_equality ("to_integer", ("+000000").to_integer, 0)
1232 check_equality ("to_integer", ("+000000000000000000001").to_integer, 1)
1233 check_equality ("to_integer", ("+127").to_integer, 127)
1234 check_equality ("to_integer", ("+128").to_integer, 128)
1235 check_equality ("to_integer", ("+255").to_integer, 255)
1236 check_equality ("to_integer", ("+256").to_integer, 256)
1237 check_equality ("to_integer", ("+32767").to_integer, 32767)
1238 check_equality ("to_integer", ("+32768").to_integer, 32768)
1239 check_equality ("to_integer", ("+65535").to_integer, 65535)
1240 check_equality ("to_integer", ("+65536").to_integer, 65536)
1241 check_equality ("to_integer", ("+2147483647").to_integer, 2147483647)
1242 -- Negative integers
1243 check_equality ("to_integer", ("-000000").to_integer, 0)
1244 check_equality ("to_integer", ("-000000000000000000001").to_integer, -1)
1245 check_equality ("to_integer", ("-127").to_integer, -127)
1246 check_equality ("to_integer", ("-128").to_integer, -128)
1247 check_equality ("to_integer", ("-255").to_integer, -255)
1248 check_equality ("to_integer", ("-256").to_integer, -256)
1249 check_equality ("to_integer", ("-32767").to_integer, -32767)
1250 check_equality ("to_integer", ("-32768").to_integer, -32768)
1251 check_equality ("to_integer", ("-65535").to_integer, -65535)
1252 check_equality ("to_integer", ("-65536").to_integer, -65536)
1253 check_equality ("to_integer", ("-2147483647").to_integer, -2147483647)
1254 check_equality ("to_integer", ("-2147483648").to_integer, -2147483648)
1255 end
1256
1257 test_to_integer_64 is
1258 do
1259 -- Unsigned integers
1260 check_equality ("to_integer_64", ("000000").to_integer_64, {INTEGER_64} 0)
1261 check_equality ("to_integer_64", ("000000000000000000001").to_integer_64, {INTEGER_64} 1)
1262 check_equality ("to_integer_64", ("127").to_integer_64, {INTEGER_64} 127)
1263 check_equality ("to_integer_64", ("128").to_integer_64, {INTEGER_64} 128)
1264 check_equality ("to_integer_64", ("255").to_integer_64, {INTEGER_64} 255)
1265 check_equality ("to_integer_64", ("256").to_integer_64, {INTEGER_64} 256)
1266 check_equality ("to_integer_64", ("32767").to_integer_64, {INTEGER_64} 32767)
1267 check_equality ("to_integer_64", ("32768").to_integer_64, {INTEGER_64} 32768)
1268 check_equality ("to_integer_64", ("65535").to_integer_64, {INTEGER_64} 65535)
1269 check_equality ("to_integer_64", ("65536").to_integer_64, {INTEGER_64} 65536)
1270 check_equality ("to_integer_64", ("2147483647").to_integer_64, {INTEGER_64} 2147483647)
1271 check_equality ("to_integer_64", ("2147483648").to_integer_64, {INTEGER_64} 2147483648)
1272 check_equality ("to_integer_64", ("9223372036854775807").to_integer_64, {INTEGER_64} 0x7FFF_FFFF_FFFF_FFFF)
1273 -- Positive integers
1274 check_equality ("to_integer_64", ("+000000").to_integer_64, {INTEGER_64} 0)
1275 check_equality ("to_integer_64", ("+000000000000000000001").to_integer_64, {INTEGER_64} 1)
1276 check_equality ("to_integer_64", ("+127").to_integer_64, {INTEGER_64} 127)
1277 check_equality ("to_integer_64", ("+128").to_integer_64, {INTEGER_64} 128)
1278 check_equality ("to_integer_64", ("+255").to_integer_64, {INTEGER_64} 255)
1279 check_equality ("to_integer_64", ("+256").to_integer_64, {INTEGER_64} 256)
1280 check_equality ("to_integer_64", ("+32767").to_integer_64, {INTEGER_64} 32767)
1281 check_equality ("to_integer_64", ("+32768").to_integer_64, {INTEGER_64} 32768)
1282 check_equality ("to_integer_64", ("+65535").to_integer_64, {INTEGER_64} 65535)
1283 check_equality ("to_integer_64", ("+65536").to_integer_64, {INTEGER_64} 65536)
1284 check_equality ("to_integer_64", ("+2147483647").to_integer_64, {INTEGER_64} 2147483647)
1285 check_equality ("to_integer_64", ("+2147483648").to_integer_64, {INTEGER_64} 2147483648)
1286 check_equality ("to_integer_64", ("+9223372036854775807").to_integer_64, {INTEGER_64} 0x7FFF_FFFF_FFFF_FFFF)
1287 -- Negative integers
1288 check_equality ("to_integer_64", ("-000000").to_integer_64, {INTEGER_64} 0)
1289 check_equality ("to_integer_64", ("-000000000000000000001").to_integer_64, {INTEGER_64} -1)
1290 check_equality ("to_integer_64", ("-127").to_integer_64, {INTEGER_64} -127)
1291 check_equality ("to_integer_64", ("-128").to_integer_64, {INTEGER_64} -128)
1292 check_equality ("to_integer_64", ("-255").to_integer_64, {INTEGER_64} -255)
1293 check_equality ("to_integer_64", ("-256").to_integer_64, {INTEGER_64} -256)
1294 check_equality ("to_integer_64", ("-32767").to_integer_64, {INTEGER_64} -32767)
1295 check_equality ("to_integer_64", ("-32768").to_integer_64, {INTEGER_64} -32768)
1296 check_equality ("to_integer_64", ("-65535").to_integer_64, {INTEGER_64} -65535)
1297 check_equality ("to_integer_64", ("-65536").to_integer_64, {INTEGER_64} -65536)
1298 check_equality ("to_integer_64", ("-2147483647").to_integer_64, {INTEGER_64} -2147483647)
1299 check_equality ("to_integer_64", ("-2147483648").to_integer_64, {INTEGER_64} -2147483648)
1300 check_equality ("to_integer_64", ("-9223372036854775807").to_integer_64, {INTEGER_64} -0x7FFF_FFFF_FFFF_FFFF)
1301 check_equality ("to_integer_64", ("-9223372036854775808").to_integer_64, {INTEGER_64} -0x8000_0000_0000_0000)
1302 end
1303
1304 test_to_real is
1305 do
1306 check_equality ("to_real", ("0").to_real, {REAL} 0.0)
1307 check_equality ("to_real", ("1").to_real, {REAL} 1.0)
1308 check_equality ("to_real", ("123").to_real, {REAL} 123.0)
1309 check_equality ("to_real", ("0.75").to_real, {REAL} 0.75)
1310 check_equality ("to_real", ("-348.75").to_real, {REAL} -348.75)
1311 check_equality ("to_real", ("62.5e-3").to_real, {REAL} 62.5e-3)
1312 end
1313
1314 test_twin is
1315 local
1316 s: IMMUTABLE_STRING_8
1317 do
1318 s := ""
1319 check_string_equality ("twin", s.twin, "")
1320 check_boolean ("twin", s /= s.twin)
1321 check_boolean ("twin", s.shared_with (s.twin))
1322 s := "12345"
1323 check_string_equality ("twin", s.twin, "12345")
1324 check_boolean ("twin", s /= s.twin)
1325 check_boolean ("twin", s.shared_with (s.twin))
1326 end
1327
1328 test_valid_index is
1329 do
1330 check_boolean ("valid_index", not ("").valid_index (-1))
1331 check_boolean ("valid_index", not ("").valid_index (0))
1332 check_boolean ("valid_index", not ("").valid_index (1))
1333 check_boolean ("valid_index", not ("").valid_index (2))
1334 check_boolean ("valid_index", not ("123").valid_index (-1))
1335 check_boolean ("valid_index", not ("123").valid_index (0))
1336 check_boolean ("valid_index", ("123").valid_index (1))
1337 check_boolean ("valid_index", ("123").valid_index (2))
1338 check_boolean ("valid_index", ("123").valid_index (3))
1339 check_boolean ("valid_index", not ("123").valid_index (4))
1340 end
1341
1342 feature {NONE} -- Checking
1343
1344 check_equality (a_name: STRING; a, b: ANY) is
1345 -- If `a' and `b' are not equal print something on the console.
1346 require
1347 a_name_not_void: a_name /= Void
1348 do
1349 if not equal (a, b) then
1350 io.put_string ("Not OK: " + a_name)
1351 io.put_new_line
1352 end
1353 end
1354
1355 check_string_equality (a_name: STRING; a, b: IMMUTABLE_STRING_8) is
1356 -- If `a' and `b' are not equal print something on the console.
1357 require
1358 a_name_not_void: a_name /= Void
1359 do
1360 if not equal (a, b) then
1361 io.put_string ("Not OK: " + a_name)
1362 io.put_new_line
1363 end
1364 end
1365
1366 check_boolean (a_name: STRING; b: BOOLEAN) is
1367 -- If `a' and `b' are not equal print something on the console.
1368 require
1369 a_name_not_void: a_name /= Void
1370 do
1371 if not b then
1372 io.put_string ("Not OK: " + a_name)
1373 io.put_new_line
1374 end
1375 end
1376
1377 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23