better error messages for zero arg hsl(a)

This commit is contained in:
ConnorSkees 2020-03-22 23:41:02 -04:00
parent 6aae433d21
commit 6460c97ef4
2 changed files with 22 additions and 5 deletions

View File

@ -12,6 +12,10 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
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<String, Builtin>) {
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<String, Builtin>) {
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") {

View File

@ -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,