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

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23