-
Notifications
You must be signed in to change notification settings - Fork 138
/
string.t
1874 lines (1599 loc) · 42.2 KB
/
string.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!./parrot
# Copyright (C) 2001-2010, Parrot Foundation.
=head1 NAME
t/op/string.t - Parrot Strings
=head1 SYNOPSIS
% prove t/op/string.t
=head1 DESCRIPTION
Tests Parrot string registers and operations.
=cut
.include 'except_types.pasm'
.sub main :main
.include 'test_more.pir'
set_s_s_sc()
test_clone()
clone_null()
test_length_i_s()
zero_length_substr()
chopn_with_clone()
chopn_oob_values()
three_argument_chopn()
three_argument_chopn__oob_values()
substr_tests()
neg_substr_offset()
exception_substr_null_string()
exception_substr_oob()
exception_substr_oob_neg()
len_greater_than_strlen()
len_greater_than_strlen_neg_offset()
replace_w_rep_eq_length()
replace_w_replacement_gt_length()
replace_w_replacement_lt_length()
replace_vs_hash()
replace__offset_at_end_of_string()
exception_replace__offset_past_end_of_string()
replace_neg_offset_repl_eq_length()
replace_neg_offset_repl_gt_length()
replace_neg_offset_repl_lt_length()
exception_replace_neg_offset_out_of_string()
replace_length_gt_strlen()
replace_length_gt_strlen_neg_offset()
replace_only_substr()
three_arg_substr()
exception_substr__pos_offset_zero_length_string()
substr_offset_zero_zero_length_string()
exception_substr_offset_one_zero_length_string()
exception_substr_neg_offset_zero_length_string()
exception_substr_oob_utf8()
zero_length_substr_zero_length_string()
zero_length_substr_zero_length_string()
three_arg_substr_zero_length_string()
replace_zero_length_string()
four_arg_substr_replace_zero_length_string()
concat_s_s_sc_null_onto_null()
concat_s_sc_repeated_two_arg_concats()
concat_s_s_sc_foo_one_onto_null()
test_concat_s_s_sc()
concat_s_s_sc_s_sc()
concat_ensure_copy_is_made()
same_constant_twice_bug()
exception_two_param_ord_empty_string()
exception_two_param_ord_empty_string_register()
exception_three_param_ord_empty_string()
exception_three_param_ord_empty_string_register()
two_param_ord_one_character_string()
two_param_ord_multi_character_string()
two_param_ord_one_character_string_register()
three_param_ord_one_character_string()
three_param_ord_one_character_string_register()
three_param_ord_multi_character_string()
three_param_ord_multi_character_string_register()
exception_three_param_ord_multi_character_string()
exception_three_param_ord_multi_character_string()
three_param_ord_one_character_string_from_end()
three_param_ord_one_character_string_register_from_end()
three_param_ord_multi_character_string_from_end()
three_param_ord_multi_character_string_register_from_end()
exception_three_param_ord_multi_character_string_register_from_end_oob()
chr_of_thirty_two_is_space_in_ascii()
chr_of_sixty_five_is_a_in_ascii()
chr_of_one_hundred_and_twenty_two_is_z_in_ascii()
test_if_s_ic()
repeat_s_s_sc_i_ic()
exception_repeat_oob()
exception_repeat_oob_repeat_p_p_p()
exception_repeat_oob_repeate_p_p_i()
encodingname_oob()
index_three_arg_form()
index_four_arg_form()
index_four_arg_form_bug_twenty_two_thousand_seven_hundred_and_eighteen()
index_trac_1482()
index_null_strings()
index_embedded_nulls()
index_big_strings()
index_big_hard_to_match_strings()
index_with_different_charsets()
negative_index_bug_35959()
index_multibyte_matching()
index_multibyte_matching_two()
num_to_string()
string_to_int()
string_to_num()
concat_or_substr_cow()
constant_to_cstring()
cow_with_chopn_leaving_original_untouched()
check_that_bug_bug_16874_was_fixed()
stress_concat()
ord_and_substring_see_bug_17035()
test_sprintf()
other_form_of_sprintf_op()
sprintf_left_justify()
correct_precision_for_sprintf_x()
test_find_encoding()
test_assign()
assign_and_globber()
split_on_null_string()
split_on_empty_string()
split_on_non_empty_string()
test_join()
test_join_many()
eq_addr_or_ne_addr()
test_if_null_s_ic()
test_upcase()
test_downcase()
test_titlecase()
three_param_ord_one_character_string_register_i()
three_param_ord_multi_character_string_i()
three_param_ord_multi_character_string_register_i()
exception_three_param_ord_multi_character_string_i()
exception_three_param_ord_multi_character_string_i()
three_param_ord_one_character_string_from_end_i()
three_param_ord_one_character_string_register_from_end_i()
three_param_ord_multi_character_string_from_end_i()
three_param_ord_multi_character_string_register_from_end_i()
exception_three_param_ord_multi_character_string_register_from_end_oob_i()
more_string_to_int()
constant_string_and_modify_in_situ_op_rt_bug_60030()
corner_cases_of_numification()
non_canonical_nan_and_inf()
split_hll_mapped()
# END_OF_TESTS
join_get_string_returns_a_null_string()
done_testing()
.end
.macro exception_is ( M )
.local pmc exception
.local string message
.get_results (exception)
message = exception['message']
is( message, .M, .M )
.endm
.sub set_s_s_sc
set $S4, "JAPH"
set $S5, $S4
is( $S4, "JAPH", '' )
is( $S5, "JAPH", '' )
.end
.sub test_clone
set $S0, "Foo1"
clone $S1, $S0
is( $S0, "Foo1", '' )
is( $S1, "Foo1", '' )
clone $S1, "Bar1"
is( $S1, "Bar1", '' )
.end
.sub clone_null
null $S0
clone $S1, $S0
is( $S1, $S0, '' )
.end
.sub test_length_i_s
set $I4, 0
set $S4, "JAPH"
length $I4, $S4
is( $I4, "4", '' )
.end
.sub zero_length_substr
set $I4, 0
set $S4, "JAPH"
substr $S3, $S4, 1, 0
length $I4, $S3
is( $I4, "0", '' )
.end
.sub chopn_with_clone
set $S4, "JAPHxyzw"
set $S5, "japhXYZW"
clone $S3, $S4
set $I1, 4
$S4 = chopn $S4, 3
$S4 = chopn $S4, 1
$S5 = chopn $S5, $I1
is( $S4, "JAPH", '' )
is( $S5, "japh", '' )
is( $S3, "JAPHxyzw", '' )
.end
.sub chopn_oob_values
set $S1, "A string of length 21"
$S1 = chopn $S1, 0
is( $S1, "A string of length 21", '' )
$S1 = chopn $S1, 4
is( $S1, "A string of lengt", '' )
# -length cuts now
$S1 = chopn $S1, -4
is( $S1, "A st", '' )
$S1 = chopn $S1, 1000
is( $S1, "", '' )
.end
.sub three_argument_chopn
set $S1, "Parrot"
chopn $S2, $S1, 0
is( $S1, "Parrot", '' )
is( $S2, "Parrot", '' )
chopn $S2, $S1, 1
is( $S1, "Parrot", '' )
is( $S2, "Parro", '' )
set $I0, 2
chopn $S2, $S1, $I0
is( $S1, "Parrot", '' )
is( $S2, "Parr", '' )
chopn $S2, "Parrot", 3
is( $S2, "Par", '' )
chopn $S1, $S1, 5
is( $S1, "P", '' )
set $S1, "Parrot"
set $S3, $S1
chopn $S2, $S1, 3
is( $S3, "Parrot", '' )
.end
#
.sub three_argument_chopn__oob_values
set $S1, "Parrot"
chopn $S2, $S1, 7
is( $S1, "Parrot", '' )
is( $S2, "", '' )
chopn $S2, $S1, -1
is( $S1, "Parrot", '' )
is( $S2, "P", '' )
.end
.sub substr_tests
set $S4, "12345JAPH01"
set $I4, 5
set $I5, 4
substr $S5, $S4, $I4, $I5
is( $S5, "JAPH", '' )
substr $S5, $S4, $I4, 4
is( $S5, "JAPH", '' )
substr $S5, $S4, 5, $I5
is( $S5, "JAPH", '' )
substr $S5, $S4, 5, 4
is( $S5, "JAPH", '' )
substr $S5, "12345JAPH01", $I4, $I5
is( $S5, "JAPH", '' )
substr $S5, "12345JAPH01", $I4, 4
is( $S5, "JAPH", '' )
substr $S5, "12345JAPH01", 5, $I5
is( $S5, "JAPH", '' )
substr $S5, "12345JAPH01", 5, 4
is( $S5, "JAPH", '' )
.end
# negative offsets
.sub neg_substr_offset
set $S0, "A string of length 21"
set $I0, -9
set $I1, 6
substr $S1, $S0, $I0, $I1
is( $S0, "A string of length 21", '' )
is( $S1, "length", '' )
.end
.sub exception_substr_null_string
.local string s
.local pmc eh
.local int r
null s
eh = new ['ExceptionHandler']
eh.'handle_types'(.EXCEPTION_UNEXPECTED_NULL)
set_label eh, handler
push_eh eh
r = 1
substr s, s, 0, 0
r = 0
handler:
pop_eh
is(r, 1, "substr with null string throws" )
.end
# This asks for substring that shouldn't be allowed...
.sub exception_substr_oob
.local pmc eh
.local int r
set $S0, "A string of length 21"
set $I0, 99
set $I1, 6
eh = new ['ExceptionHandler']
eh.'handle_types'(.EXCEPTION_SUBSTR_OUT_OF_STRING)
set_label eh, handler
push_eh eh
r = 1
substr $S1, $S0, $I0, $I1
r = 0
handler:
pop_eh
is(r, 1, "substr outside string throws" )
.end
# This asks for substring that shouldn't be allowed...
.sub exception_substr_oob_neg
.local pmc eh
.local int r
set $S0, "A string of length 21"
set $I0, -99
set $I1, 6
eh = new ['ExceptionHandler']
eh.'handle_types'(.EXCEPTION_SUBSTR_OUT_OF_STRING)
set_label eh, handler
push_eh eh
r = 1
substr $S1, $S0, $I0, $I1
r = 0
handler:
pop_eh
is(r, 1, "substr outside string throws - negative" )
.end
# This asks for substring much greater than length of original string
.sub len_greater_than_strlen
set $S0, "A string of length 21"
set $I0, 12
set $I1, 1000
substr $S1, $S0, $I0, $I1
is( $S0, "A string of length 21", '' )
is( $S1, "length 21", '' )
.end
# The same, with a negative offset
.sub len_greater_than_strlen_neg_offset
set $S0, "A string of length 21"
set $I0, -9
set $I1, 1000
substr $S1, $S0, $I0, $I1
is( $S0, "A string of length 21", '' )
is( $S1, "length 21", '' )
.end
.sub replace_w_rep_eq_length
set $S0, "abcdefghijk"
set $S1, "xyz"
replace $S2, $S0, 4, 3, $S1
is( $S2, "abcdxyzhijk", '' )
.end
.sub replace_w_replacement_gt_length
set $S0, "abcdefghijk"
set $S1, "xyz0123"
$S2 = replace $S0, 4, 3, $S1
is( $S2, "abcdxyz0123hijk", '' )
.end
.sub replace_w_replacement_lt_length
set $S0, "abcdefghijk"
set $S1, "x"
$S2 = replace $S0, 4, 3, $S1
is( $S2, "abcdxhijk", '' )
.end
.sub replace__offset_at_end_of_string
set $S0, "abcdefghijk"
set $S1, "xyz"
$S2 = replace $S0, 11, 3, $S1
is( $S2, "abcdefghijkxyz", '' )
.end
.sub replace_vs_hash
# Check that string hashval properly updated.
.local pmc hash
hash = new ['Hash']
$S0 = "fooo"
hash[$S0] = 1
hash["foo"] = 42
$S0 = replace $S0, 1, 1, ''
$S1 = hash[$S0]
is( $S1, '42', 'replace behave it self')
.end
.sub exception_replace__offset_past_end_of_string
set $S0, "abcdefghijk"
set $S1, "xyz"
push_eh handler
$S2 = replace $S0, 12, 3, $S1
ok(0,"no exception")
handler:
.exception_is( "Can only replace inside string or index after end of string" )
.end
.sub replace_neg_offset_repl_eq_length
set $S0, "abcdefghijk"
set $S1, "xyz"
$S2 = replace $S0, -3, 3, $S1
is( $S2, "abcdefghxyz", '' )
.end
.sub replace_neg_offset_repl_gt_length
set $S0, "abcdefghijk"
set $S1, "xyz"
$S2 = replace $S0, -6, 2, $S1
is( $S2, "abcdexyzhijk", '' )
.end
.sub replace_neg_offset_repl_lt_length
set $S0, "abcdefghijk"
set $S1, "xyz"
$S2 = replace $S0, -6, 4, $S1
is( $S2, "abcdexyzjk", '' )
.end
.sub exception_replace_neg_offset_out_of_string
set $S0, "abcdefghijk"
set $S1, "xyz"
push_eh handler
$S2 = replace $S0, -12, 4, $S1
ok(0,"no exception")
handler:
.exception_is( "Can only replace inside string or index after end of string" )
.end
.sub replace_length_gt_strlen
set $S0, "abcdefghijk"
set $S1, "xyz"
$S2 = replace $S0, 3, 11, $S1
is( $S2, "abcxyz", '' )
.end
.sub replace_length_gt_strlen_neg_offset
set $S0, "abcdefghijk"
set $S1, "xyz"
$S2 = replace $S0, -3, 11, $S1
is( $S2, "abcdefghxyz", '' )
.end
.sub replace_only_substr
set $S0, "abcdefghijk"
set $S1, "xyz"
$S2 = replace $S0, 3, 3, $S1
is( $S2, "abcxyzghijk", '' )
.end
.sub three_arg_substr
set $S0, "JAPH"
substr $S1, $S0, 2
is( $S1, "PH", '' )
.end
.sub exception_substr__pos_offset_zero_length_string
set $S0, ""
push_eh handler
substr $S1, $S0, 10, 3
ok(0,"no exception")
handler:
.exception_is( "Cannot take substr outside string" )
.end
.sub substr_offset_zero_zero_length_string
set $S0, ""
substr $S1, $S0, 0, 1
is( $S1, "", '' )
.end
.sub exception_substr_offset_one_zero_length_string
set $S0, ""
push_eh handler
substr $S1, $S0, -1, 1
ok(0,"no exception")
handler:
.exception_is( "Cannot take substr outside string" )
.end
.sub exception_substr_neg_offset_zero_length_string
set $S0, ""
push_eh handler
substr $S1, $S0, -10, 5
handler:
.exception_is( "Cannot take substr outside string" )
.end
.sub exception_substr_oob_utf8
set $S0, utf8:"abc\uBEEFdef"
push_eh handler
substr $S1, $S0, 8, 5
handler:
.exception_is( "Cannot take substr outside string" )
.end
.sub zero_length_substr_zero_length_string
set $S0, ""
substr $S1, $S0, 10, 0
is( $S1, "", '' )
.end
.sub zero_length_substr_zero_length_string
set $S0, ""
substr $S1, $S0, -10, 0
is( $S1, "", '' )
.end
.sub three_arg_substr_zero_length_string
set $S0, ""
substr $S1, $S0, 2
is( $S1, "", '' )
.end
.sub replace_zero_length_string
set $S0, ""
set $S1, "xyz"
$S2 = replace $S0, 0, 3, $S1
is( $S2, "xyz", '' )
set $S3, ""
set $S4, "abcde"
$S5 = replace $S3, 0, 0, $S4
is( $S5, "abcde", '' )
.end
.sub four_arg_substr_replace_zero_length_string
set $S0, ""
set $S1, "xyz"
$S0 = replace $S0, 0, 3, $S1
is( $S0, "xyz", '' )
set $S2, ""
set $S3, "abcde"
$S2 = replace $S2, 0, 0, $S3
is( $S2, "abcde", '' )
.end
.sub concat_s_s_sc_null_onto_null
$S0 = concat $S0, $S0
is( $S0, "", '' )
$S1 = concat $S1, ""
is( $S1, "", '' )
.end
.sub concat_s_sc_repeated_two_arg_concats
set $S12, ""
set $I0, 0
WHILE:
$S12 = concat $S12, "hi"
add $I0, 1
lt $I0, 10, WHILE
is( $S12, "hihihihihihihihihihi", '' )
.end
.sub concat_s_s_sc_foo_one_onto_null
$S0 = concat $S0, "foo1"
set $S1, "foo2"
$S2 = concat $S2, $S1
is( $S0, "foo1", '' )
is( $S2, "foo2", '' )
.end
.sub test_concat_s_s_sc
set $S1, "fish"
set $S2, "bone"
$S1 = concat $S1, $S2
is( $S1, "fishbone", '' )
.end
.sub concat_s_s_sc_s_sc
set $S1, "japh"
set $S2, "JAPH"
concat $S0, "japh", "JAPH"
is( $S0, "japhJAPH", '' )
concat $S0, $S1, "JAPH"
is( $S0, "japhJAPH", '' )
concat $S0, "japh", $S2
is( $S0, "japhJAPH", '' )
concat $S0, $S1, $S2
is( $S0, "japhJAPH", '' )
.end
.sub concat_ensure_copy_is_made
set $S2, "JAPH"
concat $S0, $S2, ""
concat $S1, "", $S2
$S0 = chopn $S0, 1
$S1 = chopn $S1, 1
is( $S2, "JAPH", '' )
.end
.sub same_constant_twice_bug
set $S0, ""
set $S1, ""
set $S2, "foo"
concat $S1, $S1, $S2
is( $S1, "foo", 'same constant twice bug' )
is( $S0, "", 'same constant twice bug' )
.end
.sub exception_two_param_ord_empty_string
push_eh handler
ord $I0,""
ok(0, 'no exception: 2-param ord, empty string' )
handler:
.exception_is( 'Cannot get character of empty string' )
.end
.sub exception_two_param_ord_empty_string_register
push_eh handler
ord $I0,$S0
ok( 0, 'no exception: 2-param ord, empty string register' )
handler:
.exception_is( 'Invalid operation on null string' )
.end
.sub exception_three_param_ord_empty_string
push_eh handler
ord $I0,"",0
ok(0, 'no exception: 3-param ord, empty string' )
handler:
.exception_is( 'Cannot get character of empty string' )
.end
.sub exception_three_param_ord_empty_string_register
push_eh handler
ord $I0,$S0,0
ok( 0, 'no exception: 3-param ord, empty string register' )
handler:
.exception_is( 'Invalid operation on null string' )
.end
.sub two_param_ord_one_character_string
ord $I0,"a"
is( $I0, "97", '2-param ord, one-character string' )
.end
.sub two_param_ord_multi_character_string
ord $I0,"abc"
is( $I0, "97", '2-param ord, multi-character string' )
.end
.sub two_param_ord_one_character_string_register
set $S0,"a"
ord $I0,$S0
is( $I0, "97", '2-param ord, one-character string register' )
.end
.sub three_param_ord_one_character_string
ord $I0,"a",0
is( $I0, "97", '3-param ord, one-character string' )
.end
.sub three_param_ord_one_character_string_register
set $S0,"a"
ord $I0,$S0,0
is( $I0, "97", '3-param ord, one-character string register' )
.end
.sub three_param_ord_multi_character_string
ord $I0,"ab",1
is( $I0, "98", '3-param ord, multi-character string' )
.end
.sub three_param_ord_multi_character_string_register
set $S0,"ab"
ord $I0,$S0,1
is( $I0, "98", '3-param ord, multi-character string register' )
.end
.sub exception_three_param_ord_multi_character_string
push_eh handler
ord $I0,"ab",2
ok( 0, 'no exception: 3-param ord, multi-character string' )
handler:
.exception_is( 'Cannot get character past end of string' )
.end
.sub exception_three_param_ord_multi_character_string
push_eh handler
set $S0,"ab"
ord $I0,$S0,2
ok( 0, 'no exception: 3-param ord, multi-character string' )
handler:
.exception_is( 'Cannot get character past end of string' )
.end
.sub three_param_ord_one_character_string_from_end
ord $I0,"a",-1
is( $I0, "97", '3-param ord, one-character string, from end' )
.end
.sub three_param_ord_one_character_string_register_from_end
set $S0,"a"
ord $I0,$S0,-1
is( $I0, "97", '3-param ord, one-character string register, from end' )
.end
.sub three_param_ord_multi_character_string_from_end
ord $I0,"ab",-1
is( $I0, "98", '3-param ord, multi-character string, from end' )
.end
.sub three_param_ord_multi_character_string_register_from_end
set $S0,"ab"
ord $I0,$S0,-1
is( $I0, "98", '3-param ord, multi-character string register, from end' )
.end
.sub exception_three_param_ord_multi_character_string_register_from_end_oob
push_eh handler
set $S0,"ab"
ord $I0,$S0,-3
ok( 0, 'no exception: 3-param ord, multi-character string register, from end, OOB' )
handler:
.exception_is( 'Cannot get character before beginning of string' )
.end
.sub chr_of_thirty_two_is_space_in_ascii
chr $S0, 32
is( $S0, " ", 'chr of 32 is space in ASCII' )
.end
.sub chr_of_sixty_five_is_a_in_ascii
chr $S0, 65
is( $S0, "A", 'chr of 65 is A in ASCII' )
.end
.sub chr_of_one_hundred_and_twenty_two_is_z_in_ascii
chr $S0, 122
is( $S0, "z", 'chr of 122 is z in ASCII' )
.end
.sub test_if_s_ic
set $S0, "I've told you once, I've told you twice..."
ok( $S0, 'normal strings are true' )
set $S0, "0.0"
ok( $S0, '0.0 is true' )
set $S0, ""
nok( $S0, 'empty string is false' )
set $S0, "0"
nok( $S0, '"0" string is false' )
set $S0, "0e0"
ok( $S0, 'string "0e0" is true' )
set $S0, "x"
ok( $S0, 'string "x" is true' )
set $S0, "\\x0"
ok( $S0, 'string "\\x0" is true' )
set $S0, "\n"
ok( $S0, 'string "\n" is true' )
set $S0, " "
ok( $S0, 'string " " is true' )
# An empty register should be false...
nok( $S1, 'empty register is false' )
.end
.sub repeat_s_s_sc_i_ic
set $S0, "x"
repeat $S1, $S0, 12
is( $S0, "x", 'repeat_s_s|sc_i|ic' )
is( $S1, "xxxxxxxxxxxx", 'repeat_s_s|sc_i|ic' )
set $I0, 12
set $S2, "X"
repeat $S3, $S2, $I0
is( $S2, "X", 'repeat_s_s|sc_i|ic' )
is( $S3, "XXXXXXXXXXXX", 'repeat_s_s|sc_i|ic' )
repeat $S4, "~", 12
is( $S4, "~~~~~~~~~~~~", 'repeat_s_s|sc_i|ic' )
repeat $S5, "~", $I0
is( $S5, "~~~~~~~~~~~~", 'repeat_s_s|sc_i|ic' )
repeat $S6, "***", 0
is( $S6, "", 'repeat_s_s|sc_i|ic' )
.end
.sub exception_repeat_oob
push_eh handler
repeat $S0, "japh", -1
handler:
.exception_is( 'Cannot repeat with negative arg' )
.end
.sub exception_repeat_oob_repeat_p_p_p
push_eh handler
$P0 = new ['String']
$P1 = new ['String']
$P2 = new ['Integer']
$P2 = -1
repeat $P1, $P0, $P2
handler:
.exception_is( 'Cannot repeat with negative arg' )
.end
.sub exception_repeat_oob_repeate_p_p_i
push_eh handler
$P0 = new ['String']
$P1 = new ['String']
repeat $P1, $P0, -1
handler:
.exception_is( 'Cannot repeat with negative arg' )
.end
.sub encodingname_oob
$I0 = -1
$S0 = encodingname -1
$S0 = encodingname $I0
ok( 1, "no exceptions in encodingname_oob" )
.end
.sub index_three_arg_form
set $S0, "Parrot"
set $S1, "Par"
index $I1, $S0, $S1
is( $I1, "0", 'index, 3-arg form' )
set $S1, "rot"
index $I1, $S0, $S1
is( $I1, "3", 'index, 3-arg form' )
set $S1, "bar"
index $I1, $S0, $S1
is( $I1, "-1", 'index, 3-arg form' )
# Ascii - Non-ascii, same content
set $S0, "hello"
set $S1, utf8:"hello"
index $I1, $S0, $S1
is( $I1, "0", 'index, 3-arg form' )
index $I1, $S1, $S0
is( $I1, "0", 'index, 3-arg form' )
# Non-ascii, source shorter than searched
set $S0, utf8:"-o"
set $S1, utf8:"@INC"
index $I1, $S0, $S1
is( $I1, "-1", 'index, 3-arg form' )
.end
.sub index_four_arg_form
set $S0, "Barbarian"
set $S1, "ar"
index $I1, $S0, $S1, 0
is( $I1, "1", 'index, 4-arg form' )
index $I1, $S0, $S1, 2
is( $I1, "4", 'index, 4-arg form' )
set $S1, "qwx"
index $I1, $S0, $S1, 0
is( $I1, "-1", 'index, 4-arg form' )
# Ascii - Non-ascii, same content
set $S0, "hello"
set $S1, utf8:"hello"
index $I1, $S0, $S1, 0
is( $I1, "0", 'index, 4-arg form' )
index $I1, $S1, $S0, 0
is( $I1, "0", 'index, 4-arg form' )
.end
.sub index_four_arg_form_bug_twenty_two_thousand_seven_hundred_and_eighteen
set $S1, "This is not quite right"
set $S0, " is "
index $I0, $S1, $S0, 0
is( $I0, "4", 'index, 4-arg form, bug 22718' )
set $S0, "is"
index $I0, $S1, $S0, 0
is( $I0, "2", 'index, 4-arg form, bug 22718' )
.end
.sub index_trac_1482
$S0 = utf8:"bubuc"
$S1 = utf8:"buc"
$I0 = index $S0, $S1, 0
is ($I0, 2, 'index, 4-arg, partial-match causes failure: TT #1482')
.end
.sub index_null_strings
set $S0, "Parrot"
set $S1, ""
index $I1, $S0, $S1
is( $I1, "-1", 'index, null strings' )
index $I1, $S0, $S1, 0
is( $I1, "-1", 'index, null strings' )
index $I1, $S0, $S1, 5
is( $I1, "-1", 'index, null strings' )
index $I1, $S0, $S1, 6
is( $I1, "-1", 'index, null strings' )
set $S0, ""
set $S1, "a"
index $I1, $S0, $S1
is( $I1, "-1", 'index, null strings' )
index $I1, $S0, $S1, 0
is( $I1, "-1", 'index, null strings' )
set $S0, "Parrot"
null $S1
index $I1, $S0, $S1
is( $I1, "-1", 'index, null strings' )
.local pmc eh
eh = new ['ExceptionHandler']
eh.'handle_types'(.EXCEPTION_UNEXPECTED_NULL)
set_label eh, handler
push_eh eh
$I1 = 1
null $S0
null $S1
index $I0, $S0, $S1
$I1 = 0
handler:
pop_eh
is( $I1, "1", "index with null string throws" )
.end
.sub index_embedded_nulls
set $S0, "Par\0\0rot"
set $S1, "\0"
index $I1, $S0, $S1
is( $I1, "3", 'index, embedded nulls' )
index $I1, $S0, $S1, 4
is( $I1, "4", 'index, embedded nulls' )
.end
.sub index_big_strings
set $S0, "a"
repeat $S0, $S0, 10000
set $S1, "a"
repeat $S1, $S1, 500
index $I1, $S0, $S1
is( $I1, "0", 'index, big strings' )