test: adjust formatter tests after latest tweaks

This commit is contained in:
rvcas 2023-05-25 17:37:53 -04:00
parent 151db8d4ae
commit a44b5e1a77
No known key found for this signature in database
GPG Key ID: C09B64E263F7D68C
2 changed files with 25 additions and 50 deletions

View File

@ -1459,7 +1459,6 @@ impl<'comments> Formatter<'comments> {
fn clause<'a>(&mut self, clause: &'a UntypedClause, index: u32) -> Document<'a> { fn clause<'a>(&mut self, clause: &'a UntypedClause, index: u32) -> Document<'a> {
let space_before = self.pop_empty_lines(clause.location.start); let space_before = self.pop_empty_lines(clause.location.start);
let after_position = clause.location.end;
let clause_doc = join( let clause_doc = join(
clause.patterns.iter().map(|p| self.pattern(p)), clause.patterns.iter().map(|p| self.pattern(p)),
" | ".to_doc(), " | ".to_doc(),
@ -1469,9 +1468,6 @@ impl<'comments> Formatter<'comments> {
Some(guard) => clause_doc.append(" if ").append(self.clause_guard(guard)), Some(guard) => clause_doc.append(" if ").append(self.clause_guard(guard)),
}; };
// Remove any unused empty lines within the clause
self.pop_empty_lines(after_position);
if index == 0 { if index == 0 {
clause_doc clause_doc
} else if space_before { } else if space_before {

View File

@ -138,6 +138,7 @@ fn test_format_when() {
bar() bar()
14 14
} }
False -> False ->
@ -155,8 +156,8 @@ fn test_format_when() {
14 14
} }
False ->
42 False -> 42
} }
} }
"#}; "#};
@ -216,8 +217,7 @@ fn test_format_nested_when_if() {
when xs is { when xs is {
[] -> [] ->
[] []
[_x, ..rest] -> [_x, ..rest] -> drop(rest, n - 1)
drop(rest, n - 1)
} }
} }
} }
@ -246,18 +246,14 @@ fn test_format_nested_when() {
let expected = indoc! {r#" let expected = indoc! {r#"
fn foo() { fn foo() {
when a is { when a is {
None -> None -> "foo"
"foo"
Some(b) -> Some(b) ->
when b is { when b is {
None -> None -> "foo"
"foo"
Some(c) -> Some(c) ->
when c is { when c is {
None -> None -> "foo"
"foo" Some(_) -> "foo"
Some(_) ->
"foo"
} }
} }
} }
@ -416,10 +412,8 @@ fn test_nested_function_calls() {
), ),
), ),
when output.datum is { when output.datum is {
InlineDatum(_) -> InlineDatum(_) -> True
True _ -> error @"expected inline datum"
_ ->
error @"expected inline datum"
}, },
] ]
|> list.and |> list.and
@ -468,10 +462,8 @@ fn format_trace_todo_error() {
fn foo_3() { fn foo_3() {
when x is { when x is {
Foo -> Foo -> True
True _ -> error
_ ->
error
} }
} }
@ -594,24 +586,18 @@ fn test_newline_module_comments() {
#[test] #[test]
fn test_bytearray_literals() { fn test_bytearray_literals() {
let src = indoc! {r#" let src = indoc! {r#"
const foo_const_array = const foo_const_array = #[102, 111, 111]
#[102, 111, 111]
const foo_const_hex = const foo_const_hex = #"666f6f"
#"666f6f"
const foo_const_utf8 = const foo_const_utf8 = "foo"
"foo"
fn foo() { fn foo() {
let foo_const_array = let foo_const_array = #[102, 111, 111]
#[102, 111, 111]
let foo_const_hex = let foo_const_hex = #"666f6f"
#"666f6f"
let foo_const_utf8 = let foo_const_utf8 = "foo"
"foo"
} }
"#}; "#};
@ -621,12 +607,10 @@ fn test_bytearray_literals() {
#[test] #[test]
fn test_string_literal() { fn test_string_literal() {
let src = indoc! {r#" let src = indoc! {r#"
const foo_const: String = const foo_const: String = @"foo"
@"foo"
fn foo() { fn foo() {
let foo_var: String = let foo_var: String = @"foo"
@"foo"
} }
"#}; "#};
@ -791,16 +775,11 @@ fn match_record() {
let src = indoc! { r#" let src = indoc! { r#"
fn foo() { fn foo() {
when bar is { when bar is {
Bar { a, b, c } -> Bar { a, b, c } -> Void
Void Bar { a, .. } -> Void
Bar { a, .. } -> Bar { .. } -> Void
Void Bar(a, b, c) -> Void
Bar { .. } -> Bar(..) -> Void
Void
Bar(a, b, c) ->
Void
Bar(..) ->
Void
} }
} }
"#}; "#};