Skip to content

Commit 48df8f8

Browse files
committed
Add test for width heuristics
1 parent 31ce8ee commit 48df8f8

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

src/config/config_type.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ macro_rules! create_config {
130130
pub fn $i(&mut self, value: $ty) {
131131
(self.0).$i.2 = value;
132132
match stringify!($i) {
133-
"use_small_heuristics" => self.0.set_heuristics(),
133+
"max_width" | "use_small_heuristics" => self.0.set_heuristics(),
134134
"license_template_path" => self.0.set_license_template(),
135135
&_ => (),
136136
}
@@ -292,7 +292,7 @@ macro_rules! create_config {
292292
}
293293

294294
match key {
295-
"use_small_heuristics" => self.set_heuristics(),
295+
"max_width" | "use_small_heuristics" => self.set_heuristics(),
296296
"license_template_path" => self.set_license_template(),
297297
&_ => (),
298298
}

tests/source/width-heuristics.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// rustfmt-max_width: 120
2+
3+
// elems on multiple lines for max_width 100, but same line for max_width 120
4+
fn foo(e: Enum) {
5+
match e {
6+
Enum::Var {
7+
elem1,
8+
elem2,
9+
elem3,
10+
} => {
11+
return;
12+
}
13+
}
14+
}
15+
16+
// elems not on same line for either max_width 100 or 120
17+
fn bar(e: Enum) {
18+
match e {
19+
Enum::Var {
20+
elem1,
21+
elem2,
22+
elem3,
23+
elem4,
24+
} => {
25+
return;
26+
}
27+
}
28+
}

tests/target/width-heuristics.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// rustfmt-max_width: 120
2+
3+
// elems on multiple lines for max_width 100, but same line for max_width 120
4+
fn foo(e: Enum) {
5+
match e {
6+
Enum::Var { elem1, elem2, elem3 } => {
7+
return;
8+
}
9+
}
10+
}
11+
12+
// elems not on same line for either max_width 100 or 120
13+
fn bar(e: Enum) {
14+
match e {
15+
Enum::Var {
16+
elem1,
17+
elem2,
18+
elem3,
19+
elem4,
20+
} => {
21+
return;
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)