]>
git.refcnt.org Git - colorize.git/blob - t/merge.t
6 use constant true
=> 1;
7 use constant false
=> 0;
9 use Colorize
::Common
':defaults';
10 use File
::Temp
qw(tmpnam);
13 # sequence, buffer sizes
15 [ "\e[30m", [ 1..4 ] ],
16 [ "\e[31m", [ 1..4 ] ],
17 [ "\e[32m", [ 1..4 ] ],
18 [ "\e[33m", [ 1..4 ] ],
19 [ "\e[34m", [ 1..4 ] ],
20 [ "\e[35m", [ 1..4 ] ],
21 [ "\e[36m", [ 1..4 ] ],
22 [ "\e[37m", [ 1..4 ] ],
23 [ "\e[39m", [ 1..4 ] ],
24 [ "\e[1;30m", [ 1..6 ] ],
25 [ "\e[1;31m", [ 1..6 ] ],
26 [ "\e[1;32m", [ 1..6 ] ],
27 [ "\e[1;33m", [ 1..6 ] ],
28 [ "\e[1;34m", [ 1..6 ] ],
29 [ "\e[1;35m", [ 1..6 ] ],
30 [ "\e[1;36m", [ 1..6 ] ],
31 [ "\e[1;37m", [ 1..6 ] ],
32 [ "\e[1;39m", [ 1..6 ] ],
33 [ "\e[40m", [ 1..4 ] ],
34 [ "\e[41m", [ 1..4 ] ],
35 [ "\e[42m", [ 1..4 ] ],
36 [ "\e[43m", [ 1..4 ] ],
37 [ "\e[44m", [ 1..4 ] ],
38 [ "\e[45m", [ 1..4 ] ],
39 [ "\e[46m", [ 1..4 ] ],
40 [ "\e[47m", [ 1..4 ] ],
41 [ "\e[49m", [ 1..4 ] ],
42 [ "\e[0m", [ 1..3 ] ],
44 [ "\e[;;m", [ 1..4 ] ],
45 [ "\e[123456m", [ 1 ] ], # tightly coupled to ALLOC_COMPLETE_PART_LINE
47 # sequence, buffer size
49 [ "\e30m", 1 ], # missing bracket
50 [ "\e[am", 2 ], # not a digit nor ; nor m
85 # sequence, buffer size
92 foreach (@merge_success) {
95 $tests += @merge_fail;
104 return true
if exists $programs{$buf_size};
105 my $program = tmpnam
();
106 return false
unless system("$compiler -DTEST -DTEST_MERGE_PART_LINE -DBUF_SIZE=$buf_size -o $program $source") == 0;
107 $programs{$buf_size} = $program;
108 return true
; # compiling succeeded
113 my ($sequence, $buf_size) = @_;
114 my $substr = substr($sequence, 0, $buf_size);
115 $substr =~ s/^\e/ESC/;
116 $sequence =~ s/^\e/ESC/;
117 return "$sequence: $substr";
120 my $compiling_failed_msg = 'compiling failed (merge part line)';
122 plan tests
=> $tests;
124 foreach my $test (@merge_success) {
125 foreach my $buf_size (@
{$test->[1]}) {
127 skip
$compiling_failed_msg, 1 unless $compile->($buf_size);
128 ok
(qx(printf %s "$test->[0]" | $programs{$buf_size} --clean
) eq $test->[0], 'merge success: ' . $test_name->($test->[0], $buf_size));
132 foreach my $test (@merge_fail) {
133 my $buf_size = $test->[1];
135 skip
$compiling_failed_msg, 1 unless $compile->($buf_size);
136 ok
(qx(printf %s "$test->[0]" | $programs{$buf_size} --clean
) eq substr($test->[0], 0, $buf_size), 'merge fail: ' . $test_name->($test->[0], $buf_size));
139 foreach my $test (@buffer) {
140 my $buf_size = length($test) - 1;
142 skip
$compiling_failed_msg, 1 unless $compile->($buf_size);
143 ok
(qx(printf %s "$test" | $programs{$buf_size} --clean
) eq substr($test, 0, $buf_size), 'buffer: ' . $test_name->($test, $buf_size));
146 foreach my $test (@pushback) {
147 my $buf_size = $test->[1];
149 my $program = tmpnam
();
150 skip
$compiling_failed_msg, 1 unless system("$compiler -DTEST -DBUF_SIZE=$buf_size -o $program $source") == 0;
151 ok
(qx(printf %s "$test->[0]" | $program --clean
) eq $test->[0], 'pushback: ' . $test_name->($test->[0], $buf_size));
156 unlink $programs{$_} foreach keys %programs;