Skip to content

Commit

Permalink
Issue #2447: tests for Prepare()
Browse files Browse the repository at this point in the history
where Execute => 0 was passed
  • Loading branch information
bschmalhofer committed Sep 22, 2023
1 parent e1c5fec commit 1179faf
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions scripts/test/DB/ConvenienceMethods.t
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,42 @@ subtest 'SelectMapping' => sub {
}
};

subtest 'Prepare' => sub {
my @Tests = (
{
Name => 'Prepare without bind variable',
Param => {
SQL => 'SELECT country_en, is_country FROM test_countries ORDER BY country_en DESC',
},
Expected => [],
},
{
Name => 'Prepare with a single bind variable',
Param => {
SQL => 'SELECT country_en, is_country FROM test_countries WHERE country_si = ? ORDER BY country_en DESC',
Bind => [ \'🙈' ]
},
Expected => ['🙈'],
},
{
Name => 'Prepare with three bind variables',
Param => {
SQL => 'SELECT country_en, is_country FROM test_countries WHERE country_si IN (?, ?, ?) ORDER BY country_en DESC',
Bind => [ \'🙈', \'🙉', \'🙊' ],
},
Expected => [ '🙈', '🙉', '🙊' ],
},
);

for my $Test (@Tests) {
subtest $Test->{Name} => sub {
my ( $PrepareSuccess, @Binds ) = $DBObject->Prepare( $Test->{Param}->%*, Execute => 0 );
is( $PrepareSuccess, 1, 'Prepare was successful' );
is( \@Binds, $Test->{Expected}, 'got expected bind variables' );
};
}
};

# cleanup
my $CleanupSuccess = $DBObject->Do(
SQL => 'DROP TABLE test_countries',
Expand Down

0 comments on commit 1179faf

Please sign in to comment.