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