Parse-ANSIColor-Tiny

 view release on metacpan or  search on metacpan

t/chart.t  view on Meta::CPAN

use strict;
use warnings;
use Test::More tests => 4;
use Test::Differences;

# shortcuts
BEGIN {
  use Parse::ANSIColor::Tiny;
  sub o ($) { 'on_'     . $_[0] }
  sub b ($) { 'bright_' . $_[0] }
  sub bo () { 'bold' }
  eval join '', map { "sub $_ () { '$_' }" } keys %Parse::ANSIColor::Tiny::ATTRIBUTES;
}

is underline, 'underline', 'shortcut works';
is o b cyan, 'on_bright_cyan', 'shortcuts work together';

my $p = new_ok('Parse::ANSIColor::Tiny');

my $chart = do { local $/; <DATA>; };
note $chart;

eq_or_diff $p->parse($chart), [
[[],   " 0\t"], [[         ], '  0 '],  [[             ], '  0 '],  [[], "\t\t 1\t"], [[bo         ], '  1 '],  [[bo             ], '  1 '],
[[], "\n 2\t"], [[dark     ], '  2 '],  [[bo, dark     ], '  2 '],  [[], "\t\t 3\t"], [[           ], '  3 '],  [[bo,            ], '  3 '],
[[], "\n 4\t"], [[underline], '  4 '],  [[bo, underline], '  4 '],  [[], "\t\t 5\t"], [[blink      ], '  5 '],  [[bo, blink      ], '  5 '],
[[], "\n 6\t"], [[         ], '  6 '],  [[bo,          ], '  6 '],  [[], "\t\t 7\t"], [[&reverse   ], '  7 '],  [[bo, &reverse   ], '  7 '],
[[], "\n30\t"], [[black    ], ' 30 '],  [[bo, black    ], ' 30 '],  [[], "\t\t31\t"], [[red        ], ' 31 '],  [[bo, red        ], ' 31 '],
[[], "\n32\t"], [[green    ], ' 32 '],  [[bo, green    ], ' 32 '],  [[], "\t\t33\t"], [[yellow     ], ' 33 '],  [[bo, yellow     ], ' 33 '],
[[], "\n34\t"], [[blue     ], ' 34 '],  [[bo, blue     ], ' 34 '],  [[], "\t\t35\t"], [[magenta    ], ' 35 '],  [[bo, magenta    ], ' 35 '],
[[], "\n36\t"], [[cyan     ], ' 36 '],  [[bo, cyan     ], ' 36 '],  [[], "\t\t37\t"], [[white      ], ' 37 '],  [[bo, white      ], ' 37 '],
[[], "\n40\t"], [[o black  ], ' 40 '],  [[bo, o black  ], ' 40 '],  [[], "\t\t41\t"], [[o red      ], ' 41 '],  [[bo, o red      ], ' 41 '],
[[], "\n42\t"], [[o green  ], ' 42 '],  [[bo, o green  ], ' 42 '],  [[], "\t\t43\t"], [[o yellow   ], ' 43 '],  [[bo, o yellow   ], ' 43 '],
[[], "\n44\t"], [[o blue   ], ' 44 '],  [[bo, o blue   ], ' 44 '],  [[], "\t\t45\t"], [[o magenta  ], ' 45 '],  [[bo, o magenta  ], ' 45 '],
[[], "\n46\t"], [[o cyan   ], ' 46 '],  [[bo, o cyan   ], ' 46 '],  [[], "\t\t47\t"], [[o white    ], ' 47 '],  [[bo, o white    ], ' 47 '],
[[], "\n90\t"], [[b black  ], ' 90 '],  [[bo, b black  ], ' 90 '],  [[], "\t\t91\t"], [[b red      ], ' 91 '],  [[bo, b red      ], ' 91 '],
[[], "\n92\t"], [[b green  ], ' 92 '],  [[bo, b green  ], ' 92 '],  [[], "\t\t93\t"], [[b yellow   ], ' 93 '],  [[bo, b yellow   ], ' 93 '],
[[], "\n94\t"], [[b blue   ], ' 94 '],  [[bo, b blue   ], ' 94 '],  [[], "\t\t95\t"], [[b magenta  ], ' 95 '],  [[bo, b magenta  ], ' 95 '],
[[], "\n96\t"], [[b cyan   ], ' 96 '],  [[bo, b cyan   ], ' 96 '],  [[], "\t\t97\t"], [[b white    ], ' 97 '],  [[bo, b white    ], ' 97 '],
[[], "\n100\t"], [[o b black], ' 100 '], [[bo, o b black], ' 100 '], [[], "\t\t101\t"], [[o b red    ], ' 101 '], [[bo, o b red    ], ' 101 '],
[[], "\n102\t"], [[o b green], ' 102 '], [[bo, o b green], ' 102 '], [[], "\t\t103\t"], [[o b yellow ], ' 103 '], [[bo, o b yellow ], ' 103 '],
[[], "\n104\t"], [[o b blue ], ' 104 '], [[bo, o b blue ], ' 104 '], [[], "\t\t105\t"], [[o b magenta], ' 105 '], [[bo, o b magenta], ' 105 '],
[[], "\n106\t"], [[o b cyan ], ' 106 '], [[bo, o b cyan ], ' 106 '], [[], "\t\t107\t"], [[o b white  ], ' 107 '], [[bo, o b white  ], ' 107 '],
[[], "\n"],
  ],
  'parsed simple color chart';

# cat this file to see the color chart

__DATA__
 0	  0   0 		 1	  1   1 
 2	  2   2 		 3	  3   3 
 4	  4   4 		 5	  5   5 
 6	  6   6 		 7	  7   7 
30	 30  30 		31	 31  31 
32	 32  32 		33	 33  33 
34	 34  34 		35	 35  35 
36	 36  36 		37	 37  37 
40	 40  40 		41	 41  41 
42	 42  42 		43	 43  43 
44	 44  44 		45	 45  45 
46	 46  46 		47	 47  47 
90	 90  90 		91	 91  91 
92	 92  92 		93	 93  93 



( run in 1.866 second using v1.01-cache-2.11-cpan-5a3173703d6 )