2 # Copyright (C) 2001-2010, Parrot Foundation.
7 t/op/string.t - Parrot Strings
15 Tests Parrot string registers and operations.
19 .include 'except_types.pasm'
22 .include 'test_more.pir'
31 three_argument_chopn()
32 three_argument_chopn__oob_values()
35 exception_substr_null_string()
36 exception_substr_oob()
37 exception_substr_oob_neg()
38 len_greater_than_strlen()
39 len_greater_than_strlen_neg_offset()
40 replace_w_rep_eq_length()
41 replace_w_replacement_gt_length()
42 replace_w_replacement_lt_length()
44 replace__offset_at_end_of_string()
45 exception_replace__offset_past_end_of_string()
46 replace_neg_offset_repl_eq_length()
47 replace_neg_offset_repl_gt_length()
48 replace_neg_offset_repl_lt_length()
49 exception_replace_neg_offset_out_of_string()
50 replace_length_gt_strlen()
51 replace_length_gt_strlen_neg_offset()
54 exception_substr__pos_offset_zero_length_string()
55 substr_offset_zero_zero_length_string()
56 exception_substr_offset_one_zero_length_string()
57 exception_substr_neg_offset_zero_length_string()
58 zero_length_substr_zero_length_string()
59 zero_length_substr_zero_length_string()
60 three_arg_substr_zero_length_string()
61 replace_zero_length_string()
62 four_arg_substr_replace_zero_length_string()
63 concat_s_s_sc_null_onto_null()
64 concat_s_sc_repeated_two_arg_concats()
65 concat_s_s_sc_foo_one_onto_null()
68 concat_ensure_copy_is_made()
70 same_constant_twice_bug()
71 exception_two_param_ord_empty_string()
72 exception_two_param_ord_empty_string_register()
73 exception_three_param_ord_empty_string()
74 exception_three_param_ord_empty_string_register()
75 two_param_ord_one_character_string()
76 two_param_ord_multi_character_string()
77 two_param_ord_one_character_string_register()
78 three_param_ord_one_character_string()
79 three_param_ord_one_character_string_register()
80 three_param_ord_multi_character_string()
81 three_param_ord_multi_character_string_register()
82 exception_three_param_ord_multi_character_string()
83 exception_three_param_ord_multi_character_string()
84 three_param_ord_one_character_string_from_end()
85 three_param_ord_one_character_string_register_from_end()
86 three_param_ord_multi_character_string_from_end()
87 three_param_ord_multi_character_string_register_from_end()
88 exception_three_param_ord_multi_character_string_register_from_end_oob()
89 chr_of_thirty_two_is_space_in_ascii()
90 chr_of_sixty_five_is_a_in_ascii()
91 chr_of_one_hundred_and_twenty_two_is_z_in_ascii()
94 exception_repeat_oob()
95 exception_repeat_oob_repeat_p_p_p()
96 exception_repeat_oob_repeate_p_p_i()
98 index_three_arg_form()
100 index_four_arg_form_bug_twenty_two_thousand_seven_hundred_and_eighteen()
103 index_embedded_nulls()
105 index_big_hard_to_match_strings()
106 index_with_different_charsets()
107 negative_index_bug_35959()
108 index_multibyte_matching()
109 index_multibyte_matching_two()
113 concat_or_substr_cow()
114 constant_to_cstring()
115 cow_with_chopn_leaving_original_untouched()
116 check_that_bug_bug_16874_was_fixed()
118 ord_and_substring_see_bug_17035()
121 other_form_of_sprintf_op()
122 sprintf_left_justify()
123 correct_precision_for_sprintf_x()
127 split_on_null_string()
128 split_on_empty_string()
129 split_on_non_empty_string()
137 three_param_ord_one_character_string_register_i()
138 three_param_ord_multi_character_string_i()
139 three_param_ord_multi_character_string_register_i()
140 exception_three_param_ord_multi_character_string_i()
141 exception_three_param_ord_multi_character_string_i()
142 three_param_ord_one_character_string_from_end_i()
143 three_param_ord_one_character_string_register_from_end_i()
144 three_param_ord_multi_character_string_from_end_i()
145 three_param_ord_multi_character_string_register_from_end_i()
146 exception_three_param_ord_multi_character_string_register_from_end_oob_i()
148 constant_string_and_modify_in_situ_op_rt_bug_60030()
149 corner_cases_of_numification()
150 non_canonical_nan_and_inf()
153 join_get_string_returns_a_null_string()
158 .macro exception_is ( M )
160 .local string message
161 .get_results (exception)
163 message = exception['message']
164 is( message, .M, .M )
171 is( $S4, "JAPH", '' )
172 is( $S5, "JAPH", '' )
179 is( $S0, "Foo1", '' )
180 is( $S1, "Foo1", '' )
183 is( $S1, "Bar1", '' )
199 .sub zero_length_substr
202 substr $S3, $S4, 1, 0
207 .sub chopn_with_clone
216 is( $S4, "JAPH", '' )
217 is( $S5, "japh", '' )
218 is( $S3, "JAPHxyzw", '' )
221 .sub chopn_oob_values
222 set $S1, "A string of length 21"
224 is( $S1, "A string of length 21", '' )
227 is( $S1, "A string of lengt", '' )
231 is( $S1, "A st", '' )
233 $S1 = chopn $S1, 1000
237 .sub three_argument_chopn
240 is( $S1, "Parrot", '' )
241 is( $S2, "Parrot", '' )
244 is( $S1, "Parrot", '' )
245 is( $S2, "Parro", '' )
249 is( $S1, "Parrot", '' )
250 is( $S2, "Parr", '' )
252 chopn $S2, "Parrot", 3
261 is( $S3, "Parrot", '' )
264 .sub three_argument_chopn__oob_values
267 is( $S1, "Parrot", '' )
271 is( $S1, "Parrot", '' )
276 set $S4, "12345JAPH01"
280 substr $S5, $S4, $I4, $I5
281 is( $S5, "JAPH", '' )
283 substr $S5, $S4, $I4, 4
284 is( $S5, "JAPH", '' )
286 substr $S5, $S4, 5, $I5
287 is( $S5, "JAPH", '' )
289 substr $S5, $S4, 5, 4
290 is( $S5, "JAPH", '' )
292 substr $S5, "12345JAPH01", $I4, $I5
293 is( $S5, "JAPH", '' )
295 substr $S5, "12345JAPH01", $I4, 4
296 is( $S5, "JAPH", '' )
298 substr $S5, "12345JAPH01", 5, $I5
299 is( $S5, "JAPH", '' )
301 substr $S5, "12345JAPH01", 5, 4
302 is( $S5, "JAPH", '' )
306 .sub neg_substr_offset
307 set $S0, "A string of length 21"
310 substr $S1, $S0, $I0, $I1
311 is( $S0, "A string of length 21", '' )
312 is( $S1, "length", '' )
315 .sub exception_substr_null_string
320 eh = new ['ExceptionHandler']
321 eh.'handle_types'(.EXCEPTION_SUBSTR_OUT_OF_STRING)
329 is(r, 1, "substr with null string throws" )
332 # This asks for substring that shouldn't be allowed...
333 .sub exception_substr_oob
336 set $S0, "A string of length 21"
339 eh = new ['ExceptionHandler']
340 eh.'handle_types'(.EXCEPTION_SUBSTR_OUT_OF_STRING)
345 substr $S1, $S0, $I0, $I1
349 is(r, 1, "substr outside string throws" )
352 # This asks for substring that shouldn't be allowed...
353 .sub exception_substr_oob_neg
356 set $S0, "A string of length 21"
359 eh = new ['ExceptionHandler']
360 eh.'handle_types'(.EXCEPTION_SUBSTR_OUT_OF_STRING)
365 substr $S1, $S0, $I0, $I1
369 is(r, 1, "substr outside string throws - negative" )
372 # This asks for substring much greater than length of original string
373 .sub len_greater_than_strlen
374 set $S0, "A string of length 21"
377 substr $S1, $S0, $I0, $I1
378 is( $S0, "A string of length 21", '' )
379 is( $S1, "length 21", '' )
382 # The same, with a negative offset
383 .sub len_greater_than_strlen_neg_offset
384 set $S0, "A string of length 21"
387 substr $S1, $S0, $I0, $I1
388 is( $S0, "A string of length 21", '' )
389 is( $S1, "length 21", '' )
392 .sub replace_w_rep_eq_length
393 set $S0, "abcdefghijk"
395 replace $S2, $S0, 4, 3, $S1
396 is( $S2, "abcdxyzhijk", '' )
399 .sub replace_w_replacement_gt_length
400 set $S0, "abcdefghijk"
402 $S2 = replace $S0, 4, 3, $S1
403 is( $S2, "abcdxyz0123hijk", '' )
406 .sub replace_w_replacement_lt_length
407 set $S0, "abcdefghijk"
409 $S2 = replace $S0, 4, 3, $S1
410 is( $S2, "abcdxhijk", '' )
413 .sub replace__offset_at_end_of_string
414 set $S0, "abcdefghijk"
416 $S2 = replace $S0, 11, 3, $S1
417 is( $S2, "abcdefghijkxyz", '' )
421 # Check that string hashval properly updated.
427 $S0 = replace $S0, 1, 1, ''
429 is( $S1, '42', 'replace behave it self')
432 .sub exception_replace__offset_past_end_of_string
433 set $S0, "abcdefghijk"
436 $S2 = replace $S0, 12, 3, $S1
439 .exception_is( "Can only replace inside string or index after end of string" )
442 .sub replace_neg_offset_repl_eq_length
443 set $S0, "abcdefghijk"
445 $S2 = replace $S0, -3, 3, $S1
446 is( $S2, "abcdefghxyz", '' )
449 .sub replace_neg_offset_repl_gt_length
450 set $S0, "abcdefghijk"
452 $S2 = replace $S0, -6, 2, $S1
453 is( $S2, "abcdexyzhijk", '' )
456 .sub replace_neg_offset_repl_lt_length
457 set $S0, "abcdefghijk"
459 $S2 = replace $S0, -6, 4, $S1
460 is( $S2, "abcdexyzjk", '' )
463 .sub exception_replace_neg_offset_out_of_string
464 set $S0, "abcdefghijk"
467 $S2 = replace $S0, -12, 4, $S1
470 .exception_is( "Can only replace inside string or index after end of string" )
473 .sub replace_length_gt_strlen
474 set $S0, "abcdefghijk"
476 $S2 = replace $S0, 3, 11, $S1
477 is( $S2, "abcxyz", '' )
480 .sub replace_length_gt_strlen_neg_offset
481 set $S0, "abcdefghijk"
483 $S2 = replace $S0, -3, 11, $S1
484 is( $S2, "abcdefghxyz", '' )
487 .sub replace_only_substr
488 set $S0, "abcdefghijk"
490 $S2 = replace $S0, 3, 3, $S1
491 is( $S2, "abcxyzghijk", '' )
494 .sub three_arg_substr
500 .sub exception_substr__pos_offset_zero_length_string
503 substr $S1, $S0, 10, 3
506 .exception_is( "Cannot take substr outside string" )
509 .sub substr_offset_zero_zero_length_string
511 substr $S1, $S0, 0, 1
515 .sub exception_substr_offset_one_zero_length_string
518 substr $S1, $S0, -1, 1
521 .exception_is( "Cannot take substr outside string" )
524 .sub exception_substr_neg_offset_zero_length_string
527 substr $S1, $S0, -10, 5
529 .exception_is( "Cannot take substr outside string" )
532 .sub zero_length_substr_zero_length_string
534 substr $S1, $S0, 10, 0
538 .sub zero_length_substr_zero_length_string
540 substr $S1, $S0, -10, 0
544 .sub three_arg_substr_zero_length_string
550 .sub replace_zero_length_string
553 $S2 = replace $S0, 0, 3, $S1
558 $S5 = replace $S3, 0, 0, $S4
559 is( $S5, "abcde", '' )
562 .sub four_arg_substr_replace_zero_length_string
565 $S0 = replace $S0, 0, 3, $S1
570 $S2 = replace $S2, 0, 0, $S3
571 is( $S2, "abcde", '' )
574 .sub concat_s_s_sc_null_onto_null
581 .sub concat_s_sc_repeated_two_arg_concats
588 is( $S12, "hihihihihihihihihihi", '' )
591 .sub concat_s_s_sc_foo_one_onto_null
595 is( $S0, "foo1", '' )
596 is( $S2, "foo2", '' )
599 .sub test_concat_s_s_sc
603 is( $S1, "fishbone", '' )
606 .sub concat_s_s_sc_s_sc
609 concat $S0, "japh", "JAPH"
610 is( $S0, "japhJAPH", '' )
612 concat $S0, $S1, "JAPH"
613 is( $S0, "japhJAPH", '' )
615 concat $S0, "japh", $S2
616 is( $S0, "japhJAPH", '' )
619 is( $S0, "japhJAPH", '' )
622 .sub concat_ensure_copy_is_made
628 is( $S2, "JAPH", '' )
631 .sub same_constant_twice_bug
636 is( $S1, "foo", 'same constant twice bug' )
637 is( $S0, "", 'same constant twice bug' )
640 .sub exception_two_param_ord_empty_string
643 ok(0, 'no exception: 2-param ord, empty string' )
645 .exception_is( 'Cannot get character of empty string' )
648 .sub exception_two_param_ord_empty_string_register
651 ok( 0, 'no exception: 2-param ord, empty string register' )
653 .exception_is( 'Cannot get character of NULL string' )
656 .sub exception_three_param_ord_empty_string
659 ok(0, 'no exception: 3-param ord, empty string' )
661 .exception_is( 'Cannot get character of empty string' )
664 .sub exception_three_param_ord_empty_string_register
667 ok( 0, 'no exception: 3-param ord, empty string register' )
669 .exception_is( 'Cannot get character of NULL string' )
672 .sub two_param_ord_one_character_string
674 is( $I0, "97", '2-param ord, one-character string' )
677 .sub two_param_ord_multi_character_string
679 is( $I0, "97", '2-param ord, multi-character string' )
682 .sub two_param_ord_one_character_string_register
685 is( $I0, "97", '2-param ord, one-character string register' )
688 .sub three_param_ord_one_character_string
690 is( $I0, "97", '3-param ord, one-character string' )
693 .sub three_param_ord_one_character_string_register
696 is( $I0, "97", '3-param ord, one-character string register' )
699 .sub three_param_ord_multi_character_string
701 is( $I0, "98", '3-param ord, multi-character string' )
704 .sub three_param_ord_multi_character_string_register
707 is( $I0, "98", '3-param ord, multi-character string register' )
710 .sub exception_three_param_ord_multi_character_string
713 ok( 0, 'no exception: 3-param ord, multi-character string' )
715 .exception_is( 'Cannot get character past end of string' )
718 .sub exception_three_param_ord_multi_character_string
722 ok( 0, 'no exception: 3-param ord, multi-character string' )
724 .exception_is( 'Cannot get character past end of string' )
727 .sub three_param_ord_one_character_string_from_end
729 is( $I0, "97", '3-param ord, one-character string, from end' )
732 .sub three_param_ord_one_character_string_register_from_end
735 is( $I0, "97", '3-param ord, one-character string register, from end' )
738 .sub three_param_ord_multi_character_string_from_end
740 is( $I0, "98", '3-param ord, multi-character string, from end' )
743 .sub three_param_ord_multi_character_string_register_from_end
746 is( $I0, "98", '3-param ord, multi-character string register, from end' )
749 .sub exception_three_param_ord_multi_character_string_register_from_end_oob
753 ok( 0, 'no exception: 3-param ord, multi-character string register, from end, OOB' )
755 .exception_is( 'Cannot get character before beginning of string' )
758 .sub chr_of_thirty_two_is_space_in_ascii
760 is( $S0, " ", 'chr of 32 is space in ASCII' )
763 .sub chr_of_sixty_five_is_a_in_ascii
765 is( $S0, "A", 'chr of 65 is A in ASCII' )
768 .sub chr_of_one_hundred_and_twenty_two_is_z_in_ascii
770 is( $S0, "z", 'chr of 122 is z in ASCII' )
774 set $S0, "I've told you once, I've told you twice..."
775 ok( $S0, 'normal strings are true' )
778 ok( $S0, '0.0 is true' )
781 nok( $S0, 'empty string is false' )
784 nok( $S0, '"0" string is false' )
787 ok( $S0, 'string "0e0" is true' )
790 ok( $S0, 'string "x" is true' )
793 ok( $S0, 'string "\\x0" is true' )
796 ok( $S0, 'string "\n" is true' )
799 ok( $S0, 'string " " is true' )
801 # An empty register should be false...
802 nok( $S1, 'empty register is false' )
805 .sub repeat_s_s_sc_i_ic
808 is( $S0, "x", 'repeat_s_s|sc_i|ic' )
809 is( $S1, "xxxxxxxxxxxx", 'repeat_s_s|sc_i|ic' )
814 is( $S2, "X", 'repeat_s_s|sc_i|ic' )
815 is( $S3, "XXXXXXXXXXXX", 'repeat_s_s|sc_i|ic' )
818 is( $S4, "~~~~~~~~~~~~", 'repeat_s_s|sc_i|ic' )
821 is( $S5, "~~~~~~~~~~~~", 'repeat_s_s|sc_i|ic' )
825 is( $S6, "", 'repeat_s_s|sc_i|ic' )
828 .sub exception_repeat_oob
830 repeat $S0, "japh", -1
832 .exception_is( 'Cannot repeat with negative arg' )
835 .sub exception_repeat_oob_repeat_p_p_p
839 $P2 = new ['Integer']
843 .exception_is( 'Cannot repeat with negative arg' )
846 .sub exception_repeat_oob_repeate_p_p_i
852 .exception_is( 'Cannot repeat with negative arg' )
855 .sub encodingname_oob
857 $S0 = encodingname -1
858 $S0 = encodingname $I0
859 ok( 1, "no exceptions in encodingname_oob" )
862 .sub index_three_arg_form
866 is( $I1, "0", 'index, 3-arg form' )
870 is( $I1, "3", 'index, 3-arg form' )
874 is( $I1, "-1", 'index, 3-arg form' )
876 # Ascii - Non-ascii, same content
878 set $S1, unicode:"hello"
880 is( $I1, "0", 'index, 3-arg form' )
882 is( $I1, "0", 'index, 3-arg form' )
884 # Non-ascii, source shorter than searched
885 set $S0, unicode:"-o"
886 set $S1, unicode:"@INC"
888 is( $I1, "-1", 'index, 3-arg form' )
891 .sub index_four_arg_form
894 index $I1, $S0, $S1, 0
895 is( $I1, "1", 'index, 4-arg form' )
897 index $I1, $S0, $S1, 2
898 is( $I1, "4", 'index, 4-arg form' )
901 index $I1, $S0, $S1, 0
902 is( $I1, "-1", 'index, 4-arg form' )
904 # Ascii - Non-ascii, same content
906 set $S1, unicode:"hello"
907 index $I1, $S0, $S1, 0
908 is( $I1, "0", 'index, 4-arg form' )
909 index $I1, $S1, $S0, 0
910 is( $I1, "0", 'index, 4-arg form' )
913 .sub index_four_arg_form_bug_twenty_two_thousand_seven_hundred_and_eighteen
914 set $S1, "This is not quite right"
916 index $I0, $S1, $S0, 0
917 is( $I0, "4", 'index, 4-arg form, bug 22718' )
920 index $I0, $S1, $S0, 0
921 is( $I0, "2", 'index, 4-arg form, bug 22718' )
925 $S0 = unicode:"bubuc"
928 $I0 = index $S0, $S1, 0
929 is ($I0, 2, 'index, 4-arg, partial-match causes failure: TT #1482')
932 .sub index_null_strings
936 is( $I1, "-1", 'index, null strings' )
938 index $I1, $S0, $S1, 0
939 is( $I1, "-1", 'index, null strings' )
941 index $I1, $S0, $S1, 5
942 is( $I1, "-1", 'index, null strings' )
944 index $I1, $S0, $S1, 6
945 is( $I1, "-1", 'index, null strings' )
950 is( $I1, "-1", 'index, null strings' )
952 index $I1, $S0, $S1, 0
953 is( $I1, "-1", 'index, null strings' )
958 is( $I1, "-1", 'index, null strings' )
963 is( $I1, "-1", 'index, null strings' )
966 .sub index_embedded_nulls
967 set $S0, "Par\0\0rot"
970 is( $I1, "3", 'index, embedded nulls' )
972 index $I1, $S0, $S1, 4
973 is( $I1, "4", 'index, embedded nulls' )
976 .sub index_big_strings
978 repeat $S0, $S0, 10000
982 is( $I1, "0", 'index, big strings' )
984 index $I1, $S0, $S1, 1234
985 is( $I1, "1234", 'index, big strings' )
987 index $I1, $S0, $S1, 9501
988 is( $I1, "-1", 'index, big strings' )
991 # Builds a 24th iteration fibonacci string (approx. 100K)
992 .sub index_big_hard_to_match_strings
1003 is( $I1, "46368", 'index, big, hard to match strings' )
1004 index $I1, $S1, $S2, 50000
1005 is( $I1, "-1", 'index, big, hard to match strings' )
1008 .sub index_with_different_charsets
1012 is( $I1, "3", 'default - default' )
1014 set $S0, ascii:"Parrot"
1015 set $S1, ascii:"rot"
1017 is( $I1, "3", 'ascii - ascii')
1020 set $S1, ascii:"rot"
1022 is( $I1, "3", 'default - ascii' )
1024 set $S0, ascii:"Parrot"
1027 is( $I1, "3", 'ascii - default' )
1029 set $S0, binary:"Parrot"
1030 set $S1, binary:"rot"
1032 is( $I1, 3, 'binary - binary' )
1035 .sub negative_index_bug_35959
1036 index $I1, "u", "t", -123456
1037 is( $I1, "-1", 'negative index #35959' )
1039 index $I1, "u", "t", -123456789
1040 is( $I1, "-1", 'negative index #35959' )
1043 .sub index_multibyte_matching
1044 skip( 3, "Pending rework of creating non-ascii literals" )
1047 # find_chartype $I0, "8859-1"
1048 # set_chartype $S0, $I0
1049 # find_encoding $I0, "singlebyte"
1050 # set_encoding $S0, $I0
1051 # find_encoding $I0, "utf8"
1052 # find_chartype $I1, "unicode"
1053 # transcode $S1, $S0, $I0, $I1
1054 # is( $S0, $S1, 'equal' );
1056 # index $I0, $S0, $S1
1057 # is( $I0, "0", 'index, multibyte matching' )
1059 # index $I0, $S1, $S0
1060 # is( $I0, "0", 'index, multibyte matching' )
1063 .sub index_multibyte_matching_two
1064 skip( 2, "Pending rework of creating non-ascii literals" )
1065 # set $S0, "\xAB\xBA"
1066 # set $S1, "foo\xAB\xAB\xBAbar"
1067 # find_chartype $I0, "8859-1"
1068 # set_chartype $S0, $I0
1069 # find_encoding $I0, "singlebyte"
1070 # set_encoding $S0, $I0
1071 # find_chartype $I0, "unicode"
1072 # find_encoding $I1, "utf8"
1073 # transcode $S1, $S1, $I1, $I0
1074 # index $I0, $S0, $S1
1075 # is( $I0, "-1", 'index, multibyte matching 2' )
1076 # index $I0, $S1, $S0
1077 # is( $I0, "4", 'index, multibyte matching 2' )
1083 is( $S0, "80.43", 'num to string' )
1087 is( $S0, "-1.111111", 'num to string' )
1093 is( $I0, "123", 'string to int' )
1097 is( $I0, "1", 'string to int' )
1101 is( $I0, "-1", 'string to int' )
1103 set $S0, "Not a number"
1105 is( $I0, "0", 'string to int' )
1109 is( $I0, "0", 'string to int' )
1115 is( $N0, "6", '6foo to num' )
1119 is( $N0, "16", '16foo to num' )
1122 .sub concat_or_substr_cow
1126 concat $S2, $S2, $S0
1127 concat $S2, $S2, $S1
1128 is( $S2, "<JAPH>", 'concat/substr (COW)' )
1130 substr $S0, $S2, 1, 4
1131 is( $S0, "JAPH", 'concat/substr (COW)' )
1134 .sub constant_to_cstring
1135 stringinfo $I0, "\n", 2
1136 stringinfo $I1, "\n", 2
1137 is( $I1, $I0, 'constant to cstring' )
1139 stringinfo $I2, "\n", 2
1140 is( $I2, $I0, 'constant to cstring' )
1143 .sub cow_with_chopn_leaving_original_untouched
1147 is( $S0, "ABC", 'COW with chopn leaving original untouched' )
1148 is( $S1, "ABCD", 'COW with chopn leaving original untouched' )
1151 .sub check_that_bug_bug_16874_was_fixed
1159 is( $S15, "foo bar quux ", 'Check that bug #16874 was fixed' )
1167 concat $S1, $S0, $S2
1168 concat $S3, "mic", "hael"
1169 concat $S3, $S3, $S2
1171 ok(0, 'failed stress concat test')
1177 ok(1, 'stress concat test')
1180 .sub ord_and_substring_see_bug_17035
1182 substr $S1, $S0, 2, 3
1192 ok(1, 'ord and substring #17035')
1195 ok(0, 'failed: ord and substring #17035')
1202 new $P1, 'ResizablePMCArray'
1206 new $P1, 'ResizablePMCArray'
1210 new $P1, 'ResizablePMCArray'
1214 new $P1, 'ResizablePMCArray'
1218 sprintf $S2, $S1, $P1
1219 is( $S2, $S99, $S1 )
1223 new $P4, 'ResizableIntegerArray'
1224 set $S1, "Hello, %s"
1226 set $S99, "Hello, Parrot!"
1227 local_branch $P4, NEWARYS
1228 local_branch $P4, PRINTF
1230 set $S1, "Hash[0x%x]"
1232 set $S99, "Hash[0x100]"
1233 local_branch $P4, NEWARYI
1234 local_branch $P4, PRINTF
1236 set $S1, "Hash[0x%lx]"
1238 set $S99, "Hash[0x100]"
1239 local_branch $P4, NEWARYI
1240 local_branch $P4, PRINTF
1242 set $S1, "Hello, %.2s!"
1244 set $S99, "Hello, Pa!"
1245 local_branch $P4, NEWARYS
1246 local_branch $P4, PRINTF
1248 set $S1, "Hello, %Ss"
1250 set $S99, "Hello, Hello, Pa!"
1251 local_branch $P4, NEWARYS
1252 local_branch $P4, PRINTF
1258 local_branch $P4, NEWARYP
1259 local_branch $P4, PRINTF
1261 set $S1, "-255 == %vd"
1263 set $S99, "-255 == -255"
1264 local_branch $P4, NEWARYI
1265 local_branch $P4, PRINTF
1267 set $S1, "+123 == %+vd"
1269 set $S99, "+123 == +123"
1270 local_branch $P4, NEWARYI
1271 local_branch $P4, PRINTF
1273 set $S1, "256 == %vu"
1275 set $S99, "256 == 256"
1276 local_branch $P4, NEWARYI
1277 local_branch $P4, PRINTF
1279 set $S1, "1 == %+vu"
1282 local_branch $P4, NEWARYI
1283 local_branch $P4, PRINTF
1285 set $S1, "001 == %0.3u"
1287 set $S99, "001 == 001"
1288 local_branch $P4, NEWARYI
1289 local_branch $P4, PRINTF
1291 set $S1, "001 == %+0.3u"
1293 set $S99, "001 == 001"
1294 local_branch $P4, NEWARYI
1295 local_branch $P4, PRINTF
1297 set $S1, "0.500000 == %f"
1299 set $S99, "0.500000 == 0.500000"
1300 local_branch $P4, NEWARYN
1301 local_branch $P4, PRINTF
1303 set $S1, "0.500 == %5.3f"
1305 set $S99, "0.500 == 0.500"
1306 local_branch $P4, NEWARYN
1307 local_branch $P4, PRINTF
1309 set $S1, "0.001 == %g"
1311 set $S99, "0.001 == 0.001"
1312 local_branch $P4, NEWARYN
1313 local_branch $P4, PRINTF
1315 set $S1, "1e+06 == %g"
1317 set $S99, "1e+06 == 1e+06"
1318 local_branch $P4, NEWARYN
1319 local_branch $P4, PRINTF
1321 set $S1, "0.5 == %3.3g"
1323 set $S99, "0.5 == 0.5"
1324 local_branch $P4, NEWARYN
1325 local_branch $P4, PRINTF
1330 local_branch $P4, NEWARYI
1331 local_branch $P4, PRINTF
1333 set $S1, "That's all, %s"
1335 set $S99, "That's all, folks!"
1336 local_branch $P4, NEWARYS
1337 local_branch $P4, PRINTF
1340 .sub other_form_of_sprintf_op
1341 new $P4, 'ResizableIntegerArray'
1345 new $P1, 'ResizablePMCArray'
1347 sprintf $P3, $P2, $P1
1348 is( $P3, "15 is 1111", 'other form of sprintf op' )
1351 set $P2, "128 is %o"
1352 new $P1, 'ResizablePMCArray'
1354 sprintf $P3, $P2, $P1
1355 is( $P3, "128 is 200", 'other form of sprintf op' )
1358 .sub sprintf_left_justify
1359 $P0 = new 'ResizablePMCArray'
1369 $S0 = sprintf "%-*s - %s", $P0
1370 is( $S0, "foo - bar", 'sprintf - left justify' )
1374 .sub correct_precision_for_sprintf_x
1375 .include "iglobals.pasm"
1377 # Create the string via concat
1378 .local pmc interp # a handle to our interpreter object.
1381 config = interp[.IGLOBALS_CONFIG_HASH]
1382 .local int intvalsize
1383 intvalsize = config['intvalsize']
1387 $I1 = intvalsize * 2
1395 le $I0, 20, padding_loop
1397 # Now see what sprintf comes up with
1398 $P0 = new 'ResizablePMCArray'
1400 $S1 = sprintf "%-20x", $P0
1401 is( $S1, $S0, 'Correct precision for %x' )
1404 .sub test_find_encoding
1405 skip( 4, "Pending reimplementation of find_encoding" )
1406 # find_encoding $I0, "singlebyte"
1407 # is( $I0, "0", 'find_encoding' )
1408 # find_encoding $I0, "utf8"
1409 # is( $I0, "1", 'find_encoding' )
1410 # find_encoding $I0, "utf16"
1411 # is( $I0, "2", 'find_encoding' )
1412 # find_encoding $I0, "utf32"
1413 # is( $I0, "3", 'find_encoding' )
1419 is( $S4, "JAPH", 'assign' )
1420 is( $S5, "JAPH", 'assign' )
1423 .sub assign_and_globber
1426 assign $S4, "Parrot"
1427 is( $S4, "Parrot", 'assign & globber' )
1428 is( $S5, "JAPH", 'assign & globber' )
1431 .sub split_on_null_string
1432 .local string s, delim
1439 is(i, 1, 'split on null string and delim')
1444 is(i, 1, 'split on null delim')
1450 is(i, 1, 'split on null string')
1453 .sub split_on_empty_string
1456 is( $I1, "0", 'split on empty string' )
1460 is( $I0, "2", 'split on empty string' )
1463 is( $S0, "a", 'split on empty string' )
1466 is( $S0, "b", 'split on empty string' )
1469 .sub split_on_non_empty_string
1470 split $P0, "a", "afooabara"
1472 is( $I0, "5", 'split on non-empty string' )
1475 is( $S0, "", 'split on non-empty string' )
1477 is( $S0, "foo", 'split on non-empty string' )
1479 is( $S0, "b", 'split on non-empty string' )
1481 is( $S0, "r", 'split on non-empty string' )
1483 is( $S0, "", 'split on non-empty string' )
1487 new $P0, 'ResizablePMCArray'
1489 is( $S0, "", 'join' )
1493 is( $S0, "a", 'join' )
1495 new $P0, 'ResizablePMCArray'
1499 is( $S0, "a--b", 'join' )
1502 .sub 'test_join_many'
1503 $P1 = new ['ResizablePMCArray']
1506 unless $I0 < 20000 goto done
1507 $P2 = new ['Integer']
1514 ok("Join of many temporary strings doesn't crash")
1517 # join: get_string returns a null string --------
1519 .sub get_string :vtable :method
1526 .namespace [] # revert to root for next test
1527 .sub join_get_string_returns_a_null_string
1528 newclass $P0, "Foo5"
1529 new $P0, 'ResizablePMCArray'
1533 is( $S0, "", 'join: get_string returns a null string' )
1536 .sub eq_addr_or_ne_addr
1541 eq_addr $S1, $S0, OK1
1544 ok($I99, 'eq_addr/ne_addr')
1548 ne_addr $S1, $S0, BAD4
1551 ok($I99, 'eq_addr/ne_addr')
1554 .sub test_if_null_s_ic
1560 ok($I99, 'if_null s_ic' )
1567 ok($I99, 'if_null s_ic' )
1571 set $S0, "abCD012yz"
1573 is( $S1, "ABCD012YZ", 'upcase' )
1583 $S9 = $P9['message']
1586 is ($S9, "Can't upcase NULL string", 'upcase null')
1596 $S9 = $P9['message']
1599 is ($S9, "Can't upcase NULL string", 'upcase inplace null')
1603 set $S0, "ABcd012YZ"
1605 is( $S1, "abcd012yz", 'downcase' )
1615 $S9 = $P9['message']
1618 is ($S9, "Can't downcase NULL string", 'downcase null')
1628 $S9 = $P9['message']
1631 is ($S9, "Can't downcase NULL string", 'downcase inplace null')
1635 set $S0, "aBcd012YZ"
1637 is( $S1, "Abcd012yz", 'titlecase' )
1647 $S9 = $P9['message']
1650 is ($S9, "Can't titlecase NULL string", 'titlecase null')
1660 $S9 = $P9['message']
1663 is ($S9, "Can't titlecase NULL string", 'titlecase inplace null')
1666 .sub three_param_ord_one_character_string_register_i
1670 is( $I0, "97", '3-param ord, one-character string register, I' )
1673 .sub three_param_ord_multi_character_string_i
1676 is( $I0, "98", '3-param ord, multi-character string, I' )
1679 .sub three_param_ord_multi_character_string_register_i
1683 is( $I0, "98", '3-param ord, multi-character string register, I' )
1686 .sub exception_three_param_ord_multi_character_string_i
1690 ok( 0, 'no exception: 3-param ord, multi-character string, I' )
1692 .exception_is( 'Cannot get character past end of string' )
1695 .sub exception_three_param_ord_multi_character_string_i
1700 ok( 0, 'no exception: 3-param ord, multi-character string, I' )
1702 .exception_is( 'Cannot get character past end of string' )
1705 .sub three_param_ord_one_character_string_from_end_i
1708 is( $I0, "97", '3-param ord, one-character string, from end, I' )
1711 .sub three_param_ord_one_character_string_register_from_end_i
1715 is( $I0, "97", '3-param ord, one-character string register, from end, I' )
1718 .sub three_param_ord_multi_character_string_from_end_i
1721 is( $I0, "98", '3-param ord, multi-character string, from end, I' )
1724 .sub three_param_ord_multi_character_string_register_from_end_i
1728 is( $I0, "98", '3-param ord, multi-character string register, from end, I' )
1731 .sub exception_three_param_ord_multi_character_string_register_from_end_oob_i
1736 ok( 0, 'no exception: 3-param ord, multi-character string register, from end, OOB, I' )
1738 .exception_is( 'Cannot get character before beginning of string' )
1741 # Utility method for more_string_to_int
1742 .sub 'print_as_integer'
1744 .param string answer
1746 concat $S99, 'string to int: ', s
1747 is( $I0, answer, $S99 )
1750 .sub more_string_to_int
1751 print_as_integer('-4', "-4")
1752 print_as_integer('X-4',"0")
1753 print_as_integer('--4',"0")
1754 print_as_integer('+',"0")
1755 print_as_integer('++',"0")
1756 print_as_integer('+2',"2")
1757 print_as_integer(' +3',"3")
1758 print_as_integer('++4',"0")
1759 print_as_integer('+ 5',"0")
1760 print_as_integer('-',"0")
1761 print_as_integer('--56',"0")
1762 print_as_integer(' -+67',"0")
1763 print_as_integer('+-78',"0")
1764 print_as_integer(' -089xyz',"-89")
1765 print_as_integer('- 89',"0")
1768 # Utility sub for constant_string_and_modify_in_situ_op_rt_bug_60030
1769 .sub doit_sub_for_but_60030
1772 is( s, "Foo::Bar", 'bug 60030' )
1773 s = replace s, $I0, 2, "/"
1774 is( s, "Foo/Bar", 'bug 60030' )
1776 is( s, "Foo/Bar", 'bug 60030' )
1778 .sub constant_string_and_modify_in_situ_op_rt_bug_60030
1780 doit_sub_for_but_60030('Foo::Bar')
1781 # repeat to prove that the constant 'Foo4::Bar4' remains unchanged
1782 doit_sub_for_but_60030('Foo::Bar')
1785 .sub corner_cases_of_numification
1786 is( 2147483647.0, "2147483647", 'corner cases of numification' )
1787 is( -2147483648.0, "-2147483648", 'corner cases of numification' )
1790 .sub non_canonical_nan_and_inf
1792 is( $N0, "NaN", 'Non canonical nan and inf' )
1795 is( $N0, "Inf", 'Non canonical nan and inf' )
1798 is( $N0, "Inf", 'Non canonical nan and inf' )
1801 is( $N0, "-Inf", 'Non canonical nan and inf' )
1804 is( $N0, "-Inf", 'Non canonical nan and inf' )
1808 .sub split_hll_mapped
1809 .include 'test_more.pir'
1811 .local pmc RSA, fooRSA
1812 RSA = get_class ['ResizableStringArray']
1813 fooRSA = subclass ['ResizableStringArray'], 'fooRSA'
1817 interp.'hll_map'(RSA, fooRSA)
1820 split a, "a", "afooabara"
1824 is( t, 'fooRSA', 'split - hll mapped' )
1828 is( n, '5', 'split - hll mapped' )
1832 is( s, '', 'split - hll mapped' )
1834 is( s, 'foo', 'split - hll mapped' )
1836 is( s, 'b', 'split - hll mapped' )
1838 is( s, 'r', 'split - hll mapped' )
1840 is( s, '', 'split - hll mapped' )
1847 # vim: expandtab shiftwidth=4 ft=pir: