Debian Codegraph @

t/usbonds.t

raw
1 #!/usr/bin/perl -w
2 use strict;
3 use Test::More;
4 use Finance::Quote;
5
6 if ( not $ENV{"ONLINE_TEST"} ) {
7 plan skip_all => 'Set $ENV{ONLINE_TEST} to run this test';
8 }
9
10 my $q = Finance::Quote->new('USBonds');
11 my $year = ( localtime() )[5] + 1900;
12 my $lastyear = $year - 1;
13
14 my @symbols = qw/
15 EE-100-2020-07
16 EE-50-2015-04
17 /;
18
19 plan tests => 1 + 6*(1+$#symbols) + 3;
20
21 my %quotes = $q->usbonds( @symbols, "BOGUS" );
22 ok(%quotes);
23
24 foreach my $symbol (@symbols) {
25 ok( $quotes{ $symbol, "success" }, "$symbol success" );
26 ok( $quotes{ $symbol, "symbol" } eq $symbol , "$symbol defined" );
27 ok( $quotes{ $symbol, "price" } > 0, "$symbol returned price" );
28 ok( $quotes{ $symbol, "isodate" } =~ /^\d{4}-\d{2}-\d{2}$/, "$symbol returned isodate" );
29 ok( substr( $quotes{ $symbol, "isodate" }, 0, 4 ) == $year
30 || substr( $quotes{ $symbol, "isodate" }, 0, 4 ) == $lastyear );
31 ok( substr( $quotes{ $symbol, "date" }, 6, 4 ) == $year
32 || substr( $quotes{ $symbol, "date" }, 6, 4 ) == $lastyear );
33 }
34
35 is( $quotes{ "EE-100-2020-07", "currency" }, 'USD' );
36 is( $quotes{ "EE-50-2015-04", "currency" }, 'USD' );
37
38 ok( !$quotes{ "BOGUS", "success" }, "symbol BOGUS fails" );