1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
use 5.14.1;
use warnings;
use Test::More;
use Test::Fatal;
use Twitter::API::Util qw/:all/;
## Timestamp methods
sub ex_timestamp { 'Wed Jun 06 20:07:10 +0000 2012' }
sub ex_time { 1339013230 }
can_ok('Twitter::API::Util', $_) for qw/
timestamp_to_time
timestamp_to_gmtime
timestamp_to_localtime
is_twitter_api_error
/;
is timestamp_to_time(ex_timestamp), ex_time, 'example timestamp to time';
is(
scalar timestamp_to_gmtime(ex_timestamp),
scalar gmtime(ex_time),
'example timestamp to gmtime (scalar)'
);
is(
scalar timestamp_to_localtime(ex_timestamp),
scalar localtime(ex_time),
'example timestamp to localtime (scalar)'
);
is_deeply(
[ timestamp_to_gmtime(ex_timestamp) ],
[ gmtime(ex_time) ],
'example timestamp to gmtime (list context)'
);
is(
scalar timestamp_to_localtime(ex_timestamp),
scalar localtime(ex_time),
'example timestamp to localtime (list context)'
);
is timestamp_to_time(), undef, 'returns undef on undef input';
like(
exception { timestamp_to_time('bougus') },
qr/invalid timestamp/,
'croaks on invalid format'
);
## Twitter::API::Error
ok is_twitter_api_error(bless {}, 'Twitter::API::Error'), 'is api error';
ok !is_twitter_api_error(bless {}, 'Foo'), 'other object is not api error';
ok !is_twitter_api_error(1234), 'plain scalar is not api error';
ok !is_twitter_api_error(), 'empty is not api error';
done_testing;
|