Grayscale function behaves differently when given a number

This commit is contained in:
ConnorSkees 2020-02-16 16:11:24 -05:00
parent 96d29f45b8
commit ca0e2d47cb
2 changed files with 10 additions and 0 deletions

View File

@ -2,6 +2,7 @@ use std::collections::BTreeMap;
use super::Builtin;
use crate::color::Color;
use crate::common::QuoteKind;
use crate::units::Unit;
use crate::value::{Number, Value};
@ -133,6 +134,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
max_args!(args, 1);
let color = match arg!(args, 0, "color").eval() {
Value::Color(c) => c,
Value::Dimension(n, u) => return Ok(Value::Ident(format!("grayscale({}{})", n, u), QuoteKind::None)),
v => return Err(format!("$color: {} is not a color.", v).into()),
};
Ok(Value::Color(color.desaturate(Number::from(1))))

View File

@ -391,6 +391,14 @@ test!(
"a {\n color: grayscale(red);\n}\n",
"a {\n color: gray;\n}\n"
);
test!(
grayscale_number,
"a {\n color: grayscale(15%);\n}\n"
);
// test!(
// grayscale_number_casing,
// "a {\n color: grAyscaLe(15%);\n}\n"
// );
test!(
complement,
"a {\n color: complement(red);\n}\n",