File: | t/module.t |
Coverage: | 96.8% |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | 1 1 1 | 11377 2 98 | use strict; | ||||
2 | 1 1 1 | 3 2 35 | use warnings; | ||||
3 | |||||||
4 | 1 1 1 | 443 135334 24 | use Test::Most; | ||||
5 | |||||||
6 | 1 1 1 | 56159 2 62 | use constant MODULE => 'Time::DoAfter'; | ||||
7 | |||||||
8 | 1 1 1 1 1 | 4 728 2 1 23 | BEGIN { use_ok(MODULE); } | ||||
9 | 1 | 139005 | require_ok(MODULE); | ||||
10 | |||||||
11 | 1 | 667 | my @obj; | ||||
12 | 1 | 4 | ok( push( @obj, MODULE->new ), MODULE . '->new' ); | ||||
13 | 1 | 182 | is( ref $obj[-1], MODULE, 'ref $object' ); | ||||
14 | |||||||
15 | 1 | 198 | ok( push( @obj, MODULE->new( sub {} ) ), MODULE . '->new( sub {} )' ); | ||||
16 | 1 | 155 | is( ref $obj[-1], MODULE, 'ref $object' ); | ||||
17 | |||||||
18 | 1 | 209 | ok( push( @obj, MODULE->new( 'label1', sub {} ) ), MODULE . '->new( sub {} )' ); | ||||
19 | 1 | 174 | is( ref $obj[-1], MODULE, 'ref $object' ); | ||||
20 | |||||||
21 | ok( push( @obj, | ||||||
22 | 1 | 197 | MODULE->new( 'label2', sub {}, 2, 3, 'label3', sub {}, sub{}, 'label4', [ 2, 3 ] ) | ||||
23 | ), MODULE . '->new( sub {} )' ); | ||||||
24 | 1 | 226 | is( ref $obj[-1], MODULE, 'ref $object' ); | ||||
25 | |||||||
26 | 1 1 | 190 29 | lives_ok( sub{ $obj[1]->do }, '$object->do' ); | ||||
27 | 1 1 | 204 18 | lives_ok( sub{ $obj[0]->do( sub {} ) }, '$object->do( sub {} )' ); | ||||
28 | 1 1 | 206 17 | lives_ok( sub{ $obj[0]->do('label1') }, '$object->do("label") run 1' ); | ||||
29 | 1 1 | 189 17 | lives_ok( sub{ $obj[0]->do('label1') }, '$object->do("label") run 2' ); | ||||
30 | 1 1 | 182 14 | lives_ok( sub{ $obj[0]->do('label1') }, '$object->do("label") run 3' ); | ||||
31 | |||||||
32 | 1 | 201 | my $history; | ||||
33 | 1 1 | 5 16 | lives_ok( sub { $history = $obj[0]->history }, '$object->history' ); | ||||
34 | 1 | 369 | is( @$history, 5, 'full history size' ); | ||||
35 | |||||||
36 | 1 1 | 202 21 | lives_ok( sub { $history = $obj[0]->history('label1') }, '$object->history("label")' ); | ||||
37 | 1 | 225 | is( @$history, 3, 'label history size' ); | ||||
38 | |||||||
39 | 1 1 | 193 18 | lives_ok( sub { $history = $obj[0]->history('label1', 2 ) }, '$object->history( "label", 2 )' ); | ||||
40 | 1 | 510 | is( @$history, 2, 'label history size' ); | ||||
41 | |||||||
42 | 1 | 239 | ok( $obj[0]->last, '$object->last' ); | ||||
43 | 1 | 172 | ok( $obj[0]->last('label1'), '$object->last("label")' ); | ||||
44 | 1 | 186 | ok( $obj[0]->last( 'label1', 1138 ), '$object->last( "label", time )' ); | ||||
45 | 1 | 141 | is( $obj[0]->last('label1'), 1138, '$object->last("label") new time' ); | ||||
46 | |||||||
47 | 1 | 197 | ok( $obj[0]->now, '$object->now' ); | ||||
48 | |||||||
49 | 1 | 186 | my $sub = sub {}; | ||||
50 | 1 | 9 | isnt( $obj[0]->sub('label1'), $sub, '$object->sub("label")' ); | ||||
51 | 1 1 | 250 26 | lives_ok( sub { $obj[0]->sub( 'label1', $sub ) }, '$object->sub( "label", sub {} )' ); | ||||
52 | 1 | 184 | is( $obj[0]->sub('label1'), $sub, '$object->sub("label") saved' ); | ||||
53 | |||||||
54 | 1 | 169 | is_deeply( $obj[0]->wait('label4'), [ 2, 3 ], '$object->wait("label")' ); | ||||
55 | 1 1 | 435 20 | lives_ok( sub { $obj[0]->wait( 'label4', [ 5, 7 ] ) }, '$object->wait( "label", $new_wait )' ); | ||||
56 | 1 | 149 | is_deeply( $obj[0]->wait('label4'), [ 5, 7 ], '$object->wait("label") saved' ); | ||||
57 | |||||||
58 | 1 1 | 404 17 | lives_ok( sub { $obj[0]->wait_adjust( 'label4', 3 ) }, '$object->wait_adjust( "label", 2 )' ); | ||||
59 | 1 | 254 | is_deeply( $obj[0]->wait('label4'), [ 8, 10 ], '$object->wait("label") changed OK' ); | ||||
60 | 1 1 | 385 36 | lives_ok( sub { $obj[0]->wait_adjust( 'label4', -4 ) }, '$object->wait_adjust( "label", -4 )' ); | ||||
61 | 1 | 340 | is_deeply( $obj[0]->wait('label4'), [ 4, 6 ], '$object->wait("label") changed OK again' ); | ||||
62 | |||||||
63 | |||||||
64 | 1 1 | 401 17 | lives_ok( sub { $obj[0]->wait_adjust( 'label3', 3 ) }, '$object->wait_adjust( "simple", 3 )' ); | ||||
65 | 1 | 212 | is_deeply( $obj[0]->wait('label3'), 6, '$object->wait("simple") changed OK' ); | ||||
66 | |||||||
67 | |||||||
68 | |||||||
69 | |||||||
70 | 1 | 229 | done_testing; |