1 #![allow(unused_imports)]
2 
3 extern crate ansi_term;
4 extern crate colored;
5 
6 use ansi_term::*;
7 use colored::*;
8 
9 macro_rules! test_simple_color {
10     ($string:expr, $colored_name:ident, $ansi_term_name:ident) => {
11         #[test]
12         fn $colored_name() {
13             let s = format!("{} {}", $string, stringify!($colored_name));
14             assert_eq!(
15                 s.$colored_name().to_string(),
16                 Colour::$ansi_term_name.paint(s).to_string()
17             )
18         }
19     };
20 }
21 
22 mod compat_colors {
23     use super::ansi_term::*;
24     use super::colored::*;
25 
26     test_simple_color!("test string", black, Black);
27     test_simple_color!("test string", red, Red);
28     test_simple_color!("test string", green, Green);
29     test_simple_color!("test string", yellow, Yellow);
30     test_simple_color!("test string", blue, Blue);
31     test_simple_color!("test string", magenta, Purple);
32     test_simple_color!("test string", cyan, Cyan);
33     test_simple_color!("test string", white, White);
34 }
35 
36 macro_rules! test_simple_style {
37     ($string:expr, $style:ident) => {
38         #[test]
39         fn $style() {
40             let s = format!("{} {}", $string, stringify!($style));
41             assert_eq!(
42                 s.$style().to_string(),
43                 ansi_term::Style::new().$style().paint(s).to_string()
44             )
45         }
46     };
47 }
48 
49 mod compat_styles {
50     use super::ansi_term;
51     use super::ansi_term::*;
52     use super::colored;
53     use super::colored::*;
54 
55     test_simple_style!("test string", bold);
56     test_simple_style!("test string", dimmed);
57     test_simple_style!("test string", italic);
58     test_simple_style!("test string", underline);
59     test_simple_style!("test string", blink);
60     test_simple_style!("test string", reverse);
61     test_simple_style!("test string", hidden);
62 }
63 
64 macro_rules! test_simple_bgcolor {
65     ($string:expr, $colored_name:ident, $ansi_term_name:ident) => {
66         #[test]
67         fn $colored_name() {
68             let s = format!("{} {}", $string, stringify!($colored_name));
69             assert_eq!(
70                 s.$colored_name().to_string(),
71                 ansi_term::Style::default()
72                     .on(ansi_term::Colour::$ansi_term_name)
73                     .paint(s)
74                     .to_string()
75             )
76         }
77     };
78 }
79 
80 mod compat_bgcolors {
81     use super::ansi_term;
82     use super::ansi_term::*;
83     use super::colored;
84     use super::colored::*;
85 
86     test_simple_bgcolor!("test string", on_black, Black);
87     test_simple_bgcolor!("test string", on_red, Red);
88     test_simple_bgcolor!("test string", on_green, Green);
89     test_simple_bgcolor!("test string", on_yellow, Yellow);
90     test_simple_bgcolor!("test string", on_blue, Blue);
91     test_simple_bgcolor!("test string", on_magenta, Purple);
92     test_simple_bgcolor!("test string", on_cyan, Cyan);
93     test_simple_bgcolor!("test string", on_white, White);
94 }
95 
96 mod compat_complex {
97     use super::ansi_term;
98     use super::ansi_term::*;
99     use super::colored;
100     use super::colored::*;
101 
102     #[test]
complex1()103     fn complex1() {
104         let s = "test string";
105         let ansi = Colour::Red.on(Colour::Black).bold().italic().paint(s);
106         assert_eq!(
107             ansi.to_string(),
108             s.red().bold().italic().on_black().to_string()
109         );
110     }
111 
112     #[test]
complex2()113     fn complex2() {
114         let s = "test string";
115         let ansi = Colour::Green.on(Colour::Yellow).underline().paint(s);
116         assert_eq!(
117             ansi.to_string(),
118             s.green().on_yellow().underline().to_string()
119         );
120     }
121 }
122 
123 mod compat_overrides {
124     use super::ansi_term;
125     use super::ansi_term::*;
126     use super::colored;
127     use super::colored::*;
128 
129     #[test]
overrides1()130     fn overrides1() {
131         let s = "test string";
132         let ansi = Colour::Red.on(Colour::Black).on(Colour::Blue).paint(s);
133         assert_eq!(ansi.to_string(), s.red().on_blue().to_string());
134     }
135 
136     #[test]
overrides2()137     fn overrides2() {
138         let s = "test string";
139         let ansi = Colour::Green.on(Colour::Yellow).paint(s);
140         assert_eq!(
141             ansi.to_string(),
142             s.green().on_yellow().green().on_yellow().to_string()
143         );
144     }
145 }
146