File: 89tickit-test.t

package info (click to toggle)
libtickit-perl 0.73-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 660 kB
  • sloc: perl: 4,944; makefile: 5
file content (78 lines) | stat: -rw-r--r-- 1,425 bytes parent folder | download
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/perl

use v5.14;
use warnings;

use Test::More;

use Tickit::Test;

use Time::HiRes qw( time );

my $tickit = mk_tickit;

isa_ok( $tickit, "Tickit", '$tickit' );

isa_ok( $tickit->term, "Tickit::Term", '$tickit->term' );
isa_ok( $tickit->rootwin, "Tickit::Window", '$tickit->rootin' );

# TODO: IO will be difficult to mock

# timer
{
   my $called;
   $tickit->watch_timer_after( 0.1, sub { $called++ } );

   flush_tickit;

   ok( !$called, '->watch_timer_after not yet invoked' );

   flush_tickit 0.5;

   ok( $called, '->watch_timer_after now invoked callback' );

   undef $called;
   $tickit->watch_timer_at( time + 0.2, sub { $called++ } );

   flush_tickit;

   ok( !$called, '->watch_timer_at not yet invoked' );

   flush_tickit 0.5;

   ok( $called, '->watch_timer_at now invoked callback' );
}

# timer cancellation
{
   my $called;
   my $id = $tickit->watch_timer_after( 0.2, sub { $called++ } );
   $tickit->watch_cancel( $id );

   flush_tickit 0.5;

   ok( !$called, '->watch_timer_after does not invoke after cancel' );
}

# later
{
   my $called;
   $tickit->watch_later( sub { $called++ } );

   flush_tickit;

   ok( $called, '->watch_later invokes callback' );
}

# later cancellation
{
   my $called;
   my $id = $tickit->watch_later( sub { $called++ } );
   $tickit->watch_cancel( $id );

   flush_tickit;

   ok( !$called, '->watch_later does not invoke after cancel' );
}

done_testing;