Upgrade to Module-Build-0.2802
[p5sagit/p5-mst-13.2.git] / lib / Term / ANSIColor / t / basic.t
1 #!/usr/bin/perl
2 # $Id: basic.t 55 2006-06-22 17:56:02Z eagle $
3 #
4 # t/basic.t -- Test suite for the Term::ANSIColor Perl module.
5
6 ##############################################################################
7 # Ensure module can be loaded
8 ##############################################################################
9
10 BEGIN { $| = 1; print "1..16\n" }
11 END   { print "not ok 1\n" unless $loaded }
12 delete $ENV{ANSI_COLORS_DISABLED};
13 use Term::ANSIColor qw(:constants color colored uncolor);
14 $loaded = 1;
15 print "ok 1\n";
16
17 ##############################################################################
18 # Test suite
19 ##############################################################################
20
21 # Test simple color attributes.
22 if (color ('blue on_green', 'bold') eq "\e[34;42;1m") {
23     print "ok 2\n";
24 } else {
25     print "not ok 2\n";
26 }
27
28 # Test colored.
29 if (colored ("testing", 'blue', 'bold') eq "\e[34;1mtesting\e[0m") {
30     print "ok 3\n";
31 } else {
32     print "not ok 3\n";
33 }
34
35 # Test the constants.
36 if (BLUE BOLD "testing" eq "\e[34m\e[1mtesting") {
37     print "ok 4\n";
38 } else {
39     print "not ok 4\n";
40 }
41
42 # Test AUTORESET.
43 $Term::ANSIColor::AUTORESET = 1;
44 if (BLUE BOLD "testing" eq "\e[34m\e[1mtesting\e[0m\e[0m") {
45     print "ok 5\n";
46 } else {
47     print "not ok 5\n";
48 }
49
50 # Test EACHLINE.
51 $Term::ANSIColor::EACHLINE = "\n";
52 if (colored ("test\n\ntest", 'bold')
53     eq "\e[1mtest\e[0m\n\n\e[1mtest\e[0m") {
54     print "ok 6\n";
55 } else {
56     print colored ("test\n\ntest", 'bold'), "\n";
57     print "not ok 6\n";
58 }
59
60 # Test EACHLINE with multiple trailing delimiters.
61 $Term::ANSIColor::EACHLINE = "\r\n";
62 if (colored ("test\ntest\r\r\n\r\n", 'bold')
63     eq "\e[1mtest\ntest\r\e[0m\r\n\r\n") {
64     print "ok 7\n";
65 } else {
66     print "not ok 7\n";
67 }
68
69 # Test the array ref form.
70 $Term::ANSIColor::EACHLINE = "\n";
71 if (colored (['bold', 'on_green'], "test\n", "\n", "test")
72     eq "\e[1;42mtest\e[0m\n\n\e[1;42mtest\e[0m") {
73     print "ok 8\n";
74 } else {
75     print colored (['bold', 'on_green'], "test\n", "\n", "test");
76     print "not ok 8\n";
77 }
78
79 # Test uncolor.
80 my @names = uncolor ('1;42', "\e[m", '', "\e[0m");
81 if (join ('|', @names) eq 'bold|on_green|clear') {
82     print "ok 9\n";
83 } else {
84     print join ('|', @names), "\n";
85     print "not ok 9\n";
86 }
87
88 # Test ANSI_COLORS_DISABLED.
89 $ENV{ANSI_COLORS_DISABLED} = 1;
90 if (color ('blue') eq '') {
91     print "ok 10\n";
92 } else {
93     print "not ok 10\n";
94 }
95 if (colored ('testing', 'blue', 'on_red') eq 'testing') {
96     print "ok 11\n";
97 } else {
98     print "not ok 11\n";
99 }
100 if (GREEN 'testing' eq 'testing') {
101     print "ok 12\n";
102 } else {
103     print "not ok 12\n";
104 }
105 delete $ENV{ANSI_COLORS_DISABLED};
106
107 # Make sure DARK is exported.  This was omitted in versions prior to 1.07.
108 if (DARK "testing" eq "\e[2mtesting\e[0m") {
109     print "ok 13\n";
110 } else {
111     print "not ok 13\n";
112 }
113
114 # Test colored with 0 and EACHLINE.
115 $Term::ANSIColor::EACHLINE = "\n";
116 if (colored ('0', 'blue', 'bold') eq "\e[34;1m0\e[0m") {
117     print "ok 14\n";
118 } else {
119     print "not ok 14\n";
120 }
121 if (colored ("0\n0\n\n", 'blue', 'bold')
122     eq "\e[34;1m0\e[0m\n\e[34;1m0\e[0m\n\n") {
123     print "ok 15\n";
124 } else {
125     print "not ok 15\n";
126 }
127
128 # Test colored with the empty string and EACHLINE.
129 if (colored ('', 'blue', 'bold') eq '') {
130     print "ok 16\n";
131 } else {
132     print "not ok 16\n";
133 }