]>
git.refcnt.org Git - colorize.git/blob - t/merge.t
fe73c2bfdcef74727b09ecd9daae695c13d2a941
5 use constant true
=> 1;
6 use constant false
=> 0;
8 use File
::Temp
qw(tmpnam);
11 # sequence, buffer sizes
13 [ "\e[30m", [ 1..4 ] ],
14 [ "\e[31m", [ 1..4 ] ],
15 [ "\e[32m", [ 1..4 ] ],
16 [ "\e[33m", [ 1..4 ] ],
17 [ "\e[34m", [ 1..4 ] ],
18 [ "\e[35m", [ 1..4 ] ],
19 [ "\e[36m", [ 1..4 ] ],
20 [ "\e[37m", [ 1..4 ] ],
21 [ "\e[39m", [ 1..4 ] ],
22 [ "\e[1;30m", [ 1..6 ] ],
23 [ "\e[1;31m", [ 1..6 ] ],
24 [ "\e[1;32m", [ 1..6 ] ],
25 [ "\e[1;33m", [ 1..6 ] ],
26 [ "\e[1;34m", [ 1..6 ] ],
27 [ "\e[1;35m", [ 1..6 ] ],
28 [ "\e[1;36m", [ 1..6 ] ],
29 [ "\e[1;37m", [ 1..6 ] ],
30 [ "\e[1;39m", [ 1..6 ] ],
31 [ "\e[40m", [ 1..4 ] ],
32 [ "\e[41m", [ 1..4 ] ],
33 [ "\e[42m", [ 1..4 ] ],
34 [ "\e[43m", [ 1..4 ] ],
35 [ "\e[44m", [ 1..4 ] ],
36 [ "\e[45m", [ 1..4 ] ],
37 [ "\e[46m", [ 1..4 ] ],
38 [ "\e[47m", [ 1..4 ] ],
39 [ "\e[49m", [ 1..4 ] ],
40 [ "\e[0m", [ 1..3 ] ],
42 [ "\e[;;m", [ 1..4 ] ],
44 # sequence, buffer size
46 [ "\e30m", 1 ], # missing bracket
47 [ "\e[am", 2 ], # not a digit nor ; nor m
82 # sequence, buffer size
89 foreach (@merge_success) {
92 $tests += @merge_fail;
96 my $source = 'colorize.c';
102 return true
if exists $programs{$buf_size};
103 my $program = tmpnam
();
104 return false
unless system("gcc -DTEST_MERGE_PART_LINE -DBUF_SIZE=$buf_size -o $program $source") == 0;
105 $programs{$buf_size} = $program;
106 return true
; # compiling succeeded
111 my ($sequence, $buf_size) = @_;
112 my $substr = substr($sequence, 0, $buf_size);
113 $substr =~ s/^\e/ESC/;
114 $sequence =~ s/^\e/ESC/;
115 return "$sequence: $substr";
118 plan tests
=> $tests;
120 foreach my $test (@merge_success) {
121 foreach my $buf_size (@
{$test->[1]}) {
123 skip
'compiling failed (merge part line)', 1 unless $compile->($buf_size);
124 ok
(qx(echo
-n
"$test->[0]" | $programs{$buf_size} --clean
) eq $test->[0], 'merge success: ' . $test_name->($test->[0], $buf_size));
128 foreach my $test (@merge_fail) {
129 my $buf_size = $test->[1];
131 skip
'compiling failed (merge part line)', 1 unless $compile->($buf_size);
132 ok
(qx(echo
-n
"$test->[0]" | $programs{$buf_size} --clean
) eq substr($test->[0], 0, $buf_size), 'merge fail: ' . $test_name->($test->[0], $buf_size));
135 foreach my $test (@buffer) {
136 my $buf_size = length($test) - 1;
138 skip
'compiling failed (merge part line)', 1 unless $compile->($buf_size);
139 ok
(qx(echo
-n
"$test" | $programs{$buf_size} --clean
) eq substr($test, 0, $buf_size), 'buffer: ' . $test_name->($test, $buf_size));
142 foreach my $test (@pushback) {
143 my $buf_size = $test->[1];
145 my $program = tmpnam
();
146 skip
'compiling failed (merge part line)', 1 unless system("gcc -DBUF_SIZE=$buf_size -o $program $source") == 0;
147 ok
(qx(echo
-n
"$test->[0]" | $program --clean
) eq $test->[0], 'pushback: ' . $test_name->($test->[0], $buf_size));
152 unlink $programs{$_} foreach keys %programs;