add compose routine and refactor FetchFirst to functional style
[dbsrgits/Data-Query.git] / t / perl.t
CommitLineData
81648036 1use strictures 1;
2use Test::More qw(no_plan);
3
4use Devel::Dwarn;
5use Data::Query::Renderer::Perl;
6use Data::Query::ExprHelpers qw(perl_scalar_value);
7
8BEGIN { require 't/expr.include' }
9
10my $rend = Data::Query::Renderer::Perl->new;
11
12sub binding { map perl_scalar_value($_), @_ }
13
14sub 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
21expr_perl_is { $_->foo }
22 [ '$_->foo' ],
23 'Simple identifier -> Perl';
24
25expr_perl_is { $_->foo->group }
26 [ '$_->foo->group' ],
27 'Complex identifier -> Perl';
28
29expr_perl_is { $_->foo == 1 }
30 [ "( \$_->foo == +shift )", binding(1) ],
31 "Simple expression -> Perl";
32
33expr_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
42expr_perl_is { !$_->foo }
43 [ '!( $_->foo )' ],
44 "Unary expression ok";