forked from yuki-kimoto/gitprep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathage_string.t
41 lines (37 loc) · 2.4 KB
/
age_string.t
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
use Test::More 'no_plan';
use FindBin;
use lib "$FindBin::Bin/../lib";
use lib "$FindBin::Bin/../extlib/lib/perl5";
use Gitprep::Git;
my @cases = (
{ stimulus => 0, expected => 'right now' },
{ stimulus => 1, expected => 'a sec ago' },
{ stimulus => 59, expected => '59 sec ago' },
{ stimulus => 60, expected => 'a min ago' },
{ stimulus => 60 + 1, expected => 'a min ago' },
{ stimulus => 2 * 60 - 1, expected => 'a min ago' },
{ stimulus => 2 * 60, expected => '2 min ago' },
{ stimulus => 2 * 60 + 1, expected => '2 min ago' },
{ stimulus => 60 * 60 - 1, expected => '59 min ago' },
{ stimulus => 60 * 60, expected => 'an hour ago' },
{ stimulus => 60 * 60 + 1, expected => 'an hour ago' },
{ stimulus => 61 * 60, expected => 'an hour ago' },
{ stimulus => 24 * 60 * 60 - 1, expected => '23 hours ago' },
{ stimulus => 24 * 60 * 60, expected => 'a day ago' },
{ stimulus => 24 * 60 * 60 + 1, expected => 'a day ago' },
{ stimulus => 7 * 24 * 60 * 60 - 1, expected => '6 days ago' },
{ stimulus => 7 * 24 * 60 * 60, expected => 'a week ago' },
{ stimulus => 7 * 24 * 60 * 60 + 1, expected => 'a week ago' },
{ stimulus => (365/12) * 24 * 60 * 60 - 1, expected => '4 weeks ago' },
{ stimulus => (365/12) * 24 * 60 * 60, expected => 'a month ago' },
{ stimulus => (365/12) * 24 * 60 * 60 + 1, expected => 'a month ago' },
{ stimulus => 365 * 24 * 60 * 60 - 1, expected => '11 months ago' },
{ stimulus => 365 * 24 * 60 * 60, expected => 'a year ago' },
{ stimulus => 365 * 24 * 60 * 60 + 1, expected => 'a year ago' },
{ stimulus => 2 * 365 * 24 * 60 * 60 - 1, expected => 'a year ago' },
{ stimulus => 2 * 365 * 24 * 60 * 60, expected => '2 years ago' },
{ stimulus => 2 * 365 * 24 * 60 * 60 + 1, expected => '2 years ago' },
);
for ( @cases ) {
is ( Gitprep::Git->new->_age_string ( $_->{stimulus} ), $_->{expected}, "$_->{stimulus} sec ~ \"$_->{expected}\"" );
}