From dbf699a991ab18e0ceb57beff95f630c9ef82901 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Thu, 2 Apr 2020 18:16:59 -0400 Subject: [PATCH] handle empty list separators in join --- src/builtin/list.rs | 10 ++++++---- tests/list.rs | 5 +++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/builtin/list.rs b/src/builtin/list.rs index fa67373..2de3e5b 100644 --- a/src/builtin/list.rs +++ b/src/builtin/list.rs @@ -151,9 +151,9 @@ pub(crate) fn register(f: &mut HashMap) { Value::List(v, sep, brackets) => (v, sep, brackets), v => (vec![v], ListSeparator::Space, Brackets::None), }; - let list2 = match arg!(args, 1, "list2") { - Value::List(v, ..) => v, - v => vec![v], + let (list2, sep2) = match arg!(args, 1, "list2") { + Value::List(v, sep, ..) => (v, sep), + v => (vec![v], ListSeparator::Space), }; let sep = match arg!( args, @@ -164,6 +164,8 @@ pub(crate) fn register(f: &mut HashMap) { "auto" => { if list1.len() < 2 && list2.len() < 2 { ListSeparator::Space + } else if list1.is_empty() { + sep2 } else { sep1 } @@ -174,7 +176,7 @@ pub(crate) fn register(f: &mut HashMap) { return Err("$separator: Must be \"space\", \"comma\", or \"auto\".".into()) } }, - _ => return Err("$separator: Must be \"space\", \"comma\", or \"auto\".".into()), + v => return Err(format!("$separator: {} is not a string.", v).into()), }; let brackets = match arg!( diff --git a/tests/list.rs b/tests/list.rs index 6f6ddaa..4d6387b 100644 --- a/tests/list.rs +++ b/tests/list.rs @@ -207,6 +207,11 @@ test!( "a {\n color: join(a b, c, $bracketed: afhsihsdhsdkhsd);\n}\n", "a {\n color: [a b c];\n}\n" ); +test!( + join_empty_first_takes_second_list_separator, + "a {\n color: join((), (a, b, c));\n}\n", + "a {\n color: a, b, c;\n}\n" +); test!(bracketed_ident, "a {\n color: [a];\n}\n"); test!(bracketed_space_list, "a {\n color: [a b];\n}\n"); test!(bracketed_comma_list, "a {\n color: [a, b];\n}\n");