xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/t/op/append.t (revision 0:68f95e015346)
1*0Sstevel@tonic-gate#!./perl
2*0Sstevel@tonic-gate
3*0Sstevel@tonic-gate# $RCSfile: append.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:36 $
4*0Sstevel@tonic-gate
5*0Sstevel@tonic-gateprint "1..13\n";
6*0Sstevel@tonic-gate
7*0Sstevel@tonic-gate$a = 'ab' . 'c';	# compile time
8*0Sstevel@tonic-gate$b = 'def';
9*0Sstevel@tonic-gate
10*0Sstevel@tonic-gate$c = $a . $b;
11*0Sstevel@tonic-gateprint "#1\t:$c: eq :abcdef:\n";
12*0Sstevel@tonic-gateif ($c eq 'abcdef') {print "ok 1\n";} else {print "not ok 1\n";}
13*0Sstevel@tonic-gate
14*0Sstevel@tonic-gate$c .= 'xyz';
15*0Sstevel@tonic-gateprint "#2\t:$c: eq :abcdefxyz:\n";
16*0Sstevel@tonic-gateif ($c eq 'abcdefxyz') {print "ok 2\n";} else {print "not ok 2\n";}
17*0Sstevel@tonic-gate
18*0Sstevel@tonic-gate$_ = $a;
19*0Sstevel@tonic-gate$_ .= $b;
20*0Sstevel@tonic-gateprint "#3\t:$_: eq :abcdef:\n";
21*0Sstevel@tonic-gateif ($_ eq 'abcdef') {print "ok 3\n";} else {print "not ok 3\n";}
22*0Sstevel@tonic-gate
23*0Sstevel@tonic-gate# test that when right argument of concat is UTF8, and is the same
24*0Sstevel@tonic-gate# variable as the target, and the left argument is not UTF8, it no
25*0Sstevel@tonic-gate# longer frees the wrong string.
26*0Sstevel@tonic-gate{
27*0Sstevel@tonic-gate    sub r2 {
28*0Sstevel@tonic-gate	my $string = '';
29*0Sstevel@tonic-gate	$string .= pack("U0a*", 'mnopqrstuvwx');
30*0Sstevel@tonic-gate	$string = "abcdefghijkl$string";
31*0Sstevel@tonic-gate    }
32*0Sstevel@tonic-gate
33*0Sstevel@tonic-gate    r2() and print "ok $_\n" for qw/ 4 5 /;
34*0Sstevel@tonic-gate}
35*0Sstevel@tonic-gate
36*0Sstevel@tonic-gate# test that nul bytes get copied
37*0Sstevel@tonic-gate{
38*0Sstevel@tonic-gate    my ($a, $ab)   = ("a", "a\0b");
39*0Sstevel@tonic-gate    my ($ua, $uab) = map pack("U0a*", $_), $a, $ab;
40*0Sstevel@tonic-gate
41*0Sstevel@tonic-gate    my $ub = pack("U0a*", 'b');
42*0Sstevel@tonic-gate
43*0Sstevel@tonic-gate    my $t1 = $a; $t1 .= $ab;
44*0Sstevel@tonic-gate
45*0Sstevel@tonic-gate    print $t1 =~ /b/ ? "ok 6\n" : "not ok 6\t# $t1\n";
46*0Sstevel@tonic-gate
47*0Sstevel@tonic-gate    my $t2 = $a; $t2 .= $uab;
48*0Sstevel@tonic-gate
49*0Sstevel@tonic-gate    print eval '$t2 =~ /$ub/' ? "ok 7\n" : "not ok 7\t# $t2\n";
50*0Sstevel@tonic-gate
51*0Sstevel@tonic-gate    my $t3 = $ua; $t3 .= $ab;
52*0Sstevel@tonic-gate
53*0Sstevel@tonic-gate    print $t3 =~ /$ub/ ? "ok 8\n" : "not ok 8\t# $t3\n";
54*0Sstevel@tonic-gate
55*0Sstevel@tonic-gate    my $t4 = $ua; $t4 .= $uab;
56*0Sstevel@tonic-gate
57*0Sstevel@tonic-gate    print eval '$t4 =~ /$ub/' ? "ok 9\n" : "not ok 9\t# $t4\n";
58*0Sstevel@tonic-gate
59*0Sstevel@tonic-gate    my $t5 = $a; $t5 = $ab . $t5;
60*0Sstevel@tonic-gate
61*0Sstevel@tonic-gate    print $t5 =~ /$ub/ ? "ok 10\n" : "not ok 10\t# $t5\n";
62*0Sstevel@tonic-gate
63*0Sstevel@tonic-gate    my $t6 = $a; $t6 = $uab . $t6;
64*0Sstevel@tonic-gate
65*0Sstevel@tonic-gate    print eval '$t6 =~ /$ub/' ? "ok 11\n" : "not ok 11\t# $t6\n";
66*0Sstevel@tonic-gate
67*0Sstevel@tonic-gate    my $t7 = $ua; $t7 = $ab . $t7;
68*0Sstevel@tonic-gate
69*0Sstevel@tonic-gate    print $t7 =~ /$ub/ ? "ok 12\n" : "not ok 12\t# $t7\n";
70*0Sstevel@tonic-gate
71*0Sstevel@tonic-gate    my $t8 = $ua; $t8 = $uab . $t8;
72*0Sstevel@tonic-gate
73*0Sstevel@tonic-gate    print eval '$t8 =~ /$ub/' ? "ok 13\n" : "not ok 13\t# $t8\n";
74*0Sstevel@tonic-gate}
75