X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F100populate.t;h=57efc7232de648167d252099164e1e95da70ae01;hb=0a768c9067712d4f9512748c315c617367fe8dc4;hp=16c1e6db404047ac2e3ec17071bac7c191b82ae3;hpb=d0cefd99a98e7fb2304fe6a5182d321fe7c551fc;p=dbsrgits%2FDBIx-Class.git diff --git a/t/100populate.t b/t/100populate.t index 16c1e6d..57efc72 100644 --- a/t/100populate.t +++ b/t/100populate.t @@ -395,79 +395,108 @@ warnings_like { my $rank = Math::BigInt->new(42); my $args = { - 'stringifying objects after regular values' => [ map - { { name => $_, rank => $rank } } - ( + 'stringifying objects after regular values' => { AoA => [ + [qw( name rank )], + ( map { [ $_, $rank ] } ( 'supplied before stringifying objects', 'supplied before stringifying objects 2', $fn, $fn2, - ) - ], - 'stringifying objects before regular values' => [ map - { { name => $_, rank => $rank } } - ( + )), + ]}, + + 'stringifying objects before regular values' => { AoA => [ + [qw( rank name )], + ( map { [ $rank, $_ ] } ( $fn, $fn2, 'supplied after stringifying objects', 'supplied after stringifying objects 2', - ) - ], - 'stringifying objects between regular values' => [ map - { { name => $_, rank => $rank } } - ( + )), + ]}, + + 'stringifying objects between regular values' => { AoA => [ + [qw( name rank )], + ( map { [ $_, $rank ] } ( 'supplied before stringifying objects', $fn, $fn2, 'supplied after stringifying objects', - ) - ], - 'stringifying objects around regular values' => [ map - { { name => $_, rank => $rank } } - ( + )) + ]}, + + 'stringifying objects around regular values' => { AoA => [ + [qw( rank name )], + ( map { [ $rank, $_ ] } ( $fn, 'supplied between stringifying objects', $fn2, - ) - ], + )) + ]}, + + 'single stringifying object' => { AoA => [ + [qw( rank name )], + [ $rank, $fn ], + ]}, }; - local $Storable::canonical = 1; - my $preimage = nfreeze([$fn, $fn2, $rank, $args]); + # generate the AoH equivalent based on the AoAs above + for my $bag (values %$args) { + my @hdr = @{$bag->{AoA}[0]}; + for my $v ( @{$bag->{AoA}}[1..$#{$bag->{AoA}}] ) { + push @{$bag->{AoH}}, my $h = {}; + @{$h}{@hdr} = @$v; + } + } - for my $tst (keys %$args) { + local $Storable::canonical = 1; + my $preimage = nfreeze($args); - # test void ctx - $rs->delete; - $rs->populate($args->{$tst}); - is_deeply( - $rs->all_hri, - $args->{$tst}, - "Populate() $tst in void context" - ); - # test non-void ctx - $rs->delete; - my $dummy = $rs->populate($args->{$tst}); - is_deeply( - $rs->all_hri, - $args->{$tst}, - "Populate() $tst in non-void context" - ); + for my $tst (keys %$args) { + for my $type (qw(AoA AoH)) { + + # test void ctx + $rs->delete; + $rs->populate($args->{$tst}{$type}); + is_deeply( + $rs->all_hri, + $args->{$tst}{AoH}, + "Populate() $tst in void context" + ); + + # test scalar ctx + $rs->delete; + my $dummy = $rs->populate($args->{$tst}{$type}); + is_deeply( + $rs->all_hri, + $args->{$tst}{AoH}, + "Populate() $tst in non-void context" + ); + + # test list ctx + $rs->delete; + my @dummy = $rs->populate($args->{$tst}{$type}); + is_deeply( + $rs->all_hri, + $args->{$tst}{AoH}, + "Populate() $tst in non-void context" + ); + } # test create() as we have everything set up already $rs->delete; - $rs->create($_) for @{$args->{$tst}}; + $rs->create($_) for @{$args->{$tst}{AoH}}; is_deeply( $rs->all_hri, - $args->{$tst}, + $args->{$tst}{AoH}, "Create() $tst" ); } ok ( - ($preimage eq nfreeze( [$fn, $fn2, $rank, $args] )), + ($preimage eq nfreeze($args)), 'Arguments fed to populate()/create() unchanged' ); @@ -482,7 +511,7 @@ warnings_like { ) ? () # one unique for populate() and create() each - : (qr/\QPOSSIBLE *PAST* DATA CORRUPTION detected \E.+\QTrigger condition encountered at @{[ __FILE__ ]} line\E \d/) x 2 + : (qr/\QPOSSIBLE *PAST* DATA CORRUPTION detected \E.+\QTrigger condition encountered at @{[ __FILE__ ]} line\E \d/) x 4 ], 'Data integrity warnings as planned'; $schema->is_executed_sql_bind(