| skipped 122 lines |
123 | 123 | | } |
124 | 124 | | |
125 | 125 | | #[test] |
| 126 | + | #[should_panic] |
| 127 | + | fn hex2rgb_should_panic() { |
| 128 | + | let options = Options::default(); |
| 129 | + | hex2rgb("#", &options); |
| 130 | + | } |
| 131 | + | |
| 132 | + | #[test] |
126 | 133 | | fn hsv2rsv_works() { |
127 | 134 | | let options = Options::default(); |
128 | 135 | | assert_eq!(hsv2rsv(&Hsv::Val(0.0, 0.0, 0.0), &options), Rsv::Val(0.0, 0.0, 0.0)); |
| skipped 34 lines |
163 | 170 | | #[test] |
164 | 171 | | fn color2hex_works() { |
165 | 172 | | let options = Options::default(); |
166 | | - | assert_eq!(color2hex(&Colors::Red, &options), "#ea3223".to_string()); |
167 | | - | assert_eq!(color2hex(&Colors::Rgb(Rgb::Val(255, 0, 0)), &options), "#ff0000".to_string()); |
| 173 | + | assert_eq!(color2hex(&Colors::System, &options), String::from("transparent")); |
| 174 | + | assert_eq!(color2hex(&Colors::Black, &options), String::from("#000000")); |
| 175 | + | assert_eq!(color2hex(&Colors::Red, &options), String::from("#ea3223")); |
| 176 | + | assert_eq!(color2hex(&Colors::Green, &options), String::from("#377d22")); |
| 177 | + | assert_eq!(color2hex(&Colors::Yellow, &options), String::from("#fffd54")); |
| 178 | + | assert_eq!(color2hex(&Colors::Blue, &options), String::from("#0020f5")); |
| 179 | + | assert_eq!(color2hex(&Colors::Magenta, &options), String::from("#ea3df7")); |
| 180 | + | assert_eq!(color2hex(&Colors::Cyan, &options), String::from("#74fbfd")); |
| 181 | + | assert_eq!(color2hex(&Colors::White, &options), String::from("#ffffff")); |
| 182 | + | assert_eq!(color2hex(&Colors::Gray, &options), String::from("#808080")); |
| 183 | + | assert_eq!(color2hex(&Colors::RedBright, &options), String::from("#ee776d")); |
| 184 | + | assert_eq!(color2hex(&Colors::GreenBright, &options), String::from("#8cf57b")); |
| 185 | + | assert_eq!(color2hex(&Colors::YellowBright, &options), String::from("#fffb7f")); |
| 186 | + | assert_eq!(color2hex(&Colors::BlueBright, &options), String::from("#6974f6")); |
| 187 | + | assert_eq!(color2hex(&Colors::MagentaBright, &options), String::from("#ee82f8")); |
| 188 | + | assert_eq!(color2hex(&Colors::CyanBright, &options), String::from("#8dfafd")); |
| 189 | + | |
| 190 | + | assert_eq!(color2hex(&Colors::Rgb(Rgb::Val(255, 0, 0)), &options), String::from("#ff0000")); |
| 191 | + | |
| 192 | + | let candy_color = [ |
| 193 | + | String::from("#ea3223"), |
| 194 | + | String::from("#377d22"), |
| 195 | + | String::from("#fffd54"), |
| 196 | + | String::from("#ea3df7"), |
| 197 | + | String::from("#74fbfd"), |
| 198 | + | String::from("#ee776d"), |
| 199 | + | String::from("#8cf57b"), |
| 200 | + | String::from("#fffb7f"), |
| 201 | + | String::from("#6974f6"), |
| 202 | + | String::from("#ee82f8"), |
| 203 | + | String::from("#8dfafd"), |
| 204 | + | ]; |
| 205 | + | assert!(candy_color.contains(&color2hex(&Colors::Candy, &options))); |
168 | 206 | | } |
169 | 207 | | |
170 | 208 | | #[test] |
171 | 209 | | fn bgcolor2hex_works() { |
172 | 210 | | let options = Options::default(); |
| 211 | + | assert_eq!(bgcolor2hex(&BgColors::Rgb(Rgb::Val(255, 0, 0)), &options), String::from("#ff0000")); |
| 212 | + | |
| 213 | + | assert_eq!(bgcolor2hex(&BgColors::Transparent, &options), "transparent".to_string()); |
| 214 | + | assert_eq!(bgcolor2hex(&BgColors::Black, &options), "#000000".to_string()); |
173 | 215 | | assert_eq!(bgcolor2hex(&BgColors::Red, &options), "#ea3223".to_string()); |
174 | | - | assert_eq!(bgcolor2hex(&BgColors::Rgb(Rgb::Val(255, 0, 0)), &options), "#ff0000".to_string()); |
| 216 | + | assert_eq!(bgcolor2hex(&BgColors::Green, &options), "#377d22".to_string()); |
| 217 | + | assert_eq!(bgcolor2hex(&BgColors::Yellow, &options), "#fffd54".to_string()); |
| 218 | + | assert_eq!(bgcolor2hex(&BgColors::Blue, &options), "#0020f5".to_string()); |
| 219 | + | assert_eq!(bgcolor2hex(&BgColors::Magenta, &options), "#ea3df7".to_string()); |
| 220 | + | assert_eq!(bgcolor2hex(&BgColors::Cyan, &options), "#74fbfd".to_string()); |
| 221 | + | assert_eq!(bgcolor2hex(&BgColors::White, &options), "#ffffff".to_string()); |
| 222 | + | assert_eq!(bgcolor2hex(&BgColors::Gray, &options), "#808080".to_string()); |
| 223 | + | assert_eq!(bgcolor2hex(&BgColors::RedBright, &options), "#ee776d".to_string()); |
| 224 | + | assert_eq!(bgcolor2hex(&BgColors::GreenBright, &options), "#8cf57b".to_string()); |
| 225 | + | assert_eq!(bgcolor2hex(&BgColors::YellowBright, &options), "#fffb7f".to_string()); |
| 226 | + | assert_eq!(bgcolor2hex(&BgColors::BlueBright, &options), "#6974f6".to_string()); |
| 227 | + | assert_eq!(bgcolor2hex(&BgColors::MagentaBright, &options), "#ee82f8".to_string()); |
| 228 | + | assert_eq!(bgcolor2hex(&BgColors::CyanBright, &options), "#8dfafd".to_string()); |
175 | 229 | | } |
176 | 230 | | |
177 | 231 | | #[test] |
| skipped 12 lines |
190 | 244 | | #[test] |
191 | 245 | | fn rgb_u8_2ansi_256_works() { |
192 | 246 | | assert_eq!(rgb_u8_2ansi_256(100, 200, 100), 114); |
193 | | - | assert_eq!(rgb_u8_2ansi_256(255, 255, 255), 16); |
194 | | - | assert_eq!(rgb_u8_2ansi_256(0, 0, 0), 231); |
| 247 | + | assert_eq!(rgb_u8_2ansi_256(255, 255, 255), 231); |
| 248 | + | assert_eq!(rgb_u8_2ansi_256(0, 0, 0), 16); |
195 | 249 | | assert_eq!(rgb_u8_2ansi_256(167, 5, 98), 126); |
196 | 250 | | } |
197 | 251 | | |
| skipped 1 lines |
199 | 253 | | fn rgb2ansi_256_works() { |
200 | 254 | | assert_eq!(rgb2ansi_256(&Rgb::Val(255, 0, 0), ColorLayer::Foreground), "\x1b[38;5;196m".to_string()); |
201 | 255 | | assert_eq!(rgb2ansi_256(&Rgb::Val(255, 255, 0), ColorLayer::Foreground), "\x1b[38;5;226m".to_string()); |
202 | | - | assert_eq!(rgb2ansi_256(&Rgb::Val(255, 255, 255), ColorLayer::Foreground), "\x1b[38;5;16m".to_string()); |
| 256 | + | assert_eq!(rgb2ansi_256(&Rgb::Val(255, 255, 255), ColorLayer::Foreground), "\x1b[38;5;231m".to_string()); |
203 | 257 | | assert_eq!(rgb2ansi_256(&Rgb::Val(157, 5, 98), ColorLayer::Foreground), "\x1b[38;5;126m".to_string()); |
204 | 258 | | |
205 | 259 | | assert_eq!(rgb2ansi_256(&Rgb::Val(255, 0, 0), ColorLayer::Background), "\x1b[48;5;196m".to_string()); |
206 | 260 | | assert_eq!(rgb2ansi_256(&Rgb::Val(255, 255, 0), ColorLayer::Background), "\x1b[48;5;226m".to_string()); |
207 | | - | assert_eq!(rgb2ansi_256(&Rgb::Val(255, 255, 255), ColorLayer::Background), "\x1b[48;5;16m".to_string()); |
| 261 | + | assert_eq!(rgb2ansi_256(&Rgb::Val(255, 255, 255), ColorLayer::Background), "\x1b[48;5;231m".to_string()); |
208 | 262 | | assert_eq!(rgb2ansi_256(&Rgb::Val(157, 5, 98), ColorLayer::Background), "\x1b[48;5;126m".to_string()); |
209 | 263 | | } |
210 | 264 | | |
| skipped 1 lines |
212 | 266 | | fn rgb2ansi_16_works() { |
213 | 267 | | assert_eq!(rgb2ansi_16(&Rgb::Val(255, 0, 0), ColorLayer::Foreground), "\x1b[91m".to_string()); |
214 | 268 | | assert_eq!(rgb2ansi_16(&Rgb::Val(255, 255, 0), ColorLayer::Foreground), "\x1b[93m".to_string()); |
215 | | - | assert_eq!(rgb2ansi_16(&Rgb::Val(255, 255, 255), ColorLayer::Foreground), "\x1b[0m".to_string()); |
| 269 | + | assert_eq!(rgb2ansi_16(&Rgb::Val(255, 255, 255), ColorLayer::Foreground), "\x1b[97m".to_string()); |
216 | 270 | | assert_eq!(rgb2ansi_16(&Rgb::Val(157, 5, 98), ColorLayer::Foreground), "\x1b[31m".to_string()); |
217 | 271 | | |
218 | 272 | | assert_eq!(rgb2ansi_16(&Rgb::Val(255, 0, 0), ColorLayer::Background), "\x1b[101m".to_string()); |
219 | 273 | | assert_eq!(rgb2ansi_16(&Rgb::Val(255, 255, 0), ColorLayer::Background), "\x1b[103m".to_string()); |
220 | | - | assert_eq!(rgb2ansi_16(&Rgb::Val(255, 255, 255), ColorLayer::Background), "\x1b[10m".to_string()); |
| 274 | + | assert_eq!(rgb2ansi_16(&Rgb::Val(255, 255, 255), ColorLayer::Background), "\x1b[107m".to_string()); |
221 | 275 | | assert_eq!(rgb2ansi_16(&Rgb::Val(157, 5, 98), ColorLayer::Background), "\x1b[41m".to_string()); |
222 | 276 | | } |
223 | 277 | | |
| skipped 15 lines |
239 | 293 | | assert_eq!(get_foreground_color(&Colors::Red), (String::from("\x1b[31m"), String::from("\x1b[39m"))); |
240 | 294 | | assert_eq!(get_foreground_color(&Colors::Green), (String::from("\x1b[32m"), String::from("\x1b[39m"))); |
241 | 295 | | assert_eq!(get_foreground_color(&Colors::Blue), (String::from("\x1b[34m"), String::from("\x1b[39m"))); |
| 296 | + | |
| 297 | + | let candy_color = [ |
| 298 | + | String::from("\x1b[31m"), |
| 299 | + | String::from("\x1b[32m"), |
| 300 | + | String::from("\x1b[33m"), |
| 301 | + | String::from("\x1b[35m"), |
| 302 | + | String::from("\x1b[36m"), |
| 303 | + | String::from("\x1b[91m"), |
| 304 | + | String::from("\x1b[92m"), |
| 305 | + | String::from("\x1b[93m"), |
| 306 | + | String::from("\x1b[94m"), |
| 307 | + | String::from("\x1b[95m"), |
| 308 | + | String::from("\x1b[96m"), |
| 309 | + | ]; |
| 310 | + | assert!(candy_color.contains(&get_foreground_color(&Colors::Candy).0)); |
242 | 311 | | }); |
243 | 312 | | } |
244 | 313 | | |
| skipped 261 lines |