Debian Codegraph @

t/05-uncolor.t

raw symbols SCIP
1 #!/usr/bin/perl
2 use strictscip-perl cpan Term-ExtendedColor 0.504 strict/;
3 use warningsscip-perl cpan Term-ExtendedColor 0.504 warnings/;
4 use Test::Morescip-perl cpan Term-ExtendedColor 0.504 Test/More/ tests => 4;
5 use Term::ExtendedColorscip-perl cpan Term-ExtendedColor 0.504 Term/ExtendedColor/ qw(uncolor get_colors);
6
7 my(@colors, @colors2, @attributes);
8
9 my $j = 0;
10 for(my $i = 0; $i< 17; ++$i) {
11 if($j % 2 == 0) {
12 pushscip-perl cpan Term-ExtendedColor 0.504 main/push().(@colors, "\e[38;5;$i" . 'm' . 'This is in color' . "\e[0m");
13 }
14 else {
15 pushscip-perl cpan Term-ExtendedColor 0.504 main/push().(@colors, "\033[38;5;$i" . 'm' . 'This is in color' . "\033[0m");
16 }
17 $j++;
18 }
19
20 $j = 0;
21 for(my $i = 0; $i<9; ++$i) {
22 if($j % 2 == 0) {
23 pushscip-perl cpan Term-ExtendedColor 0.504 main/push().(@attributes, "\e[$i" . 'm' . 'This is with attributes added' . "\e[0m");
24 }
25 else {
26 pushscip-perl cpan Term-ExtendedColor 0.504 main/push().(@attributes, "\033[$i" . 'm' . 'This is with attributes added' . "\033[0m");
27 }
28 }
29
30 @colors2 = @colors;
31 @colors = uncolorscip-perl cpan Term-ExtendedColor 0.504 Term/ExtendedColor/uncolor().(@colors);
32 @attributes = uncolorscip-perl cpan Term-ExtendedColor 0.504 Term/ExtendedColor/uncolor().(@attributes);
33
34 my $colors = get_colorsscip-perl cpan Term-ExtendedColor 0.504 Term/ExtendedColor/get_colors().();
35
36 #push(@colors, fg('red2', 'foobar'));
37
38 my $fail = 0;
39 for(@colors) {
40 if($_scip-perl cpan Term-ExtendedColor 0.504 main/$_. =~ /\e[38;[\d]+/) {
41 $fail++;
42 }
43 }
44 for(@attributes) {
45 if($_scip-perl cpan Term-ExtendedColor 0.504 main/$_. =~ /\e[48;[\d]+/) {
46 $fail++;
47 }
48 }
49
50 $fail
51 ? failscip-perl cpan Term-ExtendedColor 0.504 main/fail().("uncolor: color esc sequences not parsed correctly ($fail)")
52 : passscip-perl cpan Term-ExtendedColor 0.504 main/pass().("uncolor: color esc sequences parsed correctly")
53 ;
54
55 use Data::Dumperscip-perl cpan Term-ExtendedColor 0.504 Data/Dumper/;
56 $Data::Dumper::Tersescip-perl cpan Term-ExtendedColor 0.504 Data/Dumper/$Terse. = 1;
57 $Data::Dumper::Indentscip-perl cpan Term-ExtendedColor 0.504 Data/Dumper/$Indent. = 1;
58 $Data::Dumper::Useqqscip-perl cpan Term-ExtendedColor 0.504 Data/Dumper/$Useqq. = 1;
59 $Data::Dumper::Deparsescip-perl cpan Term-ExtendedColor 0.504 Data/Dumper/$Deparse. = 1;
60 $Data::Dumper::Quotekeysscip-perl cpan Term-ExtendedColor 0.504 Data/Dumper/$Quotekeys. = 0;
61 $Data::Dumper::Sortkeysscip-perl cpan Term-ExtendedColor 0.504 Data/Dumper/$Sortkeys. = 1;
62
63 my $non_color = Dumper uncolorscip-perl cpan Term-ExtendedColor 0.504 Term/ExtendedColor/uncolor().(
64 "\e[2cNot \e[38;5;100;1mlegal\e[0m color esc sequences\e [0m"
65 );
66
67 $non_color =~ s/^"(.+)"\n$/$1/;
68 isscip-perl cpan Term-ExtendedColor 0.504 main/is().($non_color,
69 '\e[2cNot legal color esc sequences\e [0m',
70 'uncolor does not remove non-color stuff'
71 );
72
73 is_deeplyscip-perl cpan Term-ExtendedColor 0.504 main/is_deeply().( [ uncolorscip-perl cpan Term-ExtendedColor 0.504 Term/ExtendedColor/uncolor().(\@colors2) ], \@colors, "uncolor: passing arrayref as first argument - list context");
74
75 isscip-perl cpan Term-ExtendedColor 0.504 main/is(). ( uncolorscip-perl cpan Term-ExtendedColor 0.504 Term/ExtendedColor/uncolor().(\@colors2), joinscip-perl cpan Term-ExtendedColor 0.504 main/join().('',@colors), "uncolor: passing arrayref as first argument - scalar context");