Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | # Test suite for the Term::ANSIColor Perl module. Before `make install' is |
2 | # performed this script should be runnable with `make test'. After `make | |
3 | # install' it should work as `perl test.pl'. | |
4 | ||
5 | ############################################################################ | |
6 | # Ensure module can be loaded | |
7 | ############################################################################ | |
8 | ||
9 | BEGIN { $| = 1; print "1..12\n" } | |
10 | END { print "not ok 1\n" unless $loaded } | |
11 | delete $ENV{ANSI_COLORS_DISABLED}; | |
12 | use Term::ANSIColor qw(:constants color colored uncolor); | |
13 | $loaded = 1; | |
14 | print "ok 1\n"; | |
15 | ||
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') == '') { | |
91 | print "ok 10\n"; | |
92 | } else { | |
93 | print "not ok 10\n"; | |
94 | } | |
95 | if (colored ('testing', 'blue', 'on_red') == '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 | } |