X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fsqlmaker%2Fbind_transport.t;h=aacd59c7908be8fec9e190031520c184c57cfc0a;hb=c0329273268971824784f239f32c7246e68da9c5;hp=cd93245a20d2f1ad2512af5b6526b43302f6d5f0;hpb=fcb7fcbb6bde5f9a211c62011b3110f07828caec;p=dbsrgits%2FDBIx-Class.git diff --git a/t/sqlmaker/bind_transport.t b/t/sqlmaker/bind_transport.t index cd93245..aacd59c 100644 --- a/t/sqlmaker/bind_transport.t +++ b/t/sqlmaker/bind_transport.t @@ -1,10 +1,14 @@ +BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) } + use strict; use warnings; + use Test::More; +use Test::Exception; +use Math::BigInt; + -use lib qw(t/lib); -use DBICTest; -use DBIC::SqlMakerTest; +use DBICTest ':DiffSQL'; use DBIx::Class::SQLMaker::LimitDialects; my ($ROWS, $OFFSET) = ( @@ -63,4 +67,90 @@ for (1,2) { # see if we get anything back at all isa_ok ($complex_rs->next, 'DBIx::Class::Row'); +# Make sure that the bind shorthand syntax translation is accurate (and doesn't error) +shorthand_check( + [ _sub => 2 ], + [ { dbic_colname => '_sub' } => 2 ], + '[ $name => $val ] === [ { dbic_colname => $name }, $val ]', +); +shorthand_check( + [ artist => 2 ], + [ { dbic_colname => 'artist', sqlt_datatype => 'integer' } => 2 ], + 'resolution of known column during [ $name => $val ] === [ { dbic_colname => $name }, $val ]', +); +shorthand_check( + [ \ 'number' => 2 ], + [ { sqlt_datatype => 'number' } => 2 ], + '[ \$dt => $val ] === [ { sqlt_datatype => $dt }, $val ]', +); +shorthand_check( + [ {} => 2 ], + [ {} => 2 ], + '[ {} => $val ] === [ {}, $val ]', +); +shorthand_check( + [ undef, 2 ], + [ {} => 2 ], + '[ undef, $val ] === [ {}, $val ]', +); +shorthand_check( + 2, + [ {} => 2 ], + '$val === [ {}, $val ]', +); + +shorthand_check( + Math::BigInt->new(42), + [ {} => Math::BigInt->new(42) ], + 'stringifyable $object === [ {}, $object ]', +); + +shorthand_check( + [ 2 ], + [ {} => [ 2 ] ], +); + +shorthand_check( + [ {} => [ 2 ] ], + [ {} => [ 2 ] ], +); + +shorthand_check( + [ {}, 2, 3 ], + [ {} => [ {}, 2, 3 ] ], +); + +shorthand_check( + bless( {}, 'Foo'), + [ {} => bless( {}, 'Foo') ], +); + +shorthand_check( + [ {}, bless( {}, 'Foo') ], + [ {}, bless( {}, 'Foo') ], +); + + +sub shorthand_check { + my ($bind_shorthand, $bind_expected, $testname) = @_; + + local $Test::Builder::Level = $Test::Builder::Level + 1; + + is_same_sql_bind ( + $schema->resultset('CD')->search({}, { + columns => [qw(cdid artist)], + group_by => ['cdid', \[ 'artist - ?', $bind_shorthand ] ], + })->as_query, + '( + SELECT me.cdid, me.artist + FROM cd me + GROUP BY cdid, artist - ? + )', + [ $bind_expected ], + $testname||(), + ); +} + +undef $schema; + done_testing;