mirror of
https://github.com/servo/servo.git
synced 2025-08-24 14:48:21 +01:00
style: Unbox a bunch of color properties.
This builds on https://github.com/servo/rust-cssparser/pull/118.
This commit is contained in:
parent
e394334739
commit
0c102e2350
37 changed files with 185 additions and 195 deletions
|
@ -6,31 +6,45 @@ use cssparser::{Color, RGBA};
|
|||
use style::properties::animated_properties::Interpolate;
|
||||
|
||||
#[test]
|
||||
fn test_rgba_color_interepolation() {
|
||||
assert_eq!(Color::RGBA(RGBA { red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0 }).interpolate(
|
||||
&Color::RGBA(RGBA { red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0 }), 1.0).unwrap(),
|
||||
Color::RGBA(RGBA { red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0 }));
|
||||
fn test_rgba_color_interepolation_preserves_transparent() {
|
||||
assert_eq!(Color::RGBA(RGBA::transparent())
|
||||
.interpolate(&Color::RGBA(RGBA::transparent()), 0.5).unwrap(),
|
||||
Color::RGBA(RGBA::transparent()));
|
||||
}
|
||||
|
||||
assert_eq!(Color::RGBA(RGBA { red: 1.0, green: 0.0, blue: 0.0, alpha: 0.6 }).interpolate(
|
||||
&Color::RGBA(RGBA { red: 0.0, green: 1.0, blue: 0.0, alpha: 0.4 }), 0.5).unwrap(),
|
||||
Color::RGBA(RGBA { red: 0.6, green: 0.4, blue: 0.0, alpha: 0.5 }));
|
||||
#[test]
|
||||
fn test_rgba_color_interepolation_alpha() {
|
||||
assert_eq!(Color::RGBA(RGBA::new(200, 0, 0, 100))
|
||||
.interpolate(&Color::RGBA(RGBA::new(0, 200, 0, 200)), 0.5).unwrap(),
|
||||
Color::RGBA(RGBA::new(66, 133, 0, 150)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rgba_color_interepolation_out_of_range_1() {
|
||||
// Some cubic-bezier functions produce values that are out of range [0, 1].
|
||||
// Unclamped cases.
|
||||
assert_eq!(Color::RGBA(RGBA { red: 0.3, green: 0.0, blue: 0.0, alpha: 0.4 }).interpolate(
|
||||
&Color::RGBA(RGBA { red: 0.0, green: 1.0, blue: 0.0, alpha: 0.6 }), -0.5).unwrap(),
|
||||
Color::RGBA(RGBA { red: 0.6, green: 0.0, blue: 0.0, alpha: 0.3 }));
|
||||
|
||||
assert_eq!(Color::RGBA(RGBA { red: 1.0, green: 0.0, blue: 0.0, alpha: 0.6 }).interpolate(
|
||||
&Color::RGBA(RGBA { red: 0.0, green: 0.3, blue: 0.0, alpha: 0.4 }), 1.5).unwrap(),
|
||||
Color::RGBA(RGBA { red: 0.0, green: 0.6, blue: 0.0, alpha: 0.3 }));
|
||||
|
||||
// Clamped cases.
|
||||
assert_eq!(Color::RGBA(RGBA { red: 1.0, green: 0.0, blue: 0.0, alpha: 0.8 }).interpolate(
|
||||
&Color::RGBA(RGBA { red: 0.0, green: 1.0, blue: 0.0, alpha: 0.2 }), -0.5).unwrap(),
|
||||
Color::RGBA(RGBA { red: 1.0, green: 0.0, blue: 0.0, alpha: 1.0 }));
|
||||
|
||||
assert_eq!(Color::RGBA(RGBA { red: 1.0, green: 0.0, blue: 0.0, alpha: 0.8 }).interpolate(
|
||||
&Color::RGBA(RGBA { red: 0.0, green: 1.0, blue: 0.0, alpha: 0.2 }), 1.5).unwrap(),
|
||||
Color::RGBA(RGBA { red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0 }));
|
||||
assert_eq!(Color::RGBA(RGBA::from_floats(0.3, 0.0, 0.0, 0.4)).interpolate(
|
||||
&Color::RGBA(RGBA::from_floats(0.0, 1.0, 0.0, 0.6)), -0.5).unwrap(),
|
||||
Color::RGBA(RGBA::new(152, 0, 0, 76)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rgba_color_interepolation_out_of_range_2() {
|
||||
assert_eq!(Color::RGBA(RGBA::from_floats(1.0, 0.0, 0.0, 0.6)).interpolate(
|
||||
&Color::RGBA(RGBA::from_floats(0.0, 0.3, 0.0, 0.4)), 1.5).unwrap(),
|
||||
Color::RGBA(RGBA::new(0, 152, 0, 76)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rgba_color_interepolation_out_of_range_clamped_1() {
|
||||
assert_eq!(Color::RGBA(RGBA::from_floats(1.0, 0.0, 0.0, 0.8)).interpolate(
|
||||
&Color::RGBA(RGBA::from_floats(0.0, 1.0, 0.0, 0.2)), -0.5).unwrap(),
|
||||
Color::RGBA(RGBA::from_floats(1.0, 0.0, 0.0, 1.0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rgba_color_interepolation_out_of_range_clamped_2() {
|
||||
assert_eq!(Color::RGBA(RGBA::from_floats(1.0, 0.0, 0.0, 0.8)).interpolate(
|
||||
&Color::RGBA(RGBA::from_floats(0.0, 1.0, 0.0, 0.2)), 1.5).unwrap(),
|
||||
Color::RGBA(RGBA::from_floats(0.0, 0.0, 0.0, 0.0)));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue