mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-22 16:30:04 +03:00
List formatting basics
This commit is contained in:
parent
db524062ed
commit
b6086a0b0f
@ -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),
|
||||
}
|
||||
}
|
||||
|
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user