This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
tests are expected to fail if dirfd () does not exist
[perl5.git] / t / op / append.t
1 #!./perl
2
3 # $RCSfile: append.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:36 $
4
5 print "1..13\n";
6
7 $a = 'ab' . 'c';        # compile time
8 $b = 'def';
9
10 $c = $a . $b;
11 print "#1\t:$c: eq :abcdef:\n";
12 if ($c eq 'abcdef') {print "ok 1\n";} else {print "not ok 1\n";}
13
14 $c .= 'xyz';
15 print "#2\t:$c: eq :abcdefxyz:\n";
16 if ($c eq 'abcdefxyz') {print "ok 2\n";} else {print "not ok 2\n";}
17
18 $_ = $a;
19 $_ .= $b;
20 print "#3\t:$_: eq :abcdef:\n";
21 if ($_ eq 'abcdef') {print "ok 3\n";} else {print "not ok 3\n";}
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 {
38     my ($a, $ab)   = ("a", "a\0b");
39     my ($ua, $uab) = map pack("U0a*", $_), $a, $ab;
40
41     my $ub = pack("U0a*", 'b');
42
43     my $t1 = $a; $t1 .= $ab;
44
45     print $t1 =~ /b/ ? "ok 6\n" : "not ok 6\t# $t1\n";
46     
47     my $t2 = $a; $t2 .= $uab;
48     
49     print eval '$t2 =~ /$ub/' ? "ok 7\n" : "not ok 7\t# $t2\n";
50     
51     my $t3 = $ua; $t3 .= $ab;
52     
53     print $t3 =~ /$ub/ ? "ok 8\n" : "not ok 8\t# $t3\n";
54     
55     my $t4 = $ua; $t4 .= $uab;
56     
57     print eval '$t4 =~ /$ub/' ? "ok 9\n" : "not ok 9\t# $t4\n";
58     
59     my $t5 = $a; $t5 = $ab . $t5;
60     
61     print $t5 =~ /$ub/ ? "ok 10\n" : "not ok 10\t# $t5\n";
62     
63     my $t6 = $a; $t6 = $uab . $t6;
64     
65     print eval '$t6 =~ /$ub/' ? "ok 11\n" : "not ok 11\t# $t6\n";
66     
67     my $t7 = $ua; $t7 = $ab . $t7;
68     
69     print $t7 =~ /$ub/ ? "ok 12\n" : "not ok 12\t# $t7\n";
70     
71     my $t8 = $ua; $t8 = $uab . $t8;
72     
73     print eval '$t8 =~ /$ub/' ? "ok 13\n" : "not ok 13\t# $t8\n";
74 }