List formatting basics

This commit is contained in:
Chad Stearns 2019-12-31 02:44:51 -05:00
parent db524062ed
commit b6086a0b0f
2 changed files with 37 additions and 0 deletions

View File

@ -173,6 +173,25 @@ pub fn fmt_expr<'a>(
}
}
}
List(loc_items) => {
buf.push('[');
let mut iter = loc_items.iter().peekable();
while let Some(item) = iter.next() {
buf.push(' ');
fmt_expr(buf, &item.value, indent, false, true);
if iter.peek().is_some() {
buf.push(',');
}
}
if !loc_items.is_empty() {
buf.push(' ');
}
buf.push(']');
}
other => panic!("TODO implement Display for AST variant {:?}", other),
}
}

View File

@ -540,6 +540,24 @@ mod test_format {
));
}
// LIST
#[test]
fn empty_list() {
expr_formats_same("[]");
// expr_formats_to("[ ]", "[]");
}
#[test]
fn one_item_list() {
expr_formats_same(indoc!("[ 4 ] "));
}
#[test]
fn two_item_list() {
expr_formats_same(indoc!("[ 7, 8 ] "));
expr_formats_to(indoc!("[ 7 , 8 ] "), indoc!("[ 7, 8 ] "));
}
// RECORD LITERALS
#[test]