diff options
author | Nicholas Clark <nick@ccl4.org> | 2006-04-30 11:14:04 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2006-04-30 11:14:04 +0000 |
commit | 73ee8be2712c500c98e5976864ba96726bf311e2 (patch) | |
tree | 69af13d297713caa615426fcc1c9262ed09a8540 /t | |
parent | d34786ba12ee5b96d9e34dd6fcdda158d7d2597b (diff) | |
download | perl-73ee8be2712c500c98e5976864ba96726bf311e2.tar.gz |
index and rindex couldn't correctly handle surprises from UTF-8
overloading.
p4raw-id: //depot/perl@28022
Diffstat (limited to 't')
-rw-r--r-- | t/lib/warnings/9uninit | 4 | ||||
-rw-r--r-- | t/uni/overload.t | 32 |
2 files changed, 33 insertions, 3 deletions
diff --git a/t/lib/warnings/9uninit b/t/lib/warnings/9uninit index 575161d2a1..fadcd1bd2a 100644 --- a/t/lib/warnings/9uninit +++ b/t/lib/warnings/9uninit @@ -873,11 +873,11 @@ Use of uninitialized value $m2 in index at - line 14. Use of uninitialized value $g1 in index at - line 15. Use of uninitialized value $m1 in index at - line 15. Use of uninitialized value $m2 in index at - line 15. -Use of uninitialized value $m2 in rindex at - line 16. Use of uninitialized value $m1 in rindex at - line 16. +Use of uninitialized value $m2 in rindex at - line 16. Use of uninitialized value $g1 in rindex at - line 17. -Use of uninitialized value $m2 in rindex at - line 17. Use of uninitialized value $m1 in rindex at - line 17. +Use of uninitialized value $m2 in rindex at - line 17. ######## use warnings 'uninitialized'; my ($m1, $v); diff --git a/t/uni/overload.t b/t/uni/overload.t index 5812425ca5..ef61667448 100644 --- a/t/uni/overload.t +++ b/t/uni/overload.t @@ -7,7 +7,7 @@ BEGIN { } } -use Test::More tests => 116; +use Test::More tests => 190; package UTF8Toggle; use strict; @@ -212,6 +212,36 @@ foreach my $operator ('print', 'syswrite', 'syswrite len', 'syswrite off', } } +my $little = "\243\243"; +my $big = " \243 $little ! $little ! $little \243 "; +my $right = rindex $big, $little; +my $right1 = rindex $big, $little, 11; +my $left = index $big, $little; +my $left1 = index $big, $little, 4; + +cmp_ok ($right, ">", $right1, "Sanity check our rindex tests"); +cmp_ok ($left, "<", $left1, "Sanity check our index tests"); + +foreach my $b ($big, UTF8Toggle->new($big)) { + foreach my $l ($little, UTF8Toggle->new($little), + UTF8Toggle->new($little, 1)) { + is (rindex ($b, $l), $right, "rindex"); + is (rindex ($b, $l), $right, "rindex"); + is (rindex ($b, $l), $right, "rindex"); + + is (rindex ($b, $l, 11), $right1, "rindex 11"); + is (rindex ($b, $l, 11), $right1, "rindex 11"); + is (rindex ($b, $l, 11), $right1, "rindex 11"); + + is (index ($b, $l), $left, "index"); + is (index ($b, $l), $left, "index"); + is (index ($b, $l), $left, "index"); + + is (index ($b, $l, 4), $left1, "index 4"); + is (index ($b, $l, 4), $left1, "index 4"); + is (index ($b, $l, 4), $left1, "index 4"); + } +} END { 1 while -f $tmpfile and unlink $tmpfile || die "unlink '$tmpfile': $!"; |