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