From 965d151168f3c58c4463ea4fd1eaf220f108c694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Besnier?= Date: Mon, 28 Dec 2020 18:57:45 +0100 Subject: [PATCH] add tag union tests for trailing commas formatting --- compiler/fmt/src/expr.rs | 2 +- compiler/fmt/tests/test_fmt.rs | 62 ++++++++++++++++++++++++++-------- 2 files changed, 48 insertions(+), 16 deletions(-) diff --git a/compiler/fmt/src/expr.rs b/compiler/fmt/src/expr.rs index 623326ac19..1be56ee514 100644 --- a/compiler/fmt/src/expr.rs +++ b/compiler/fmt/src/expr.rs @@ -415,7 +415,7 @@ pub fn fmt_list<'a>( for item in loc_items.iter() { match &item.value { // TODO?? These SpaceAfter/SpaceBefore litany seems overcomplicated - // Can we simplify this? + // Can we simplify this? Or at least move this in a separate function. Expr::SpaceBefore(expr_below, spaces_above_expr) => { newline(buf, item_indent); fmt_comments_only( diff --git a/compiler/fmt/tests/test_fmt.rs b/compiler/fmt/tests/test_fmt.rs index 8b7004fbcb..adcbfd46b7 100644 --- a/compiler/fmt/tests/test_fmt.rs +++ b/compiler/fmt/tests/test_fmt.rs @@ -2452,22 +2452,54 @@ mod test_fmt { )); } - // TODO This raises a parse error: - // NotYetImplemented("TODO the : in this declaration seems outdented") - // #[test] - // fn multiline_tag_union_annotation() { - // expr_formats_same(indoc!( - // r#" - // b : - // [ - // True, - // False, - // ] + #[test] + fn multiline_tag_union_annotation() { + expr_formats_same(indoc!( + r#" + b : + [ + True, + False, + ] - // b - // "# - // )); - // } + b + "# + )); + } + + #[test] + fn multiline_tag_union_annotation_with_final_comment() { + expr_formats_to( + indoc!( + r#" + b : + [ + True, + # comment 1 + False # comment 2 + , + # comment 3 + ] + + b + "# + ), + indoc!( + r#" + b : + [ + True, + # comment 1 + False, + # comment 2 + # comment 3 + ] + + b + "# + ), + ); + } #[test] fn tag_union() {