Commit | Line | Data |
9ee33178 |
1 | use strictures 1; |
2 | use Test::More qw(no_plan); |
9e0200bc |
3 | use Test::Exception; |
9ee33178 |
4 | |
7f666d37 |
5 | BEGIN { require 't/expr.include' } |
9ee33178 |
6 | |
7 | sub expr_is (&;@) { |
8 | my $sub = shift; |
2cf0bb42 |
9 | is_deeply(_run_expr($sub)->{expr}, @_); |
9ee33178 |
10 | } |
11 | |
12 | expr_is { $_->foo } |
13 | { |
14 | type => DQ_IDENTIFIER, |
15 | elements => [ 'foo' ] |
16 | }, |
17 | 'Simple identifier ok'; |
18 | |
19 | |
20 | expr_is { $_->foo->bar } |
21 | { |
22 | type => DQ_IDENTIFIER, |
23 | elements => [ 'foo', 'bar' ] |
24 | }, |
25 | 'Nested identifier ok'; |
b616bc41 |
26 | |
27 | expr_is { $_->foo == 3 } |
28 | { |
29 | type => DQ_OPERATOR, |
d68bc999 |
30 | operator => { Perl => '==' }, |
b616bc41 |
31 | args => [ |
32 | expr { $_->foo }, |
33 | { |
34 | type => DQ_VALUE, |
d68bc999 |
35 | subtype => { Perl => 'Scalar' }, |
b616bc41 |
36 | value => 3, |
37 | }, |
38 | ], |
39 | }, |
40 | 'Simple equality ok'; |
ef94e94d |
41 | |
42 | expr_is { $_->foo == 3 } |
43 | { |
44 | type => DQ_OPERATOR, |
d68bc999 |
45 | operator => { Perl => '==' }, |
ef94e94d |
46 | args => [ |
47 | expr { $_->foo }, |
48 | { |
49 | type => DQ_VALUE, |
d68bc999 |
50 | subtype => { Perl => 'Scalar' }, |
ef94e94d |
51 | value => 3, |
52 | }, |
53 | ], |
54 | }, |
55 | 'Simple equality ok'; |
56 | |
57 | expr_is { 3 == $_->foo } |
58 | { |
59 | type => DQ_OPERATOR, |
d68bc999 |
60 | operator => { Perl => '==' }, |
ef94e94d |
61 | args => [ |
62 | { |
63 | type => DQ_VALUE, |
d68bc999 |
64 | subtype => { Perl => 'Scalar' }, |
ef94e94d |
65 | value => 3, |
66 | }, |
67 | expr { $_->foo }, |
68 | ], |
69 | }, |
70 | 'Operand reversed equality ok'; |
9e0200bc |
71 | |
72 | throws_ok { |
73 | expr { $_->foo <=> 3 } |
74 | } qr/\QCan't use operator <=>/, 'Exception on bad operator'; |
7e599929 |
75 | |
76 | expr_is { $_->foo & $_->bar } |
77 | { |
78 | type => DQ_OPERATOR, |
d68bc999 |
79 | operator => { Perl => 'and' }, |
7e599929 |
80 | args => [ |
81 | expr { $_->foo }, |
82 | expr { $_->bar }, |
83 | ], |
84 | }, |
85 | 'Masquerade for & as and ok'; |
86 | |
87 | expr_is { $_->foo | $_->bar } |
88 | { |
89 | type => DQ_OPERATOR, |
d68bc999 |
90 | operator => { Perl => 'or' }, |
7e599929 |
91 | args => [ |
92 | expr { $_->foo }, |
93 | expr { $_->bar }, |
94 | ], |
95 | }, |
96 | 'Masquerade for | as or ok'; |
c3633a0e |
97 | |
98 | expr_is { !$_->foo } |
99 | { |
100 | type => DQ_OPERATOR, |
d68bc999 |
101 | operator => { Perl => '!' }, |
c3633a0e |
102 | args => [ expr { $_->foo } ], |
103 | }, |
104 | '! ok'; |