make -is work at top level
[scpubgit/Q-Branch.git] / t / 08special_ops.t
index 7632be4..131f99e 100644 (file)
@@ -1,5 +1,3 @@
-#!/usr/bin/perl
-
 use strict;
 use warnings;
 use Test::More;
@@ -11,7 +9,7 @@ use SQL::Abstract;
 my $sqlmaker = SQL::Abstract->new(special_ops => [
 
   # special op for MySql MATCH (field) AGAINST(word1, word2, ...)
-  {regex => qr/^match$/i, 
+  {regex => qr/^match$/i,
    handler => sub {
      my ($self, $field, $op, $arg) = @_;
      $arg = [$arg] if not ref $arg;
@@ -26,7 +24,7 @@ my $sqlmaker = SQL::Abstract->new(special_ops => [
    },
 
   # special op for Basis+ NATIVE
-  {regex => qr/^native$/i, 
+  {regex => qr/^native$/i,
    handler => sub {
      my ($self, $field, $op, $arg) = @_;
      $arg =~ s/'/''/g;
@@ -35,11 +33,16 @@ my $sqlmaker = SQL::Abstract->new(special_ops => [
      }
    },
 
+], unary_ops => [
+  # unary op from Mojo::Pg
+  {regex => qr/^json$/i,
+   handler => sub { '?', { json => $_[2] } }
+  },
 ]);
 
 my @tests = (
 
-  #1 
+  #1
   { where => {foo => {-match => 'foo'},
               bar => {-match => [qw/foo bar/]}},
     stmt  => " WHERE ( MATCH (bar) AGAINST (?, ?) AND MATCH (foo) AGAINST (?) )",
@@ -52,6 +55,18 @@ my @tests = (
     bind  => [],
   },
 
+  #3
+  { where => { foo => { -json => { bar => 'baz' } } },
+    stmt => "WHERE foo = ?",
+    bind => [ { json => { bar => 'baz' } } ],
+  },
+
+  #4
+  { where => { foo => { '@>' => { -json => { bar => 'baz' } } } },
+    stmt => "WHERE foo @> ?",
+    bind => [ { json => { bar => 'baz' } } ],
+  },
+
 );
 
 for (@tests) {