handle non list separator in join()
This commit is contained in:
parent
31a19b5ecb
commit
e7008cd7e8
@ -147,10 +147,14 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
||||
"join".to_owned(),
|
||||
Box::new(|mut args, _| {
|
||||
max_args!(args, 4);
|
||||
let mut is_first_list = true;
|
||||
let (mut list1, sep1, brackets) = match arg!(args, 0, "list1") {
|
||||
Value::List(v, sep, brackets) => (v, sep, brackets),
|
||||
Value::Map(m) => (m.entries(), ListSeparator::Comma, Brackets::None),
|
||||
v => (vec![v], ListSeparator::Space, Brackets::None),
|
||||
v => {
|
||||
is_first_list = false;
|
||||
(vec![v], ListSeparator::Space, Brackets::None)
|
||||
}
|
||||
};
|
||||
let (list2, sep2) = match arg!(args, 1, "list2") {
|
||||
Value::List(v, sep, ..) => (v, sep),
|
||||
@ -164,7 +168,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
||||
) {
|
||||
Value::Ident(s, ..) => match s.as_str() {
|
||||
"auto" => {
|
||||
if list1.is_empty() {
|
||||
if list1.is_empty() || !is_first_list {
|
||||
sep2
|
||||
} else {
|
||||
sep1
|
||||
|
@ -222,6 +222,11 @@ test!(
|
||||
"a {\n color: join((c: d, e: f), (g: h, i: j));\n}\n",
|
||||
"a {\n color: c d, e f, g h, i j;\n}\n"
|
||||
);
|
||||
test!(
|
||||
join_non_list_first_takes_separator_of_second,
|
||||
"a {\n color: join(c, (d, e));\n}\n",
|
||||
"a {\n color: c, d, e;\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