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