Commit | Line | Data |
81648036 |
1 | use strictures 1; |
2 | use Test::More qw(no_plan); |
3 | |
4 | use Devel::Dwarn; |
5 | use Data::Query::Renderer::Perl; |
6 | use Data::Query::ExprHelpers qw(perl_scalar_value); |
7 | |
8 | BEGIN { require 't/expr.include' } |
9 | |
10 | my $rend = Data::Query::Renderer::Perl->new; |
11 | |
12 | sub binding { map perl_scalar_value($_), @_ } |
13 | |
14 | sub expr_perl_is (&;@) { |
15 | my $sub = shift; |
16 | @_ |
17 | ? is_deeply($rend->render(_run_expr($sub)->{expr}), @_) |
18 | : ::Dwarn($rend->render(_run_expr($sub)->{expr})); |
19 | } |
20 | |
21 | expr_perl_is { $_->foo } |
22 | [ '$_->foo' ], |
23 | 'Simple identifier -> Perl'; |
24 | |
25 | expr_perl_is { $_->foo->group } |
26 | [ '$_->foo->group' ], |
27 | 'Complex identifier -> Perl'; |
28 | |
29 | expr_perl_is { $_->foo == 1 } |
30 | [ "( \$_->foo == +shift )", binding(1) ], |
31 | "Simple expression -> Perl"; |
32 | |
33 | expr_perl_is { ($_->foo == 1) & ($_->bar eq "foo") } |
34 | [ |
35 | "( ( \$_->foo == +shift ) and ( \$_->bar eq +shift ) )", |
36 | binding(1, "foo") |
37 | ], |
38 | "Compound expression -> Perl"; |
39 | |
40 | # Skipping flattening test for now |
41 | |
42 | expr_perl_is { !$_->foo } |
43 | [ '!( $_->foo )' ], |
44 | "Unary expression ok"; |