This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Use PL_{argv,stdin,stdout}gv to avoid unnecessary gv_fetch calls.
[perl5.git] / t / op / concat.t
CommitLineData
bdaa056b
JH
1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6}
7
0dee2995
MS
8# This ok() function is specially written to avoid any concatenation.
9my $test = 1;
10sub ok {
11 my($ok, $name) = @_;
bdaa056b 12
0dee2995 13 printf "%sok %d - %s\n", ($ok ? "" : "not "), $test, $name;
bdaa056b 14
0dee2995 15 printf "# Failed test at line %d\n", (caller)[2] unless $ok;
bdaa056b 16
0dee2995
MS
17 $test++;
18 return $ok;
19}
bdaa056b 20
0dee2995 21print "1..12\n";
bdaa056b 22
0dee2995
MS
23($a, $b, $c) = qw(foo bar);
24
25ok("$a" eq "foo", "verifying assign");
26ok("$a$b" eq "foobar", "basic concatenation");
27ok("$c$a$c" eq "foo", "concatenate undef, fore and aft");
bdaa056b 28
0dee2995 29# Okay, so that wasn't very challenging. Let's go Unicode.
bdaa056b
JH
30
31{
32 # bug id 20000819.004
33
34 $_ = $dx = "\x{10f2}";
35 s/($dx)/$dx$1/;
36 {
0dee2995 37 ok($_ eq "$dx$dx","bug id 20000819.004, back");
bdaa056b
JH
38 }
39
40 $_ = $dx = "\x{10f2}";
41 s/($dx)/$1$dx/;
42 {
0dee2995 43 ok($_ eq "$dx$dx","bug id 20000819.004, front");
bdaa056b
JH
44 }
45
46 $dx = "\x{10f2}";
47 $_ = "\x{10f2}\x{10f2}";
48 s/($dx)($dx)/$1$2/;
49 {
0dee2995 50 ok($_ eq "$dx$dx","bug id 20000819.004, front and back");
bdaa056b
JH
51 }
52}
53
54{
55 # bug id 20000901.092
56 # test that undef left and right of utf8 results in a valid string
57
58 my $a;
59 $a .= "\x{1ff}";
0dee2995
MS
60 ok($a eq "\x{1ff}", "bug id 20000901.092, undef left");
61 $a .= undef;
62 ok($a eq "\x{1ff}", "bug id 20000901.092, undef right");
bdaa056b
JH
63}
64
65{
66 # ID 20001020.006
67
68 "x" =~ /(.)/; # unset $2
69
70 # Without the fix this 5.7.0 would croak:
71 # Modification of a read-only value attempted at ...
0dee2995
MS
72 eval {"$2\x{1234}"};
73 ok(!$@, "bug id 20001020.006, left");
bdaa056b
JH
74
75 # For symmetry with the above.
0dee2995
MS
76 eval {"\x{1234}$2"};
77 ok(!$@, "bug id 20001020.006, right");
bdaa056b
JH
78
79 *pi = \undef;
80 # This bug existed earlier than the $2 bug, but is fixed with the same
81 # patch. Without the fix this 5.7.0 would also croak:
82 # Modification of a read-only value attempted at ...
0dee2995
MS
83 eval{"$pi\x{1234}"};
84 ok(!$@, "bug id 20001020.006, constant left");
bdaa056b
JH
85
86 # For symmetry with the above.
0dee2995
MS
87 eval{"\x{1234}$pi"};
88 ok(!$@, "bug id 20001020.006, constant right");
bdaa056b 89}