| 1 |
#!/usr/bin/perl -w |
| 2 |
use strict; |
| 3 |
use Test::More tests => 12; |
| 4 |
use Finance::Quote; |
| 5 |
|
| 6 |
# Test overall currency lookup |
| 7 |
my $currencies = Finance::Quote::currency_lookup(); |
| 8 |
|
| 9 |
my %test_currencies = ( AUD => "Australian Dollar" |
| 10 |
, EUR => "Euro" |
| 11 |
, CAD => "Canadian Dollar" |
| 12 |
); |
| 13 |
|
| 14 |
while ( my ($code, $name) = each %test_currencies ) { |
| 15 |
ok( exists $currencies->{$code}, "Expected currency code (${code}) exists" ); |
| 16 |
is( $currencies->{$code}->{name} |
| 17 |
, $name |
| 18 |
, "Expected currency name (${name}) for code (${code})" |
| 19 |
); |
| 20 |
} |
| 21 |
|
| 22 |
# Test selective currency lookup |
| 23 |
$currencies = Finance::Quote::currency_lookup( name => qr/pound/i ); |
| 24 |
|
| 25 |
# Test multiple lookup parameters |
| 26 |
$currencies = Finance::Quote::currency_lookup( name => "Australia" |
| 27 |
, code => qr/AU/ ); |
| 28 |
ok( exists $currencies->{AUD} |
| 29 |
, "Expected currency code (AUD) exists for matching multiple params" ); |
| 30 |
cmp_ok( scalar keys %{$currencies}, '==', 1 |
| 31 |
, "Only one currency returned for matching multiple params" |
| 32 |
); |
| 33 |
|
| 34 |
$currencies = Finance::Quote::currency_lookup( name => "Euro" |
| 35 |
, code => "AUD" ); |
| 36 |
cmp_ok( scalar keys %{$currencies}, '==', 0 |
| 37 |
, "Expected zero-response for non-matching multiple params" |
| 38 |
); |
| 39 |
|
| 40 |
# Test non-matching currency lookup |
| 41 |
$currencies = Finance::Quote::currency_lookup( name => qr/rubbish_value/i ); |
| 42 |
is( ref $currencies |
| 43 |
, 'HASH' |
| 44 |
, 'Hash-ref returned for non-matching lookup' |
| 45 |
); |
| 46 |
cmp_ok( scalar keys %{$currencies} |
| 47 |
, '==', 0 |
| 48 |
, "Empty hashref returned for non-matching lookup" |
| 49 |
); |
| 50 |
|
| 51 |
# Suppress warning message in last test |
| 52 |
local $SIG{__WARN__} = sub {}; |
| 53 |
|
| 54 |
# Test that an error returns undef |
| 55 |
$currencies = Finance::Quote::currency_lookup( invalid_param => 1 ); |
| 56 |
is( $currencies |
| 57 |
, undef |
| 58 |
, "Error results in undef response" |
| 59 |
); |