From: Ash Berlin Date: Tue, 3 Mar 2009 23:59:55 +0000 (+0000) Subject: Add tests for more basic constructs X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FSQL-Abstract-2.0-ish.git;a=commitdiff_plain;h=44cfd1f679b239e32d7cc7e79f0a74d678ac6f6a Add tests for more basic constructs --- diff --git a/lib/SQL/Abstract/AST/v1.pm b/lib/SQL/Abstract/AST/v1.pm index 4040104..bf50d4f 100644 --- a/lib/SQL/Abstract/AST/v1.pm +++ b/lib/SQL/Abstract/AST/v1.pm @@ -134,6 +134,7 @@ class SQL::Abstract::AST::v1 extends SQL::Abstract { method _in($ast) { my (undef, $field, @values) = @$ast; + return $self->_false if @values == 0; return $self->dispatch($field) . " IN (" . join(", ", map { $self->dispatch($_) } @values ) . @@ -143,4 +144,8 @@ class SQL::Abstract::AST::v1 extends SQL::Abstract { method _generic_func(ArrayRef $ast) { } + # 'constants' that are portable across DBs + method _false($ast?) { "0 = 1" } + method _true($ast?) { "1 = 1" } + } diff --git a/t/001_basic.t b/t/001_basic.t index ce0bb8f..2f009ba 100644 --- a/t/001_basic.t +++ b/t/001_basic.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 15; +use Test::More tests => 18; use Test::Differences; use_ok('SQL::Abstract') or BAIL_OUT( "$@" ); @@ -12,6 +12,14 @@ is $sqla->dispatch( [ -name => qw/me id/]), "me.id", "Simple name generator"; is $sqla->dispatch( + [ '-false' ] +), "0 = 1", "false value"; + +is $sqla->dispatch( + [ '-true' ] +), "1 = 1", "true value"; + +is $sqla->dispatch( [ -list => [ -name => qw/me id/], [ -name => qw/me foo bar/], @@ -42,6 +50,10 @@ is $sqla->dispatch( is $sqla->dispatch( + [ -in => [ ] ] +), "0 = 1", "emtpy -in"; + +is $sqla->dispatch( [ -where => [ '>', [-name => qw/me id/], [-value => 500 ] ] ]