Skip to content

Commit

Permalink
Fix a bug that an unexpected newline is inserted when formatting `fun…
Browse files Browse the repository at this point in the history
… () -> ?assertMatch(..., ...) end.`.
  • Loading branch information
sile committed Sep 15, 2024
1 parent fc155a1 commit 043dc45
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
10 changes: 5 additions & 5 deletions efmt_core/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,16 @@ impl Formatter {
return;
}

if self.skipping {
self.pending_blank = Some(Blank::Newline(n));
if self.single_line_mode {
self.write_space();
return;
}
self.pending_blank = None;

if self.single_line_mode {
self.write_space();
if self.skipping {
self.pending_blank = Some(Blank::Newline(n));
return;
}
self.pending_blank = None;

let indent = self.cancel_last_spaces();
for c in self.buf.chars().rev() {
Expand Down
9 changes: 7 additions & 2 deletions efmt_core/src/items/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,15 +618,20 @@ mod tests {

#[test]
fn assert_match() {
let texts = [indoc::indoc! {"
let texts = [
indoc::indoc! {"
foo() ->
?assertMatch(ok when true, Value),
?assertNotMatch([A, B, C]
when is_binary(B) andalso
is_integer(C),
Value),
ok.
"}];
"},
indoc::indoc! {"
foo() -> fun() -> ?assertMatch(ok, Value) end.
"},
];
for text in texts {
crate::assert_format!(text, Module);
}
Expand Down

0 comments on commit 043dc45

Please sign in to comment.