File: 20rootwin.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 (172 lines) | stat: -rw-r--r-- 4,831 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/perl

use v5.14;
use warnings;

use Test::More;
use Test::Refcount;

use Tickit::Test;

my ( $term, $win ) = mk_term_and_window;

isa_ok( $win, "Tickit::Window", '$win isa Tickit::Window' );

is_refcount( $win, 1, '$win has refcount 1 initially' );

is( $win->top,  0, '$win->top is 0' );
is( $win->left, 0, '$win->left is 0' );

is( $win->abs_top,  0, '$win->abs_top is 0' );
is( $win->abs_left, 0, '$win->abs_left is 0' );

is( $win->lines, 25, '$win->lines is 25' );
is( $win->cols,  80, '$win->cols is 80' );

isa_ok( $win->term, "Tickit::Term", '$win->term' );

isa_ok( $win->tickit, "Tickit", '$win->tickit' );

# window pen
{
   isa_ok( $win->pen, "Tickit::Pen", '$win->pen isa Tickit::Pen' );

   is_deeply( { $win->pen->getattrs },
              {},
              '$win->pen has no attrs set' );

   is( $win->getpenattr( 'fg' ), undef, '$win has pen fg undef' );

   is_deeply( { $win->get_effective_pen->getattrs },
              {},
              '$win->get_effective_pen has no attrs set' );

   is( $win->get_effective_penattr( 'fg' ), undef, '$win has effective pen fg undef' );

   $win->pen->chattr( fg => 3 );

   is_deeply( { $win->pen->getattrs },
              { fg => 3 },
              '$win->pen->getattrs has fg => 3' );

   is( $win->getpenattr( 'fg' ), 3, '$win has pen fg 3' );

   is_deeply( { $win->get_effective_pen->getattrs },
              { fg => 3 },
              '$win->get_effective_pen has fg => 3' );

   is( $win->get_effective_penattr( 'fg' ), 3, '$win has effective pen fg 3' );

   my $newpen = Tickit::Pen->new;
   $newpen->chattr( fg => 3 );
   $newpen->chattr( u => 1 );

   $win->set_pen( $newpen );

   is_deeply( { $win->pen->getattrs },
              { fg => 3, u => 1 },
              '$win->set_pen replaces window pen' );

   $win->pen->chattr( u => undef );
}

# scrolling
{
   ok( $win->scroll( 1, 0 ), '$win can ->scroll' );

   is_termlog( [ SETBG(undef),
                 SCROLLRECT(0,0,25,80, 1,0) ],
               'Termlog scrolled' );

   $win->scrollrect( Tickit::Rect->new( top => 5, left => 0, lines => 10, cols => 80 ),
                     3, 0 );

   is_termlog( [ SETBG(undef),
                 SCROLLRECT(5,0,10,80, 3,0) ],
               'Termlog after scrollrect' );

   $win->scrollrect( Tickit::Rect->new( top => 20, left => 0, lines => 1, cols => 80 ),
                     0, 1 );

   is_termlog( [ SETBG(undef),
                 SCROLLRECT(20,0,1,80, 0,1) ],
               'Termlog after scrollrect rightward' );

   $win->scrollrect( Tickit::Rect->new( top => 21, left => 10, lines => 1, cols => 70 ),
                     0, -1 );
   flush_tickit;

   is_termlog( [ SETBG(undef),
                 SCROLLRECT(21,10,1,70, 0,-1) ],
               'Termlog after scrollrect leftward not fullwidth' );
}

# Scrolling region exposure
{
   my @exposed_rects;
   $win->bind_event( expose => sub { push @exposed_rects, $_[2]->rect } );

   $win->scroll( 1, 0 );
   flush_tickit;

   is_deeply( \@exposed_rects,
              [ Tickit::Rect->new( top => 24, bottom => 25, left => 0, right => 80 ) ],
              'Exposed area after ->scroll downward' );
   undef @exposed_rects;

   $win->scroll( -1, 0 );
   flush_tickit;

   is_deeply( \@exposed_rects,
              [ Tickit::Rect->new( top => 0, bottom => 1, left => 0, right => 80 ) ],
              'Exposed area after ->scroll upward' );
   undef @exposed_rects;

   $win->scroll( 0, 1 );
   flush_tickit;

   is_deeply( \@exposed_rects,
              [ Tickit::Rect->new( top => 0, bottom => 25, left => 79, right => 80 ) ],
              'Exposed area after ->scroll rightward' );
   undef @exposed_rects;

   $win->scroll( 0, -1 );
   flush_tickit;

   is_deeply( \@exposed_rects,
              [ Tickit::Rect->new( top => 0, bottom => 25, left => 0, right => 1 ) ],
              'Exposed area after ->scroll leftward' );
   undef @exposed_rects;

   # Test that ->scroll updates pending damage

   $win->expose( Tickit::Rect->new( top => 10, bottom => 12, left => 0, right => 80 ) );
   $win->scroll( 2, 0 );
   flush_tickit;

   is_deeply( \@exposed_rects,
              [ Tickit::Rect->new( top => 8, bottom => 10, left => 0, right => 80 ),
                Tickit::Rect->new( top => 23, bottom => 25, left => 0, right => 80 ) ],
              'Damage area updated after ->scroll' );

   drain_termlog;
}

# geometry change event
{
   my $geom_changed = 0;
   $win->bind_event( geomchange => sub { $geom_changed++ } );

   is( $geom_changed, 0, '$reshaped is 0 before term resize' );

   resize_term( 30, 100 );

   is( $win->lines, 30, '$win->lines is 30 after term resize' );
   is( $win->cols, 100, '$win->cols is 100 after term resize' );

   is( $geom_changed, 1, '$reshaped is 1 after term resize' );
}

is_refcount( $win, 1, '$win has refcount 1 before EOF' );

done_testing;