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