From d4dd3606824e0d13812915b3d0907e5a436feb84 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Sun, 16 Feb 2020 17:00:31 -0500 Subject: [PATCH] Handle number passed to invert() --- src/builtin/color/hsl.rs | 4 +++- tests/color.rs | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/builtin/color/hsl.rs b/src/builtin/color/hsl.rs index ff30593..6613f59 100644 --- a/src/builtin/color/hsl.rs +++ b/src/builtin/color/hsl.rs @@ -150,11 +150,13 @@ pub(crate) fn register(f: &mut BTreeMap) { decl!(f "invert", |args, _| { max_args!(args, 2); let weight = match arg!(args, 1, "weight"=Value::Dimension(Number::from(100), Unit::Percent)) { - Value::Dimension(n, u) => bound!("amount", n, u, 0, 100) / Number::from(100), + Value::Dimension(n, u) => bound!("weight", n, u, 0, 100) / Number::from(100), v => return Err(format!("$weight: {} is not a number.", v).into()), }; match arg!(args, 0, "color") { Value::Color(c) => Ok(Value::Color(c.invert(weight))), + Value::Dimension(n, Unit::Percent) => Ok(Value::Ident(format!("invert({}%)", n), QuoteKind::None)), + Value::Dimension(..) => return Err("Only one argument may be passed to the plain-CSS invert() function.".into()), v => return Err(format!("$color: {} is not a color.", v).into()), } }); diff --git a/tests/color.rs b/tests/color.rs index cca2cc1..5cf3bf5 100644 --- a/tests/color.rs +++ b/tests/color.rs @@ -258,6 +258,14 @@ test!( "a {\n color: invert(white);\n}\n", "a {\n color: black;\n}\n" ); +test!( + invert_number, + "a {\n color: invert(10%);\n}\n" +); +// test!( +// invert_number_casing, +// "a {\n color: iNveRt(10%);\n}\n" +// ); test!( invert_weight_percent, "a {\n color: invert(white, 20%);\n}\n",