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