From: Hugo van der Sanden Date: Wed, 26 Jun 2002 17:43:07 +0000 (+0100) Subject: Re: Another Unicode s/// buglet? X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d6d0e86e2a8517b0818bacf1527a279e85266d73;p=p5sagit%2Fp5-mst-13.2.git Re: Another Unicode s/// buglet? Message-Id: <200206261643.g5QGh7519204@crypt.compulink.co.uk> (only the test cases) p4raw-id: //depot/perl@17364 --- diff --git a/t/op/subst.t b/t/op/subst.t index 026a940..f691aff 100755 --- a/t/op/subst.t +++ b/t/op/subst.t @@ -7,7 +7,7 @@ BEGIN { } require './test.pl'; -plan( tests => 108 ); +plan( tests => 122 ); $x = 'foo'; $_ = "x"; @@ -445,3 +445,45 @@ is($pv1, $pv2); like($a, qr/\x{100}/); is(length($a), 1); } + +{ + # subst with mixed utf8/non-utf8 type + my($ua, $ub, $uc, $ud) = ("\x{101}", "\x{102}", "\x{103}", "\x{104}"); + my($na, $nb) = ("\x{ff}", "\x{fe}"); + my $a = "$ua--$ub"; + my $b; + ($b = $a) =~ s/--/$na/; + is($b, "$ua$na$ub", "s///: replace non-utf8 into utf8"); + ($b = $a) =~ s/--/--$na--/; + is($b, "$ua--$na--$ub", "s///: replace long non-utf8 into utf8"); + ($b = $a) =~ s/--/$uc/; + is($b, "$ua$uc$ub", "s///: replace utf8 into utf8"); + ($b = $a) =~ s/--/--$uc--/; + is($b, "$ua--$uc--$ub", "s///: replace long utf8 into utf8"); + $a = "$na--$nb"; + ($b = $a) =~ s/--/$ua/; + is($b, "$na$ua$nb", "s///: replace utf8 into non-utf8"); + ($b = $a) =~ s/--/--$ua--/; + is($b, "$na--$ua--$nb", "s///: replace long utf8 into non-utf8"); + + # now with utf8 pattern + $a = "$ua--$ub"; + ($b = $a) =~ s/-($ud)?-/$na/; + is($b, "$ua$na$ub", "s///: replace non-utf8 into utf8 (utf8 pattern)"); + ($b = $a) =~ s/-($ud)?-/--$na--/; + is($b, "$ua--$na--$ub", "s///: replace long non-utf8 into utf8 (utf8 pattern)"); + ($b = $a) =~ s/-($ud)?-/$uc/; + is($b, "$ua$uc$ub", "s///: replace utf8 into utf8 (utf8 pattern)"); + ($b = $a) =~ s/-($ud)?-/--$uc--/; + is($b, "$ua--$uc--$ub", "s///: replace long utf8 into utf8 (utf8 pattern)"); + $a = "$na--$nb"; + ($b = $a) =~ s/-($ud)?-/$ua/; + is($b, "$na$ua$nb", "s///: replace utf8 into non-utf8 (utf8 pattern)"); + ($b = $a) =~ s/-($ud)?-/--$ua--/; + is($b, "$na--$ua--$nb", "s///: replace long utf8 into non-utf8 (utf8 pattern)"); + ($b = $a) =~ s/-($ud)?-/$na/; + is($b, "$na$na$nb", "s///: replace non-utf8 into non-utf8 (utf8 pattern)"); + ($b = $a) =~ s/-($ud)?-/--$na--/; + is($b, "$na--$na--$nb", "s///: replace long non-utf8 into non-utf8 (utf8 pattern)"); +} +