use crate::color::color_triplet::ColorTriplet;
use crate::terminal_bg::{is_dark_background, parse_osc11_response, ConsoleBackground};
#[test]
fn test_parse_osc11_black_bel() {
let result = parse_osc11_response("\x1b]11;rgb:0000/0000/0000\x07");
assert_eq!(result, Some(ColorTriplet::new(0, 0, 0)));
}
#[test]
fn test_parse_osc11_white_bel() {
let result = parse_osc11_response("\x1b]11;rgb:ffff/ffff/ffff\x07");
assert_eq!(result, Some(ColorTriplet::new(255, 255, 255)));
}
#[test]
fn test_parse_osc11_white_st() {
let result = parse_osc11_response("\x1b]11;rgb:ffff/ffff/ffff\x1b\\");
assert_eq!(result, Some(ColorTriplet::new(255, 255, 255)));
}
#[test]
fn test_parse_osc11_2digit_hex() {
let result = parse_osc11_response("\x1b]11;rgb:ff/ff/ff\x07");
assert_eq!(result, Some(ColorTriplet::new(255, 255, 255)));
}
#[test]
fn test_parse_osc11_1digit_hex() {
let result = parse_osc11_response("\x1b]11;rgb:f/f/f\x07");
assert_eq!(result, Some(ColorTriplet::new(255, 255, 255)));
}
#[test]
fn test_parse_osc11_midrange() {
let result = parse_osc11_response("\x1b]11;rgb:8080/8080/8080\x07");
assert_eq!(result, Some(ColorTriplet::new(128, 128, 128)));
}
#[test]
fn test_parse_osc11_no_prefix_returns_none() {
assert_eq!(parse_osc11_response("rgb:ffff/ffff/ffff"), None);
}
#[test]
fn test_parse_osc11_wrong_osc_number_returns_none() {
assert_eq!(parse_osc11_response("\x1b]10;rgb:ffff/ffff/ffff\x07"), None);
}
#[test]
fn test_parse_osc11_missing_channels_returns_none() {
assert_eq!(parse_osc11_response("\x1b]11;rgb:\x07"), None);
}
#[test]
fn test_parse_osc11_non_hex_returns_none() {
assert_eq!(parse_osc11_response("\x1b]11;rgb:zzzz/zzzz/zzzz\x07"), None);
}
#[test]
fn test_parse_osc11_empty_returns_none() {
assert_eq!(parse_osc11_response(""), None);
}
#[test]
fn test_is_dark_background_black() {
assert!(is_dark_background(ColorTriplet::new(0, 0, 0)));
}
#[test]
fn test_is_dark_background_white() {
assert!(!is_dark_background(ColorTriplet::new(255, 255, 255)));
}
#[test]
fn test_is_dark_background_mid_dark_grey() {
assert!(is_dark_background(ColorTriplet::new(118, 118, 118)));
}
#[test]
fn test_is_dark_background_light_grey() {
assert!(!is_dark_background(ColorTriplet::new(200, 200, 200)));
}
#[test]
fn test_console_background_enum_variants_exist() {
let _dark = ConsoleBackground::Dark;
let _light = ConsoleBackground::Light;
let _unknown = ConsoleBackground::Unknown;
assert_ne!(ConsoleBackground::Dark, ConsoleBackground::Light);
assert_ne!(ConsoleBackground::Dark, ConsoleBackground::Unknown);
assert_ne!(ConsoleBackground::Light, ConsoleBackground::Unknown);
}