Debian Codegraph @

t/googleweb.t

raw
1 #!/usr/bin/perl -w
2 # vi: set ts=2 sw=2 noai ic showmode showmatch:
3
4 use strict;
5
6 use constant DEBUG => $ENV{DEBUG};
7 use if DEBUG, 'Smart::Comments';
8
9 use Test::More;
10 use Finance::Quote;
11
12 if (not $ENV{ONLINE_TEST}) {
13 plan skip_all => 'Set $ENV{ONLINE_TEST} to run this test';
14 }
15
16 my $q = Finance::Quote->new('GoogleWeb', timeout => 30);
17 # AAPL (NASDAQ), GE (NYSE), ESML/NULC (BATS ETFs), VFIAX (MUTF mutual fund)
18 my @valid = ('AAPL', 'ESML', 'VFIAX', 'GE', 'NULC');
19 my @invalid = qw/BOGUS/;
20 my @symbols = (@valid, @invalid);
21 my $year = (localtime())[5] + 1900;
22 my $lastyear = $year - 1;
23 my %check = (
24 'currency' => sub { $_[0] =~ /^[A-Z]+$/ },
25 'date' => sub { $_[0] =~ m{^[0-9]{2}/[0-9]{2}/[0-9]{4}$} },
26 'isodate' => sub { $_[0] =~ /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/ },
27 'last' => sub { $_[0] =~ /^[0-9.]+$/ },
28 'method' => sub { $_[0] =~ /^googleweb$/ },
29 'success' => sub { $_[0] },
30 'symbol' => sub { $_[0] eq $_[1] },
31 );
32
33 plan tests => 1 + %check*@valid + @invalid;
34
35 my %quotes = $q->fetch('googleweb', @symbols);
36 ok(%quotes);
37
38 ### [<now>] quotes: %quotes
39
40 foreach my $symbol (@valid) {
41 while (my ($key, $lambda) = each %check) {
42 ok($lambda->($quotes{$symbol, $key}, $symbol), "$key -> $quotes{$symbol, $key}");
43 }
44 }
45
46 foreach my $symbol (@invalid) {
47 ok((not $quotes{'BOGUS', 'success'}), 'failed as expected');
48 }
49