Upgrade to ANSIColor-1.11
[p5sagit/p5-mst-13.2.git] / lib / Term / ANSIColor / t / basic.t
CommitLineData
2e589669 1#!/usr/bin/perl
cd07961b 2# $Id: basic.t 55 2006-06-22 17:56:02Z eagle $
2e589669 3#
cd07961b 4# t/basic.t -- Test suite for the Term::ANSIColor Perl module.
e3e5e1ea 5
51da1d85 6##############################################################################
e3e5e1ea 7# Ensure module can be loaded
51da1d85 8##############################################################################
e3e5e1ea 9
51da1d85 10BEGIN { $| = 1; print "1..16\n" }
e3e5e1ea 11END { print "not ok 1\n" unless $loaded }
110e9fb0 12delete $ENV{ANSI_COLORS_DISABLED};
13use Term::ANSIColor qw(:constants color colored uncolor);
e3e5e1ea 14$loaded = 1;
15print "ok 1\n";
16
51da1d85 17##############################################################################
e3e5e1ea 18# Test suite
51da1d85 19##############################################################################
e3e5e1ea 20
21# Test simple color attributes.
22if (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.
29if (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.
36if (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;
44if (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";
52if (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";
62if (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}
f63addff 68
69# Test the array ref form.
70$Term::ANSIColor::EACHLINE = "\n";
71if (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}
110e9fb0 78
79# Test uncolor.
80my @names = uncolor ('1;42', "\e[m", '', "\e[0m");
81if (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;
92c7d2a2 90if (color ('blue') eq '') {
110e9fb0 91 print "ok 10\n";
92} else {
93 print "not ok 10\n";
94}
92c7d2a2 95if (colored ('testing', 'blue', 'on_red') eq 'testing') {
110e9fb0 96 print "ok 11\n";
97} else {
98 print "not ok 11\n";
99}
100if (GREEN 'testing' eq 'testing') {
101 print "ok 12\n";
102} else {
103 print "not ok 12\n";
104}
2e589669 105delete $ENV{ANSI_COLORS_DISABLED};
106
107# Make sure DARK is exported. This was omitted in versions prior to 1.07.
108if (DARK "testing" eq "\e[2mtesting\e[0m") {
109 print "ok 13\n";
110} else {
111 print "not ok 13\n";
112}
51da1d85 113
114# Test colored with 0 and EACHLINE.
115$Term::ANSIColor::EACHLINE = "\n";
116if (colored ('0', 'blue', 'bold') eq "\e[34;1m0\e[0m") {
117 print "ok 14\n";
118} else {
119 print "not ok 14\n";
120}
121if (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.
129if (colored ('', 'blue', 'bold') eq '') {
130 print "ok 16\n";
131} else {
132 print "not ok 16\n";
133}