File: util.t

package info (click to toggle)
libtwitter-api-perl 1.0006-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 424 kB
  • sloc: perl: 2,868; makefile: 7
file content (58 lines) | stat: -rw-r--r-- 1,431 bytes parent folder | download | duplicates (2)
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;