diff --git a/src/builtin/color/hsl.rs b/src/builtin/color/hsl.rs index d064aad..b1982f6 100644 --- a/src/builtin/color/hsl.rs +++ b/src/builtin/color/hsl.rs @@ -8,20 +8,16 @@ use crate::value::{Number, Value}; pub(crate) fn register(f: &mut BTreeMap) { decl!(f "hsl", |args, _| { let hue = match arg!(args, 0, "hue").eval() { - Value::Dimension(n, Unit::None) - | Value::Dimension(n, Unit::Percent) - | Value::Dimension(n, Unit::Deg) => n, - _ => todo!("expected either unitless or % number for alpha"), + Value::Dimension(n, _) => n, + _ => todo!("$hue: ____ is not a number."), }; let saturation = match arg!(args, 1, "saturation").eval() { - Value::Dimension(n, Unit::None) - | Value::Dimension(n, Unit::Percent) => n / Number::from(100), - _ => todo!("expected either unitless or % number for alpha"), + Value::Dimension(n, _) => n / Number::from(100), + _ => todo!("$saturation: ____ is not a number."), }; let luminance = match arg!(args, 2, "luminance").eval() { - Value::Dimension(n, Unit::None) - | Value::Dimension(n, Unit::Percent) => n / Number::from(100), - _ => todo!("expected either unitless or % number for alpha"), + Value::Dimension(n, _) => n / Number::from(100), + _ => todo!("$luminance: ____ is not a number."), }; let alpha = match arg!(args, 3, "alpha"=Value::Dimension(Number::from(1), Unit::None)) { Value::Dimension(n, Unit::None) => n, @@ -32,25 +28,21 @@ pub(crate) fn register(f: &mut BTreeMap) { }); decl!(f "hsla", |args, _| { let hue = match arg!(args, 0, "hue").eval() { - Value::Dimension(n, Unit::None) - | Value::Dimension(n, Unit::Percent) - | Value::Dimension(n, Unit::Deg) => n, - _ => todo!("expected either unitless or % number for alpha"), + Value::Dimension(n, _) => n, + _ => todo!("$hue: ____ is not a number."), }; let saturation = match arg!(args, 1, "saturation").eval() { - Value::Dimension(n, Unit::None) - | Value::Dimension(n, Unit::Percent) => n / Number::from(100), - _ => todo!("expected either unitless or % number for alpha"), + Value::Dimension(n, _) => n / Number::from(100), + _ => todo!("$saturation: ____ is not a number."), }; let luminance = match arg!(args, 2, "luminance").eval() { - Value::Dimension(n, Unit::None) - | Value::Dimension(n, Unit::Percent) => n / Number::from(100), - _ => todo!("expected either unitless or % number for alpha"), + Value::Dimension(n, _) => n / Number::from(100), + _ => todo!("$luminance: ____ is not a number."), }; let alpha = match arg!(args, 3, "alpha").eval() { Value::Dimension(n, Unit::None) => n, Value::Dimension(n, Unit::Percent) => n / Number::from(100), - _ => todo!("expected either unitless or % number for alpha"), + _ => todo!("$alpha: Expected ____ to have no units or \"%\"."), }; Ok(Value::Color(Color::from_hsla(hue, saturation, luminance, alpha))) }); diff --git a/tests/color.rs b/tests/color.rs index f01c922..d697e36 100644 --- a/tests/color.rs +++ b/tests/color.rs @@ -133,6 +133,11 @@ test!( "a {\n color: hsla(193, 67%, 99, .6);\n}\n", "a {\n color: rgba(251, 253, 254, 0.6);\n}\n" ); +test!( + hsl_doesnt_care_about_units, + "a {\n color: hsl(193deg, 67foo, 99%);\n}\n", + "a {\n color: #fbfdfe;\n}\n" +); test!( hsl_named, "a {\n color: hsl($hue: 193, $saturation: 67%, $luminance: 99);\n}\n",