Skip to content

Commit

Permalink
add test and simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
Febriananda Wida Pramudita authored and ytmimi committed Apr 26, 2024
1 parent 22a4306 commit 3854ce9
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,9 @@ pub(crate) fn rewrite_match(
let inner_attrs_str = if inner_attrs.is_empty() {
String::new()
} else {
shape.indent.block_indent(context.config);
let result = inner_attrs
.rewrite(context, shape)
.map(|s| format!("{}{}\n", nested_indent_str, s))?;
shape.indent.block_unindent(context.config);
result
inner_attrs
.rewrite(context, shape.block_indent(context.config.tab_spaces()))
.map(|s| format!("{}{}\n", nested_indent_str, s))?
};

let open_brace_pos = if inner_attrs.is_empty() {
Expand Down
18 changes: 18 additions & 0 deletions tests/source/issue-6147/expect_changed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pub fn main() {
let a = Some(12)
match a {
#![attr1]
#![attr2]
#![attr3]
_ => None,
}

{
match a {
#![attr1]
#![attr2]
#![attr3]
_ => None,
}
}
}
18 changes: 18 additions & 0 deletions tests/target/issue-6147/expect_changed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pub fn main() {
let a = Some(12)
match a {
#![attr1]
#![attr2]
#![attr3]
_ => None,
}

{
match a {
#![attr1]
#![attr2]
#![attr3]
_ => None,
}
}
}
18 changes: 18 additions & 0 deletions tests/target/issue-6147/expect_not_changed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pub fn main() {
let a = Some(12)
match a {
#![attr1]
#![attr2]
#![attr3]
_ => None,
}

{
match a {
#![attr1]
#![attr2]
#![attr3]
_ => None,
}
}
}

0 comments on commit 3854ce9

Please sign in to comment.