This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #35865, #43011] FETCH after autovivifying
[perl5.git] / t / op / qr.t
CommitLineData
c2123ae3
NC
1#!./perl -w
2
3use strict;
4
5require './test.pl';
6
b9ad13ac 7plan(tests => 18);
c2123ae3
NC
8
9sub r {
10 return qr/Good/;
11}
12
13my $a = r();
bbce3ca6 14object_ok($a, 'Regexp');
c2123ae3 15my $b = r();
bbce3ca6 16object_ok($b, 'Regexp');
c2123ae3
NC
17
18my $b1 = $b;
19
20isnt($a + 0, $b + 0, 'Not the same object');
21
22bless $b, 'Pie';
23
bbce3ca6
MS
24object_ok($b, 'Pie');
25object_ok($a, 'Regexp');
26object_ok($b1, 'Pie');
c2123ae3
NC
27
28my $c = r();
29like("$c", qr/Good/);
30my $d = r();
31like("$d", qr/Good/);
32
33my $d1 = $d;
34
35isnt($c + 0, $d + 0, 'Not the same object');
36
37$$d = 'Bad';
38
39like("$c", qr/Good/);
b9ad13ac
NC
40is($$d, 'Bad');
41is($$d1, 'Bad');
42
43# Assignment to an implicitly blessed Regexp object retains the class
44# (No different from direct value assignment to any other blessed SV
45
bbce3ca6 46object_ok($d, 'Regexp');
b9ad13ac
NC
47like("$d", qr/\ARegexp=SCALAR\(0x[0-9a-f]+\)\z/);
48
49# As does an explicitly blessed Regexp object.
50
51my $e = bless qr/Faux Pie/, 'Stew';
52
bbce3ca6 53object_ok($e, 'Stew');
b9ad13ac
NC
54$$e = 'Fake!';
55
56is($$e, 'Fake!');
bbce3ca6 57object_ok($e, 'Stew');
b9ad13ac 58like("$e", qr/\Stew=SCALAR\(0x[0-9a-f]+\)\z/);