Display characters as Unicode for clarity
[p5sagit/p5-mst-13.2.git] / t / re / reg_nc_tie.t
CommitLineData
192b9cd1 1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6 require './test.pl';
7}
8
9# Do a basic test on all the tied methods of Tie::Hash::NamedCapture
10
1d021cc8 11plan(tests => 21);
1e1d4b91 12
13# PL_curpm->paren_names can be a null pointer. See that this succeeds anyway.
14'x' =~ /(.)/;
15() = %+;
16pass( 'still alive' );
192b9cd1 17
18"hlagh" =~ /
19 (?<a>.)
20 (?<b>.)
21 (?<a>.)
22 .*
23 (?<e>$)
24/x;
25
26# FETCH
27is($+{a}, "h", "FETCH");
28is($+{b}, "l", "FETCH");
29is($-{a}[0], "h", "FETCH");
30is($-{a}[1], "a", "FETCH");
31
32# STORE
33eval { $+{a} = "yon" };
34ok(index($@, "read-only") != -1, "STORE");
35
36# DELETE
37eval { delete $+{a} };
38ok(index($@, "read-only") != -1, "DELETE");
39
40# CLEAR
41eval { %+ = () };
42ok(index($@, "read-only") != -1, "CLEAR");
43
44# EXISTS
45ok(exists $+{e}, "EXISTS");
46ok(!exists $+{d}, "EXISTS");
47
48# FIRSTKEY/NEXTKEY
49is(join('|', sort keys %+), "a|b|e", "FIRSTKEY/NEXTKEY");
50
51# SCALAR
52is(scalar(%+), 3, "SCALAR");
53is(scalar(%-), 3, "SCALAR");
1d021cc8 54
55# Abuse all methods with undef as the first argument (RT #71828 and then some):
56
57is(Tie::Hash::NamedCapture::FETCH(undef, undef), undef, 'FETCH with undef');
58eval {Tie::Hash::NamedCapture::STORE(undef, undef, undef)};
59like($@, qr/Modification of a read-only value attempted/, 'STORE with undef');
60eval {Tie::Hash::NamedCapture::DELETE(undef, undef)};
61like($@, , qr/Modification of a read-only value attempted/,
62 'DELETE with undef');
63eval {Tie::Hash::NamedCapture::CLEAR(undef)};
64like($@, qr/Modification of a read-only value attempted/, 'CLEAR with undef');
65is(Tie::Hash::NamedCapture::EXISTS(undef, undef), undef, 'EXISTS with undef');
66is(Tie::Hash::NamedCapture::FIRSTKEY(undef), undef, 'FIRSTKEY with undef');
67is(Tie::Hash::NamedCapture::NEXTKEY(undef, undef), undef, 'NEXTKEY with undef');
68is(Tie::Hash::NamedCapture::SCALAR(undef), undef, 'SCALAR with undef');