handle empty list separators in join
This commit is contained in:
parent
8718673519
commit
dbf699a991
@ -151,9 +151,9 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
||||
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<String, Builtin>) {
|
||||
"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<String, Builtin>) {
|
||||
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!(
|
||||
|
@ -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");
|
||||
|
Loading…
x
Reference in New Issue
Block a user