From 6460c97ef4a4edcec0c928c336b780ec74fb36eb Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Sun, 22 Mar 2020 23:41:02 -0400 Subject: [PATCH] better error messages for zero arg hsl(a) --- src/builtin/color/hsl.rs | 13 ++++++++++++- tests/color.rs | 14 ++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/builtin/color/hsl.rs b/src/builtin/color/hsl.rs index b46fac8..4f4bdc6 100644 --- a/src/builtin/color/hsl.rs +++ b/src/builtin/color/hsl.rs @@ -12,6 +12,10 @@ pub(crate) fn register(f: &mut HashMap) { f.insert( "hsl".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, @@ -86,6 +90,10 @@ pub(crate) fn register(f: &mut HashMap) { f.insert( "hsla".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, @@ -237,7 +245,10 @@ pub(crate) fn register(f: &mut HashMap) { Box::new(|args, _| { max_args!(args, 2); if args.len() == 1 { - return Ok(Value::Ident(format!("saturate({})", arg!(args, 0, "amount")), QuoteKind::None)); + return Ok(Value::Ident( + format!("saturate({})", arg!(args, 0, "amount")), + QuoteKind::None, + )); } let amount = match arg!(args, 1, "amount") { diff --git a/tests/color.rs b/tests/color.rs index 7ec6d7e..2a3a885 100644 --- a/tests/color.rs +++ b/tests/color.rs @@ -128,13 +128,19 @@ test!( ); error!( rgb_no_args, - "a {\n color: rgb();\n}\n", - "Error: Missing argument $channels." + "a {\n color: rgb();\n}\n", "Error: Missing argument $channels." ); error!( rgba_no_args, - "a {\n color: rgba();\n}\n", - "Error: Missing argument $channels." + "a {\n color: rgba();\n}\n", "Error: Missing argument $channels." +); +error!( + hsl_no_args, + "a {\n color: hsl();\n}\n", "Error: Missing argument $channels." +); +error!( + hsla_no_args, + "a {\n color: hsla();\n}\n", "Error: Missing argument $channels." ); test!( hsl_basic,