Small optimisations, by Brandon Black
[p5sagit/p5-mst-13.2.git] / t / op / append.t
CommitLineData
8d063cd8 1#!./perl
2
da450f52 3print "1..13\n";
8d063cd8 4
5$a = 'ab' . 'c'; # compile time
6$b = 'def';
7
8$c = $a . $b;
9print "#1\t:$c: eq :abcdef:\n";
10if ($c eq 'abcdef') {print "ok 1\n";} else {print "not ok 1\n";}
11
12$c .= 'xyz';
13print "#2\t:$c: eq :abcdefxyz:\n";
14if ($c eq 'abcdefxyz') {print "ok 2\n";} else {print "not ok 2\n";}
15
16$_ = $a;
17$_ .= $b;
18print "#3\t:$_: eq :abcdef:\n";
19if ($_ eq 'abcdef') {print "ok 3\n";} else {print "not ok 3\n";}
15bb2692 20
21# test that when right argument of concat is UTF8, and is the same
22# variable as the target, and the left argument is not UTF8, it no
23# longer frees the wrong string.
24{
25 sub r2 {
26 my $string = '';
27 $string .= pack("U0a*", 'mnopqrstuvwx');
28 $string = "abcdefghijkl$string";
29 }
30
31 r2() and print "ok $_\n" for qw/ 4 5 /;
32}
33
34# test that nul bytes get copied
35{
2d708654 36 my ($a, $ab) = ("a", "a\0b");
37 my ($ua, $uab) = map pack("U0a*", $_), $a, $ab;
1d996145 38
2d708654 39 my $ub = pack("U0a*", 'b');
1d996145 40
15bb2692 41 my $t1 = $a; $t1 .= $ab;
1d996145 42
2d708654 43 print $t1 =~ /b/ ? "ok 6\n" : "not ok 6\t# $t1\n";
1d996145 44
2d708654 45 my $t2 = $a; $t2 .= $uab;
1d996145 46
2d708654 47 print eval '$t2 =~ /$ub/' ? "ok 7\n" : "not ok 7\t# $t2\n";
1d996145 48
2d708654 49 my $t3 = $ua; $t3 .= $ab;
1d996145 50
2d708654 51 print $t3 =~ /$ub/ ? "ok 8\n" : "not ok 8\t# $t3\n";
1d996145 52
2d708654 53 my $t4 = $ua; $t4 .= $uab;
1d996145 54
2d708654 55 print eval '$t4 =~ /$ub/' ? "ok 9\n" : "not ok 9\t# $t4\n";
1d996145 56
15bb2692 57 my $t5 = $a; $t5 = $ab . $t5;
1d996145 58
2d708654 59 print $t5 =~ /$ub/ ? "ok 10\n" : "not ok 10\t# $t5\n";
1d996145 60
2d708654 61 my $t6 = $a; $t6 = $uab . $t6;
1d996145 62
2d708654 63 print eval '$t6 =~ /$ub/' ? "ok 11\n" : "not ok 11\t# $t6\n";
1d996145 64
2d708654 65 my $t7 = $ua; $t7 = $ab . $t7;
1d996145 66
2d708654 67 print $t7 =~ /$ub/ ? "ok 12\n" : "not ok 12\t# $t7\n";
1d996145 68
2d708654 69 my $t8 = $ua; $t8 = $uab . $t8;
1d996145 70
2d708654 71 print eval '$t8 =~ /$ub/' ? "ok 13\n" : "not ok 13\t# $t8\n";
15bb2692 72}