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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
|
#!/usr/bin/perl
use v5.26;
use warnings;
use utf8;
use Test2::V0;
use Tickit::Test 0.12;
use Tickit::Pen;
use Tickit::RenderBuffer;
use Tickit::Widget::Scroller::Item::Text;
my $term = mk_term;
my $item = Tickit::Widget::Scroller::Item::Text->new( "My message here" );
isa_ok( $item, [ "Tickit::Widget::Scroller::Item::Text" ], '$item' );
is( [ $item->chunks ],
[ [ "My message here", 15 ] ],
'$item->chunks' );
is( $item->height_for_width( 80 ), 1, 'height_for_width 80' );
my $rb = Tickit::RenderBuffer->new( lines => $term->lines, cols => $term->cols );
$item->render( $rb, top => 0, firstline => 0, lastline => 0, width => 80, height => 25 );
$rb->flush_to_term( $term );
flush_tickit;
is_termlog( [ GOTO(0,0),
SETPEN,
PRINT("My message here"),
SETBG(undef),
ERASECH(65) ],
'Termlog for render fullwidth' );
is_display( [ [TEXT("My message here")] ],
'Display for render fullwidth' );
$term->clear;
drain_termlog;
{
{
$rb->save;
$rb->clip( Tickit::Rect->new(
top => 0,
left => 0,
lines => 10,
cols => 12,
) );
is( $item->height_for_width( 12 ), 2, 'height_for_width 12' );
$item->render( $rb, top => 0, firstline => 0, lastline => 1, width => 12, height => 10 );
$rb->restore;
}
$rb->flush_to_term( $term );
flush_tickit;
is_termlog( [ GOTO(0,0),
SETPEN,
PRINT("My message "),
SETBG(undef),
ERASECH(1),
GOTO(1,0),
SETPEN,
PRINT("here"),
SETBG(undef),
ERASECH(8) ],
'Termlog for render width 12' );
is_display( [ [TEXT("My message")],
[TEXT("here")] ],
'Display for render width 12' );
my $indenteditem = Tickit::Widget::Scroller::Item::Text->new( "My message here", indent => 4 );
is( $indenteditem->height_for_width( 12 ), 2, 'height_for_width 12 with indent' );
$indenteditem->render( $rb, top => 0, firstline => 0, lastline => 1, width => 12, height => 10 );
$rb->flush_to_term( $term );
flush_tickit;
is_termlog( [ GOTO(0,0),
SETPEN,
PRINT("My message "),
SETBG(undef),
ERASECH(1),
GOTO(1,0),
SETBG(undef),
ERASECH(4,1),
SETPEN,
PRINT("here"),
SETBG(undef),
ERASECH(4) ],
'Termlog for render width 12 with indent' );
is_display( [ [TEXT("My message")],
[TEXT(" here")] ],
'Display for render width 12 with indent' );
}
# Boundary condition in whitespace splitting
{
$term->clear;
drain_termlog;
my $item = Tickit::Widget::Scroller::Item::Text->new( "AAAA BBBB CCCC DDDD" );
is( $item->height_for_width( 9 ), 2, 'height_for_width 2 for splitting boundary' );
$item->render( $rb, top => 0, firstline => 0, lastline => 1, width => 9, height => 2 );
$rb->flush_to_term( $term );
flush_tickit;
is_termlog( [ GOTO(0,0),
SETPEN,
PRINT("AAAA BBBB"),
GOTO(1,0),
SETPEN,
PRINT("CCCC DDDD") ],
'Termlog for render splitting boundary' );
is_display( [ [TEXT("AAAA BBBB")],
[TEXT("CCCC DDDD")] ],
'Display for render splitting boundary' );
}
# Linefeeds
{
$term->clear;
drain_termlog;
my $item = Tickit::Widget::Scroller::Item::Text->new( "Some more text\nwith linefeeds" );
is( [ $item->chunks ],
[ [ "Some more text", 14, linebreak => 1 ],
[ "with linefeeds", 14 ] ],
'$item->chunks with linefeeds' );
is( $item->height_for_width( 80 ), 2, 'height_for_width 2 with linefeeds' );
$item->render( $rb, top => 0, firstline => 0, lastline => 1, width => 80, height => 2 );
$rb->flush_to_term( $term );
flush_tickit;
is_termlog( [ GOTO(0,0),
SETPEN,
PRINT("Some more text"),
SETPEN,
ERASECH(66),
GOTO(1,0),
SETPEN,
PRINT("with linefeeds"),
SETPEN,
ERASECH(66) ],
'Termlog for render with linefeeds' );
is_display( [ [TEXT("Some more text")],
[TEXT("with linefeeds")] ],
'Display for render with linefeeds' );
}
# Odd Unicode
{
$term->clear;
drain_termlog;
my $item = Tickit::Widget::Scroller::Item::Text->new( "(ノಠ益ಠ)ノ彡┻━┻" );
is( [ $item->chunks ],
[ [ "(ノಠ益ಠ)ノ彡┻━┻", 15 ] ],
'$item->chunks with Unicode' );
is( $item->height_for_width( 80 ), 1, 'height_for_width 2 with Unicode' );
$item->render( $rb, top => 0, firstline => 0, lastline => 0, width => 80, height => 1 );
$rb->flush_to_term( $term );
flush_tickit;
is_termlog( [ GOTO(0,0),
SETPEN,
PRINT("(ノಠ益ಠ)ノ彡┻━┻"),
SETPEN,
ERASECH(65) ],
'Termlog for render with Unicode' );
is_display( [ [TEXT("(ノಠ益ಠ)ノ彡┻━┻")] ],
'Display for render with Unicode' );
}
# Non-breaking spaces
{
$term->clear;
drain_termlog;
my $item = Tickit::Widget::Scroller::Item::Text->new( "abcdef 12\x{A0}34" );
is( $item->height_for_width( 11 ), 2, 'height_for_width 2 with NBSP' );
$item->render( $rb, top => 0, firstline => 0, lastline => 1, width => 11, height => 2 );
$rb->flush_to_term( $term );
flush_tickit;
is_termlog( [ GOTO(0,0),
SETPEN,
PRINT("abcdef "),
SETPEN,
ERASECH(4),
GOTO(1,0),
SETPEN,
PRINT("12 34"),
SETPEN,
ERASECH(6) ],
'Termlog for render with NBSP' );
is_display( [ [TEXT("abcdef")],
[TEXT("12 34")] ],
'Display for render with NBSP' );
}
# Empty
{
$term->clear;
drain_termlog;
my $item = Tickit::Widget::Scroller::Item::Text->new( "" );
is( [ $item->chunks ],
[ [ "", 0 ] ],
'$item->chunks for empty string' );
is( $item->height_for_width( 80 ), 1, 'height_for_width 1 for empty string' );
$item->render( $rb, top => 0, firstline => 0, lastline => 0, width => 80, height => 1 );
$rb->flush_to_term( $term );
flush_tickit;
is_termlog( [ GOTO(0,0),
SETPEN,
ERASECH(80) ],
'Termlog for render for empty string' );
is_display( [ ],
'Display for render for empty string' );
}
# With pen
{
$term->clear;
drain_termlog;
my $item = Tickit::Widget::Scroller::Item::Text->new( "Red with green BG",
pen => Tickit::Pen->new( fg => "red", bg => "green" )
);
$item->height_for_width( 80 );
$item->render( $rb, top => 0, firstline => 0, lastline => 0, width => 80, height => 1 );
$rb->flush_to_term( $term );
flush_tickit;
is_termlog( [ GOTO(0,0),
SETPEN(fg=>1,bg=>2),
PRINT("Red with green BG"),
SETPEN(fg=>1,bg=>2),
ERASECH(63) ],
'Termlog for render with pen' );
}
done_testing;
|