diff --git a/src/fmt/expr.rs b/src/fmt/expr.rs index d6aa509572..0ee15c89ed 100644 --- a/src/fmt/expr.rs +++ b/src/fmt/expr.rs @@ -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), } } diff --git a/tests/test_format.rs b/tests/test_format.rs index 1ff5e0b1dd..ea5e185261 100644 --- a/tests/test_format.rs +++ b/tests/test_format.rs @@ -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]