use strictures 1;
use Test::More qw(no_plan);
-use Data::Query::ExprBuilder::Identifier;
-use Data::Query::Constants qw(DQ_IDENTIFIER);
-
-sub mk_expr {
- local $_ = Data::Query::ExprBuilder::Identifier->new({
- expr => {
- type => DQ_IDENTIFIER,
- elements => [],
- },
- });
- $_[0]->()->{expr};
-}
+use Test::Exception;
+
+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 }
elements => [ 'foo', 'bar' ]
},
'Nested identifier ok';
+
+expr_is { $_->foo == 3 }
+ {
+ type => DQ_OPERATOR,
+ operator => { Perl => '==' },
+ args => [
+ expr { $_->foo },
+ {
+ type => DQ_VALUE,
+ subtype => { Perl => 'Scalar' },
+ value => 3,
+ },
+ ],
+ },
+ 'Simple equality ok';
+
+expr_is { $_->foo == 3 }
+ {
+ type => DQ_OPERATOR,
+ operator => { Perl => '==' },
+ args => [
+ expr { $_->foo },
+ {
+ type => DQ_VALUE,
+ subtype => { Perl => 'Scalar' },
+ value => 3,
+ },
+ ],
+ },
+ 'Simple equality ok';
+
+expr_is { 3 == $_->foo }
+ {
+ type => DQ_OPERATOR,
+ operator => { Perl => '==' },
+ args => [
+ {
+ type => DQ_VALUE,
+ subtype => { Perl => 'Scalar' },
+ value => 3,
+ },
+ expr { $_->foo },
+ ],
+ },
+ 'Operand reversed equality ok';
+
+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';