Debian Codegraph @

t/bvb.t

raw
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 use constant DEBUG => $ENV{DEBUG};
6 use if DEBUG, 'Smart::Comments';
7
8 use Test::More;
9 use Finance::Quote;
10
11 if (not $ENV{ONLINE_TEST}) {
12 plan skip_all => 'Set $ENV{ONLINE_TEST} to run this test';
13 }
14
15 my $q = Finance::Quote->new();
16 my @stocks = ("TLV", "BAYN", "SNP");
17 my $year = (localtime())[5] + 1900;
18 my $lastyear = $year - 1;
19
20 # Tests: fetch, fetch BOGUS, and 5 per stock
21 plan tests => 2 + 5*@stocks;
22
23 my %quotes = $q->fetch("bvb", @stocks);
24 ok(%quotes);
25
26 # Check that the name and last are defined for all of the stocks.
27 foreach my $stock (@stocks) {
28 ok($quotes{$stock, "last"} > 0);
29 ok($quotes{$stock, "success"});
30 ok($quotes{$stock, "currency"} eq "RON");
31 ok(substr($quotes{$stock,"isodate"},0,4) == $year ||
32 substr($quotes{$stock,"isodate"},0,4) == $lastyear);
33 ok(substr($quotes{$stock,"date"},6,4) == $year ||
34 substr($quotes{$stock,"date"},6,4) == $lastyear);
35 }
36
37 # Check that a bogus fund returns no-success.
38 %quotes = $q->fetch("bvb", "BOGUS");
39 ok(! $quotes{"BOGUS","success"});