@@ -107,6 +107,7 @@ fn apply_directive(string: ColoredString, directive: &str) -> ColoredString {
107
107
#[ cfg( test) ]
108
108
mod tests {
109
109
use super :: fmt;
110
+ use figment:: Jail ;
110
111
111
112
macro_rules! make_test {
112
113
( $( $name: ident: $styles: expr => $prefix: expr, $suffix: expr, ) * ) => {
@@ -131,16 +132,38 @@ mod tests {
131
132
test_fmt_applies_bright_text_color: & [ "bright_blue" ] => "\x1b [94m" , "\x1b [0m" ,
132
133
test_fmt_ignores_invalid_text_color: & [ "invalid" ] => "" , "" ,
133
134
134
- test_fmt_applies_rgb_text_color: & [ "rgb(77,77,77)" ] => "\x1b [38;2;77;77;77m" , "\x1b [0m" ,
135
- test_fmt_ignores_out_of_bounds_rgb_text_color: & [ "rgb(256,256,256)" ] => "" , "" ,
136
-
137
135
test_fmt_applies_regular_background_color: & [ "bg:blue" ] => "\x1b [44m" , "\x1b [0m" ,
138
136
test_fmt_applies_bright_background_color: & [ "bg:bright_blue" ] => "\x1b [104m" , "\x1b [0m" ,
139
137
test_fmt_ignores_invalid_background_color: & [ "bg:invalid" ] => "" , "" ,
140
138
141
- test_fmt_applies_rgb_background_color: & [ "bg:rgb(77,77,77)" ] => "\x1b [48;2;77;77;77m" , "\x1b [0m" ,
142
- test_fmt_ignores_out_of_bounds_rgb_background_color: & [ "bg:rgb(256,256,256)" ] => "" , "" ,
143
-
144
139
test_fmt_handles_clear_directive: & [ "bold" , "italic" , "clear" ] => "" , "" , // no prefix, no suffix
145
140
) ;
141
+
142
+ macro_rules! make_env_test {
143
+ ( $( $name: ident: $colorterm: expr, $styles: expr => $prefix: expr, $suffix: expr, ) * ) => {
144
+ $(
145
+ #[ test]
146
+ fn $name( ) {
147
+ colored:: control:: set_override( true ) ; // needed when running tests in CLion
148
+ Jail :: expect_with( |jail| {
149
+ jail. set_env( "COLORTERM" , $colorterm) ;
150
+ let text = fmt( "Hello, World!" , $styles) ;
151
+ assert_eq!( text, format!( "{}{}{}" , $prefix, "Hello, World!" , $suffix) ) ;
152
+ Ok ( ( ) )
153
+ } )
154
+ }
155
+ ) *
156
+ } ;
157
+ }
158
+
159
+ make_env_test ! (
160
+ test_fmt_applies_rgb_text_color_truecolor: "truecolor" , & [ "rgb(77,77,77)" ] => "\x1b [38;2;77;77;77m" , "\x1b [0m" ,
161
+ test_fmt_applies_rgb_text_color_ansi: "ansi" , & [ "rgb(77,77,77)" ] => "\x1b [90m" , "\x1b [0m" ,
162
+ test_fmt_applies_rgb_background_color_truecolor: "truecolor" , & [ "bg:rgb(77,77,77)" ] => "\x1b [48;2;77;77;77m" , "\x1b [0m" ,
163
+ test_fmt_applies_rgb_background_color_ansi: "ansi" , & [ "bg:rgb(77,77,77)" ] => "\x1b [100m" , "\x1b [0m" ,
164
+ test_fmt_ignores_out_of_bounds_rgb_text_color_truecolor: "truecolor" , & [ "rgb(256,256,256)" ] => "" , "" ,
165
+ test_fmt_ignores_out_of_bounds_rgb_text_color_ansi: "ansi" , & [ "rgb(256,256,256)" ] => "" , "" ,
166
+ test_fmt_ignores_out_of_bounds_rgb_background_color_truecolor: "truecolor" , & [ "bg:rgb(256,256,256)" ] => "" , "" ,
167
+ test_fmt_ignores_out_of_bounds_rgb_background_color_ansi: "ansi" , & [ "bg:rgb(256,256,256)" ] => "" , "" ,
168
+ ) ;
146
169
}
0 commit comments