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