don't gensym for unqualified versions of already selected columns
[dbsrgits/Data-Query.git] / t / expr.t
index cc33fe6..3621e11 100644 (file)
--- a/t/expr.t
+++ b/t/expr.t
@@ -1,26 +1,12 @@
 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 }
@@ -41,12 +27,12 @@ expr_is { $_->foo->bar }
 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,
       },
     ],
@@ -56,12 +42,12 @@ expr_is { $_->foo == 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,
       },
     ],
@@ -71,11 +57,11 @@ expr_is { $_->foo == 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 },
@@ -86,3 +72,33 @@ expr_is { 3 == $_->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';