From 0aac40441da139246ad59bfccf8249d6cecbc853 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Sun, 16 Feb 2020 12:35:03 -0500 Subject: [PATCH] Put max_args! everywhere --- src/builtin/color/hsl.rs | 11 +++++++++++ src/builtin/color/opacity.rs | 6 ++++++ src/builtin/color/rgb.rs | 4 ++++ 3 files changed, 21 insertions(+) diff --git a/src/builtin/color/hsl.rs b/src/builtin/color/hsl.rs index 1cee31f..85dbfde 100644 --- a/src/builtin/color/hsl.rs +++ b/src/builtin/color/hsl.rs @@ -49,24 +49,28 @@ pub(crate) fn register(f: &mut BTreeMap) { Ok(Value::Color(Color::from_hsla(hue, saturation, luminance, alpha))) }); decl!(f "hue", |args, _| { + max_args!(args, 1); match arg!(args, 0, "color") { Value::Color(c) => Ok(Value::Dimension(c.hue(), Unit::Deg)), v => return Err(format!("$color: {} is not a color.", v).into()), } }); decl!(f "saturation", |args, _| { + max_args!(args, 1); match arg!(args, 0, "color") { Value::Color(c) => Ok(Value::Dimension(c.saturation(), Unit::Percent)), v => return Err(format!("$color: {} is not a color.", v).into()), } }); decl!(f "lightness", |args, _| { + max_args!(args, 1); match arg!(args, 0, "color") { Value::Color(c) => Ok(Value::Dimension(c.lightness(), Unit::Percent)), v => return Err(format!("$color: {} is not a color.", v).into()), } }); decl!(f "adjust-hue", |args, _| { + max_args!(args, 2); let color = match arg!(args, 0, "color").eval() { Value::Color(c) => c, v => return Err(format!("$color: {} is not a color.", v).into()), @@ -78,6 +82,7 @@ pub(crate) fn register(f: &mut BTreeMap) { Ok(Value::Color(color.adjust_hue(degrees))) }); decl!(f "lighten", |args, _| { + max_args!(args, 2); let color = match arg!(args, 0, "color").eval() { Value::Color(c) => c, v => return Err(format!("$color: {} is not a color.", v).into()), @@ -89,6 +94,7 @@ pub(crate) fn register(f: &mut BTreeMap) { Ok(Value::Color(color.lighten(amount))) }); decl!(f "darken", |args, _| { + max_args!(args, 2); let color = match arg!(args, 0, "color").eval() { Value::Color(c) => c, v => return Err(format!("$color: {} is not a color.", v).into()), @@ -100,6 +106,7 @@ pub(crate) fn register(f: &mut BTreeMap) { Ok(Value::Color(color.darken(amount))) }); decl!(f "saturate", |args, _| { + max_args!(args, 2); let color = match arg!(args, 0, "color").eval() { Value::Color(c) => c, v => return Err(format!("$color: {} is not a color.", v).into()), @@ -111,6 +118,7 @@ pub(crate) fn register(f: &mut BTreeMap) { Ok(Value::Color(color.saturate(amount))) }); decl!(f "desaturate", |args, _| { + max_args!(args, 2); let color = match arg!(args, 0, "color").eval() { Value::Color(c) => c, v => return Err(format!("$color: {} is not a color.", v).into()), @@ -122,6 +130,7 @@ pub(crate) fn register(f: &mut BTreeMap) { Ok(Value::Color(color.desaturate(amount))) }); decl!(f "grayscale", |args, _| { + max_args!(args, 1); let color = match arg!(args, 0, "color").eval() { Value::Color(c) => c, v => return Err(format!("$color: {} is not a color.", v).into()), @@ -129,6 +138,7 @@ pub(crate) fn register(f: &mut BTreeMap) { Ok(Value::Color(color.desaturate(Number::from(1)))) }); decl!(f "complement", |args, _| { + max_args!(args, 1); let color = match arg!(args, 0, "color").eval() { Value::Color(c) => c, v => return Err(format!("$color: {} is not a color.", v).into()), @@ -136,6 +146,7 @@ pub(crate) fn register(f: &mut BTreeMap) { Ok(Value::Color(color.complement())) }); 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, _) => n / Number::from(100), v => return Err(format!("$weight: {} is not a number.", v).into()), diff --git a/src/builtin/color/opacity.rs b/src/builtin/color/opacity.rs index 469c7c1..4d5d2cf 100644 --- a/src/builtin/color/opacity.rs +++ b/src/builtin/color/opacity.rs @@ -7,12 +7,14 @@ use crate::value::Value; pub(crate) fn register(f: &mut BTreeMap) { decl!(f "alpha", |args, _| { + max_args!(args, 1); match arg!(args, 0, "color") { Value::Color(c) => Ok(Value::Dimension(c.alpha(), Unit::None)), v => return Err(format!("$color: {} is not a color.", v).into()), } }); decl!(f "opacity", |args, _| { + max_args!(args, 1); match arg!(args, 0, "color") { Value::Color(c) => Ok(Value::Dimension(c.alpha(), Unit::None)), Value::Dimension(num, unit) => Ok(Value::Ident(format!("opacity({}{})", num , unit), QuoteKind::None)), @@ -20,6 +22,7 @@ pub(crate) fn register(f: &mut BTreeMap) { } }); decl!(f "opacify", |args, _| { + max_args!(args, 2); let color = match arg!(args, 0, "color").eval() { Value::Color(c) => c, v => return Err(format!("$color: {} is not a color.", v).into()), @@ -31,6 +34,7 @@ pub(crate) fn register(f: &mut BTreeMap) { Ok(Value::Color(color.fade_in(amount))) }); decl!(f "fade-in", |args, _| { + max_args!(args, 2); let color = match arg!(args, 0, "color").eval() { Value::Color(c) => c, v => return Err(format!("$color: {} is not a color.", v).into()), @@ -42,6 +46,7 @@ pub(crate) fn register(f: &mut BTreeMap) { Ok(Value::Color(color.fade_in(amount))) }); decl!(f "transparentize", |args, _| { + max_args!(args, 2); let color = match arg!(args, 0, "color").eval() { Value::Color(c) => c, v => return Err(format!("$color: {} is not a color.", v).into()), @@ -53,6 +58,7 @@ pub(crate) fn register(f: &mut BTreeMap) { Ok(Value::Color(color.fade_out(amount))) }); decl!(f "fade-out", |args, _| { + max_args!(args, 2); let color = match arg!(args, 0, "color").eval() { Value::Color(c) => c, v => return Err(format!("$color: {} is not a color.", v).into()), diff --git a/src/builtin/color/rgb.rs b/src/builtin/color/rgb.rs index 6c41815..a2a08e6 100644 --- a/src/builtin/color/rgb.rs +++ b/src/builtin/color/rgb.rs @@ -155,24 +155,28 @@ pub(crate) fn register(f: &mut BTreeMap) { } }); decl!(f "red", |args, _| { + max_args!(args, 1); match arg!(args, 0, "color") { Value::Color(c) => Ok(Value::Dimension(c.red(), Unit::None)), v => return Err(format!("$color: {} is not a color.", v).into()), } }); decl!(f "green", |args, _| { + max_args!(args, 1); match arg!(args, 0, "color") { Value::Color(c) => Ok(Value::Dimension(c.green(), Unit::None)), v => return Err(format!("$color: {} is not a color.", v).into()), } }); decl!(f "blue", |args, _| { + max_args!(args, 1); match arg!(args, 0, "color") { Value::Color(c) => Ok(Value::Dimension(c.blue(), Unit::None)), v => return Err(format!("$color: {} is not a color.", v).into()), } }); decl!(f "mix", |args, _| { + max_args!(args, 3); let color1 = match arg!(args, 0, "color1").eval() { Value::Color(c) => c, v => return Err(format!("$color1: {} is not a color.", v).into()),