File: postfix_deref.t

package info (click to toggle)
libppr-perl 0.001010-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 932 kB
  • sloc: perl: 5,987; makefile: 2
file content (80 lines) | stat: -rw-r--r-- 1,681 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use warnings;
use strict;

use Test::More;

plan tests => 38;

use PPR;

my @valid_derefs = grep /\S/, split "\n", q{

        $sref->$*

        $aref->$#*
        $aref->@*
        $aref->@[1,2,3]
        $aref->%[1..3]

        $href->%*
        $href->%{'a','b'}
        $href->@{'a','b'}

        $cref->()
        $cref->&*

        $rref->$*->$*
        $rref->$*->@*

        $gref->**
        $gref->**->{IO}
        $gref->**->**->{IO}
        $gref->*{IO}

        $obj->method
        $obj->method()
        $obj->$method
        $obj->$method()

        # Composite look-ups, including elided arrows between brackets...
        $ref->{a}[1]('arg')[2]{z}
        $ref->method->[1]('arg')('arg2')->$method()->[2]{z}->**->$*->&*->$#*

        # These are all--believe it or not--legal (at least syntactically)...
        $aref->@*->%[1..3]
        $aref->@*->%{'k1', 'k2'}
        $aref->@*->method()
        $aref->@*->$*
        $aref->@*->**

        $href->%*->@[1..3]
        $href->%*->@{'k1', 'k2'}
        $href->%*->method()
        $href->%*->$*
        $href->%*->**
};

my @invalid_derefs = grep /\S/, split "\n", q{

        $aref->@*->[1]
        $aref->@*->@[1..3]
        $aref->@*->@{'k1', 'k2'}

        $href->%*->{k}
        $href->%*->%[1..3]
        $href->%*->%{'k1', 'k2'}
};

for my $deref (@valid_derefs) {
    next if $deref =~ m{\A \s* \#}xms;
    ok $deref =~ qr{ \A \s* (?&PerlPrefixPostfixTerm) \s* \Z $PPR::GRAMMAR}xms  => "Valid: $deref";
}

for my $deref (@invalid_derefs) {
    next if $deref =~ m{\A \s* \#}xms;
    ok $deref !~ qr{ \A \s* (?&PerlPrefixPostfixTerm) \s* \Z $PPR::GRAMMAR}xms  => "Invalid: $deref";
}


done_testing();