Commit | Line | Data |
e3e5e1ea |
1 | BEGIN { |
2 | chdir 't' if -d 't'; |
20822f61 |
3 | @INC = '../lib'; |
e3e5e1ea |
4 | } |
5 | |
6 | # Test suite for the Term::ANSIColor Perl module. Before `make install' is |
7 | # performed this script should be runnable with `make test'. After `make |
8 | # install' it should work as `perl test.pl'. |
9 | |
10 | ############################################################################ |
11 | # Ensure module can be loaded |
12 | ############################################################################ |
13 | |
f63addff |
14 | BEGIN { $| = 1; print "1..8\n" } |
e3e5e1ea |
15 | END { print "not ok 1\n" unless $loaded } |
16 | use Term::ANSIColor qw(:constants color colored); |
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 | } |
f63addff |
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 | } |