Debian Codegraph @

t/fondsweb.t

raw
1 #!/usr/bin/perl -w
2
3 use constant DEBUG => $ENV{DEBUG};
4 use if DEBUG, Smart::Comments;
5
6 use strict;
7 use Test::More;
8 use Finance::Quote;
9
10 if (not $ENV{ONLINE_TEST}) {
11 plan skip_all => 'Set $ENV{ONLINE_TEST} to run this test';
12 }
13
14 my $q = Finance::Quote->new();
15 my @valid = ('LU0804734787','DE0008491002','DE0008474503','DE0008491051','DE0009805507');
16 my @invalid = qw/BOGUS/;
17 my @symbols = (@valid, @invalid);
18 my $year = (localtime())[5] + 1900;
19 my %check = (
20 'currency' => sub { $_[0] =~ /^[A-Z]+$/ },
21 'date' => sub { $_[0] =~ m{^[0-9]{2}/[0-9]{2}/([0-9]{4})$} and ($1 == $year || $1 == $year + 1) },
22 'isin' => sub { $_[0] =~ /^[A-Z]{2}[0-9]{10}$/ },
23 'isodate' => sub { $_[0] =~ /^([0-9]{4})-[0-9]{2}-[0-9]{2}$/ and ($1 == $year || $1 == $year + 1) },
24 'last' => sub { $_[0] =~ /^[0-9.]+$/ },
25 'method' => sub { $_[0] =~ /^fondsweb$/ },
26 'name' => sub { length($_[0]) },
27 'nav' => sub { $_[0] =~ /^[0-9.]+$/ },
28 'success' => sub { $_[0] },
29 'type' => sub { $_[0] eq 'fund' },
30 );
31
32 plan tests => 1 + %check*@valid + @invalid;
33
34 my %quotes = $q->fetch('fondsweb', @symbols);
35 ok(%quotes);
36
37 ### [<now>] quotes: %quotes
38
39 foreach my $symbol (@valid) {
40 while (my ($key, $lambda) = each %check) {
41 ok($lambda->($quotes{$symbol, $key}, $symbol), "$key -> $quotes{$symbol, $key}");
42 }
43 }
44
45 foreach my $symbol (@invalid) {
46 ok((not $quotes{'BOGUS', 'success'}), 'failed as expected');
47 }
48