use culors::spaces::{Hsl, Rgb};
use culors::{format_hex, format_hex8, format_hsl, format_rgb, parse, Color};
#[test]
fn format_hex_tomato() {
let tomato = parse("tomato").expect("tomato is a CSS named color");
assert_eq!(format_hex(&tomato), "#ff6347");
}
#[test]
fn format_hex8_white_alpha_zero() {
let c = Color::Rgb(Rgb {
r: 1.0,
g: 1.0,
b: 1.0,
alpha: Some(0.0),
});
assert_eq!(format_hex8(&c), "#ffffff00");
}
#[test]
fn format_rgb_hex_with_alpha() {
let c = parse("#f0f0f0f0").expect("8-char hex parses");
assert_eq!(format_rgb(&c), "rgba(240, 240, 240, 0.94)");
}
#[test]
fn format_hsl_named_red() {
let red = parse("red").expect("red is a CSS named color");
assert_eq!(format_hsl(&red), "hsl(0, 100%, 50%)");
}
#[test]
fn format_hsl_decimals_negative_alpha() {
let c = Color::Hsl(Hsl {
h: 30.21,
s: 0.2361,
l: 0.48321,
alpha: Some(-0.2),
});
assert_eq!(format_hsl(&c), "hsla(30.21, 23.61%, 48.32%, 0)");
}
#[test]
fn format_hsl_out_of_range_clamped() {
let c = Color::Hsl(Hsl {
h: 405.0,
s: 1.2,
l: -1.0,
alpha: None,
});
assert_eq!(format_hsl(&c), "hsl(405, 100%, 0%)");
}