--- a/src/display/utils.rs +++ b/src/display/utils.rs @@ -53,166 +53,3 @@ _ => ColorMode::TwoTone, } } - -#[cfg(all(windows, test))] -mod tests { - use crate::display::color_mode::ColorMode; - use crate::display::utils::detect_color_mode; - - #[test] - fn detect_color_mode_windows() { - assert_eq!(detect_color_mode(2), ColorMode::ThreeBit); - } -} - -#[cfg(all(unix, test))] -mod tests { - use crate::display::color_mode::ColorMode; - use crate::display::utils::detect_color_mode; - use std::env::{remove_var, set_var}; - - fn clear_env() { - remove_var("COLORTERM"); - remove_var("VTE_VERSION"); - remove_var("TERM_PROGRAM"); - remove_var("TERM"); - } - - #[test] - fn detect_color_mode_no_env_2_colors() { - clear_env(); - assert_eq!(detect_color_mode(2), ColorMode::TwoTone); - } - - #[test] - fn detect_color_mode_no_env_8_colors() { - clear_env(); - assert_eq!(detect_color_mode(8), ColorMode::ThreeBit); - } - - #[test] - fn detect_color_mode_no_env_less_8_colors() { - clear_env(); - assert_eq!(detect_color_mode(7), ColorMode::TwoTone); - } - - #[test] - fn detect_color_mode_no_env_16_colors() { - clear_env(); - assert_eq!(detect_color_mode(16), ColorMode::FourBit); - } - - #[test] - fn detect_color_mode_no_env_less_16_colors() { - clear_env(); - assert_eq!(detect_color_mode(15), ColorMode::ThreeBit); - } - - #[test] - fn detect_color_mode_no_env_256_colors() { - clear_env(); - assert_eq!(detect_color_mode(256), ColorMode::EightBit); - } - - #[test] - fn detect_color_mode_no_env_less_256_colors() { - clear_env(); - assert_eq!(detect_color_mode(255), ColorMode::FourBit); - } - - #[test] - fn detect_color_mode_no_env_more_256_colors() { - clear_env(); - assert_eq!(detect_color_mode(257), ColorMode::EightBit); - } - - #[test] - fn detect_color_mode_term_env_no_256() { - clear_env(); - set_var("TERM", "XTERM"); - assert_eq!(detect_color_mode(0), ColorMode::TwoTone); - } - - #[test] - fn detect_color_mode_term_env_with_256() { - clear_env(); - set_var("TERM", "XTERM-256"); - assert_eq!(detect_color_mode(0), ColorMode::EightBit); - } - - #[test] - fn detect_color_mode_term_program_env_apple_terminal() { - clear_env(); - set_var("TERM_PROGRAM", "Apple_Terminal"); - assert_eq!(detect_color_mode(0), ColorMode::EightBit); - } - - #[test] - fn detect_color_mode_term_program_env_iterm() { - clear_env(); - set_var("TERM_PROGRAM", "iTerm.app"); - assert_eq!(detect_color_mode(0), ColorMode::EightBit); - } - - #[test] - fn detect_color_mode_term_program_env_other() { - clear_env(); - set_var("TERM_PROGRAM", "other"); - assert_eq!(detect_color_mode(0), ColorMode::TwoTone); - } - - #[test] - fn detect_color_mode_vte_version_0_36_00() { - clear_env(); - set_var("VTE_VERSION", "3600"); - assert_eq!(detect_color_mode(0), ColorMode::TrueColor); - } - - #[test] - fn detect_color_mode_vte_version_greater_0_36_00() { - clear_env(); - set_var("VTE_VERSION", "3601"); - assert_eq!(detect_color_mode(0), ColorMode::TrueColor); - } - - #[test] - fn detect_color_mode_vte_version_less_0_36_00() { - clear_env(); - set_var("VTE_VERSION", "1"); - assert_eq!(detect_color_mode(0), ColorMode::EightBit); - } - - #[test] - fn detect_color_mode_vte_version_0() { - clear_env(); - set_var("VTE_VERSION", "0"); - assert_eq!(detect_color_mode(0), ColorMode::TwoTone); - } - #[test] - fn detect_color_mode_vte_version_invalid() { - clear_env(); - set_var("VTE_VERSION", "invalid"); - assert_eq!(detect_color_mode(0), ColorMode::TwoTone); - } - - #[test] - fn detect_color_mode_colorterm_env_is_truecolor() { - clear_env(); - set_var("COLORTERM", "truecolor"); - assert_eq!(detect_color_mode(0), ColorMode::TrueColor); - } - - #[test] - fn detect_color_mode_colorterm_env_is_24bit() { - clear_env(); - set_var("COLORTERM", "24bit"); - assert_eq!(detect_color_mode(0), ColorMode::TrueColor); - } - - #[test] - fn detect_color_mode_colorterm_env_is_other() { - clear_env(); - set_var("COLORTERM", "other"); - assert_eq!(detect_color_mode(0), ColorMode::TwoTone); - } -}