diff --git a/src/args.rs b/src/args.rs index 4dc1e97..93ecfb5 100644 --- a/src/args.rs +++ b/src/args.rs @@ -40,6 +40,10 @@ impl CallArgs { self.0.len() } + pub fn is_empty(&self) -> bool { + self.0.len() == 0 + } + pub fn remove(&mut self, s: &str) -> Option { self.0.remove(s) } diff --git a/src/builtin/color/hsl.rs b/src/builtin/color/hsl.rs index 798a77b..b46fac8 100644 --- a/src/builtin/color/hsl.rs +++ b/src/builtin/color/hsl.rs @@ -236,6 +236,10 @@ pub(crate) fn register(f: &mut HashMap) { "saturate".to_owned(), Box::new(|args, _| { max_args!(args, 2); + if args.len() == 1 { + return Ok(Value::Ident(format!("saturate({})", arg!(args, 0, "amount")), QuoteKind::None)); + } + let amount = match arg!(args, 1, "amount") { Value::Dimension(n, u) => bound!("amount", n, u, 0, 100) / Number::from(100), v => return Err(format!("$amount: {} is not a number.", v).into()), diff --git a/src/builtin/color/rgb.rs b/src/builtin/color/rgb.rs index 67588b5..0478840 100644 --- a/src/builtin/color/rgb.rs +++ b/src/builtin/color/rgb.rs @@ -11,6 +11,10 @@ pub(crate) fn register(f: &mut HashMap) { f.insert( "rgb".to_owned(), Box::new(|args, _| { + if args.is_empty() { + return Err("Missing argument $channels.".into()); + } + if args.len() == 1 { let mut channels = match arg!(args, 0, "channels") { Value::List(v, _) => v, @@ -129,6 +133,10 @@ pub(crate) fn register(f: &mut HashMap) { f.insert( "rgba".to_owned(), Box::new(|args, _| { + if args.is_empty() { + return Err("Missing argument $channels.".into()); + } + if args.len() == 1 { let mut channels = match arg!(args, 0, "channels") { Value::List(v, _) => v, diff --git a/tests/color.rs b/tests/color.rs index a98848b..7ec6d7e 100644 --- a/tests/color.rs +++ b/tests/color.rs @@ -126,6 +126,16 @@ test!( "a {\n color: rgba(7.1%, 20.4%, 33.9%);\n}\n", "a {\n color: #123456;\n}\n" ); +error!( + rgb_no_args, + "a {\n color: rgb();\n}\n", + "Error: Missing argument $channels." +); +error!( + rgba_no_args, + "a {\n color: rgba();\n}\n", + "Error: Missing argument $channels." +); test!( hsl_basic, "a {\n color: hsl(193, 67%, 99);\n}\n", @@ -340,6 +350,11 @@ test!( "a {\n color: saturate($color: hsl(25, 100%, 80%), $amount: 30%);\n}\n", "a {\n color: #ffc499;\n}\n" ); +test!( + saturate_one_arg, + "a {\n color: saturate($amount: 50%);\n}\n", + "a {\n color: saturate(50%);\n}\n" +); test!( saturate_basic, "a {\n color: saturate(hsl(120, 30%, 90%), 20%);\n}\n",