2 # $Id: basic.t 55 2006-06-22 17:56:02Z eagle $
4 # t/basic.t -- Test suite for the Term::ANSIColor Perl module.
6 ##############################################################################
7 # Ensure module can be loaded
8 ##############################################################################
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);
17 ##############################################################################
19 ##############################################################################
21 # Test simple color attributes.
22 if (color ('blue on_green', 'bold') eq "\e[34;42;1m") {
29 if (colored ("testing", 'blue', 'bold') eq "\e[34;1mtesting\e[0m") {
36 if (BLUE BOLD "testing" eq "\e[34m\e[1mtesting") {
43 $Term::ANSIColor::AUTORESET = 1;
44 if (BLUE BOLD "testing" eq "\e[34m\e[1mtesting\e[0m\e[0m") {
51 $Term::ANSIColor::EACHLINE = "\n";
52 if (colored ("test\n\ntest", 'bold')
53 eq "\e[1mtest\e[0m\n\n\e[1mtest\e[0m") {
56 print colored ("test\n\ntest", 'bold'), "\n";
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") {
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") {
75 print colored (['bold', 'on_green'], "test\n", "\n", "test");
80 my @names = uncolor ('1;42', "\e[m", '', "\e[0m");
81 if (join ('|', @names) eq 'bold|on_green|clear') {
84 print join ('|', @names), "\n";
88 # Test ANSI_COLORS_DISABLED.
89 $ENV{ANSI_COLORS_DISABLED} = 1;
90 if (color ('blue') eq '') {
95 if (colored ('testing', 'blue', 'on_red') eq 'testing') {
100 if (GREEN 'testing' eq 'testing') {
105 delete $ENV{ANSI_COLORS_DISABLED};
107 # Make sure DARK is exported. This was omitted in versions prior to 1.07.
108 if (DARK "testing" eq "\e[2mtesting\e[0m") {
114 # Test colored with 0 and EACHLINE.
115 $Term::ANSIColor::EACHLINE = "\n";
116 if (colored ('0', 'blue', 'bold') eq "\e[34;1m0\e[0m") {
121 if (colored ("0\n0\n\n", 'blue', 'bold')
122 eq "\e[34;1m0\e[0m\n\e[34;1m0\e[0m\n\n") {
128 # Test colored with the empty string and EACHLINE.
129 if (colored ('', 'blue', 'bold') eq '') {