use strictures 1;
use Test::More qw(no_plan);
-use Data::Query::ExprBuilder::Identifier;
-use Data::Query::Constants qw(DQ_IDENTIFIER DQ_OPERATOR DQ_VALUE);
use Test::Exception;
-sub expr (&) {
- _mk_expr($_[0]);
-}
-
-sub _mk_expr {
- local $_ = Data::Query::ExprBuilder::Identifier->new({
- expr => {
- type => DQ_IDENTIFIER,
- elements => [],
- },
- });
- $_[0]->()->{expr};
-}
+BEGIN { require 't/expr.include' }
sub expr_is (&;@) {
my $sub = shift;
- is_deeply(_mk_expr($sub), @_);
+ is_deeply(_run_expr($sub)->{expr}, @_);
}
expr_is { $_->foo }
expr_is { $_->foo == 3 }
{
type => DQ_OPERATOR,
- operator => { perl => '==' },
+ operator => { Perl => '==' },
args => [
expr { $_->foo },
{
type => DQ_VALUE,
- subtype => { perl => 'Scalar' },
+ subtype => { Perl => 'Scalar' },
value => 3,
},
],
expr_is { $_->foo == 3 }
{
type => DQ_OPERATOR,
- operator => { perl => '==' },
+ operator => { Perl => '==' },
args => [
expr { $_->foo },
{
type => DQ_VALUE,
- subtype => { perl => 'Scalar' },
+ subtype => { Perl => 'Scalar' },
value => 3,
},
],
expr_is { 3 == $_->foo }
{
type => DQ_OPERATOR,
- operator => { perl => '==' },
+ operator => { Perl => '==' },
args => [
{
type => DQ_VALUE,
- subtype => { perl => 'Scalar' },
+ subtype => { Perl => 'Scalar' },
value => 3,
},
expr { $_->foo },
throws_ok {
expr { $_->foo <=> 3 }
} qr/\QCan't use operator <=>/, 'Exception on bad operator';
+
+expr_is { $_->foo & $_->bar }
+ {
+ type => DQ_OPERATOR,
+ operator => { Perl => 'and' },
+ args => [
+ expr { $_->foo },
+ expr { $_->bar },
+ ],
+ },
+ 'Masquerade for & as and ok';
+
+expr_is { $_->foo | $_->bar }
+ {
+ type => DQ_OPERATOR,
+ operator => { Perl => 'or' },
+ args => [
+ expr { $_->foo },
+ expr { $_->bar },
+ ],
+ },
+ 'Masquerade for | as or ok';
+
+expr_is { !$_->foo }
+ {
+ type => DQ_OPERATOR,
+ operator => { Perl => '!' },
+ args => [ expr { $_->foo } ],
+ },
+ '! ok';