1#!/usr/bin/perl -w 2use strict; 3use Test::More; 4use Finance::Quote; 5use Time::Piece; 6 7if (not $ENV{ONLINE_TEST}) { 8 plan skip_all => 'Set $ENV{ONLINE_TEST} to run this test'; 9} 10 11plan tests => 91; 12 13# Test TIAA-CREF functions. 14 15my $q = Finance::Quote->new(); 16my $year = localtime()->year; 17my $lastyear = $year - 1; 18 19my @symbols = do { no warnings 'qw'; qw/ 20 QCBMIX 21 TEMLX 22 TLFIX 23 TSBPX 24 W156# 25 W323# 26 W464# 27 W719# 28/}; 29 30ok( my %quotes = $q->tiaacref( @symbols, 'BOGUS' ), 'retrieved quotes' ); 31 32for my $symbol (@symbols) { 33 34 # the following labels are expected to be supplied: 35 # symbol, nav, currency, method, exchange, price, date, isodate 36 37 ok( $quotes{$symbol,"success"} > 0, "$symbol got retrieved" ); 38 ok( $quotes{$symbol,"symbol"} eq $symbol, "$symbol has matching symbol" ); 39 ok( $quotes{$symbol,"nav"} > 0, "$symbol has a NAV" ); 40 ok( $quotes{$symbol,"nav"} =~ /^[\d\.]+$/, "$symbol NAV looks numeric" ); 41 ok( $quotes{$symbol,"currency"} eq "USD", "$symbol currency is valid" ); 42 ok( $quotes{$symbol,"method"} eq 'tiaacref', "$symbol has matching method" ); 43 ok( $quotes{$symbol,"exchange"} eq 'TIAA', "$symbol has matching exchange" ); 44 ok( length $quotes{$symbol,"name"}, "$symbol has defined name" ); 45 ok( $quotes{$symbol,"price"} == $quotes{$symbol,'nav'}, 46 "$symbol price == NAV" ); 47 ok( substr($quotes{$symbol,"isodate"}, 0, 4) == $year 48 || substr($quotes{$symbol,"isodate"}, 0, 4) == $lastyear, 49 "$symbol isodate is recent" ); 50 ok( substr($quotes{$symbol,"date"}, 6, 4) == $year 51 || substr($quotes{$symbol,"date"}, 6, 4) == $lastyear, 52 "$symbol date is recent" ); 53}; 54 55ok( $quotes{"BOGUS","success"} == 0, "BOGUS failed" ); 56ok( length $quotes{"BOGUS","errormsg"}, "BOGUS returned error message" ); 57