ACME-QuoteDB
view release on metacpan or search on metacpan
t/02-get_quotes.t view on Meta::CPAN
}
eval { # param mispelled
$sq->get_quote({Charcter => 'bart'});
};
if ($@) {
pass if $@ =~ m/unsupported argument option passed/;
} else {fail 'should alert user on non existant params' };
eval {
$sq->get_quote({Limit => '4'}); # only avail for 'get_quotes'
};
if ($@) {
pass if $@ =~ m/unsupported argument option passed/;
} else {fail 'should alert user on non existant params' };
eval {
$sq->get_quote({Contain => '4'}); # only avail for 'get_quotes_contain'
};
if ($@) {
pass if $@ =~ m/unsupported argument option passed/;
} else {fail 'should alert user on non existant params' };
# any unique part of name should work
# i.e these should all return the same results
is scalar @{$sq->get_quotes({AttrName => 'comic book guy'})}, 8;
is scalar @{$sq->get_quotes({AttrName => 'comic book'})}, 8;
is scalar @{$sq->get_quotes({AttrName => 'comic'})}, 8;
is scalar @{$sq->get_quotes({AttrName => 'book'})}, 8;
is scalar @{$sq->get_quotes({AttrName => 'book guy'})}, 8;
is scalar @{$sq->get_quotes({AttrName => 'guy'})}, 8;
eval {
$sq->get_quotes({AttrName => 'your momma'});
};
if ($@) {
pass 'ok' if $@ =~ m/attribution not found/;
pass 'ok'; #'dont talk about my momma on the simpsons';
} else {fail 'attribution should not be found' };
eval {
$sq->get_quotes({AttrName => 'chewbaccas momma'});
};
if ($@) {
pass 'ok' if $@ =~ m/attribution not found/;
pass 'ok'; #'now your really asking for trouble';
} else {fail 'attribution should not be found' };
eval { # param mispelled
$sq->get_quotes({Charcter => 'bart'});
};
if ($@) {
pass if $@ =~ m/unsupported argument option passed/;
} else {fail 'should alert user on non existant params' };
#sqlite> select COUNT(*) from quote where attribution_id IN (29,5);
#61 # get all family name wiggum quotes (ralph and clancy)
is scalar @{$sq->get_quotes({AttrName => 'wiggum', Rating => '2-10'})}, 15;
# get 6 random quotes
is scalar @{$sq->get_quotes({Limit => 6})}, 6;
is scalar @{$sq->get_quotes({
Limit => 2,
Rating => '9-10'
})}, 2; # get 2 very funny random quotes
is scalar @{$sq->get_quotes({
AttrName => ' wiggum ',
Rating => ' 4 - 7 ', # opps, 'spacing' out,...
Limit => 2
})}, 2; # get 2 not so funny wiggum quotes
ok $sq->get_quotes({
AttrName => 'comic',
Rating => '7'
})->[0] =~ m/Highlander/;
ok $sq->get_quotes({
AttrName => 'comic',
Rating => '7.0'
})->[0] =~ m/Highlander/;
my $gs = "Big deal! When I was a pup, we got spanked by presidents " .
"'til the cows came home! Grover Cleveland spanked me on " .
"two non-consecutive occasions!\n-- Grandpa Simpson";
is $sq->get_quotes_contain({
Contain => 'til the cow'
})->[0], $gs;
is $sq->get_quotes_contain({
Contain => 'til the cow',
Rating => '1-5',
Limit => 2
})->[0], undef;
eval {
$sq->get_quotes_contain({
Contain => 'til the cow',
Rating => '-7',
Limit => 2
})};
if ($@) {
pass if $@ =~ m/negative range not permitted/;
} else {fail 'should alert user on incorrect rating input' };
is $sq->get_quotes_contain({
Contain => 'wookie',
AttrName => 'ralph',
Limit => 1
})->[0], qq{I bent my wookie.\n-- Ralph Wiggum};
( run in 1.722 second using v1.01-cache-2.11-cpan-5837b0d9d2c )