Skip to content

Commit 082ba05

Browse files
tests: refactor closure tests to account for new indent style
1 parent ae6b098 commit 082ba05

10 files changed

+177
-63
lines changed

tests/source/closure.rs renamed to tests/source/closure_block_style.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// rustfmt-indent_style: Block
12
// rustfmt-normalize_comments: true
23
// Closures
34

@@ -211,3 +212,15 @@ fn issue2262() {
211212
slave: None,
212213
})?;
213214
}
215+
216+
fn issue_3865() {
217+
{
218+
let write_status = |status: &mut Vec<ansi_term::ANSIString>,
219+
diff: &Diff,
220+
heading: &str,
221+
color: &Style,
222+
show_hints: bool,
223+
hints: &[&str]|-> Option<bool> { Some(true) };}
224+
let baz = |foo: bool| -> Option<bool> { Some(true) };
225+
let write_status = |status: &mut Vec<ansi_term::ANSIString>,diff: &Diff,heading: &str,color: &Style,| -> Option<bool> { Some(true) };
226+
}

tests/source/closure_block_style_comma.rs

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/source/closure_block_style_no_comma.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// rustfmt-indent_style: Block
22
// rustfmt-trailing_comma: Never
3-
// rustfmt-version: Two
43

54
fn foo() {
65
{

tests/source/closure_visual_style.rs

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// rustfmt-indent_style: Visual
2-
// rustfmt-version: Two
2+
// rustfmt-normalize_comments: true
33

44
fn foo() {
55
{
@@ -15,3 +15,56 @@ fn bar() {
1515
let write_status = |status: &mut Vec<ansi_term::ANSIString>,diff: &Diff,heading: &str,color: &Style,| -> Option<bool> { Some(true) };
1616
let baz = |foo: bool| -> Option<bool> { Some(true) };
1717
}
18+
19+
fn main() {
20+
let square = ( |i: i32 | i * i );
21+
22+
let commented = |// first
23+
a, // argument
24+
// second
25+
b: WithType, // argument
26+
// ignored
27+
_| {
28+
(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb)
29+
};
30+
31+
let commented2 = |/* first */ a /*argument*/, /* second*/ b: WithType /* argument*/, /* ignored */ _ |
32+
(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb);
33+
34+
let block_body = move |xxxxxxxxxxxxxxxxxxxxxxxxxxxxx, ref yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy| {
35+
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx + yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
36+
};
37+
38+
let loooooooooooooong_name = |field| {
39+
// format comments.
40+
if field.node.attrs.len() > 0 { field.node.attrs[0].span.lo()
41+
} else {
42+
field.span.lo()
43+
}};
44+
45+
let unblock_me = |trivial| {
46+
closure()
47+
};
48+
49+
let empty = |arg| {};
50+
51+
let simple = |arg| { /* comment formatting */ foo(arg) };
52+
53+
let test = | | { do_something(); do_something_else(); };
54+
55+
let arg_test = |big_argument_name, test123| looooooooooooooooooong_function_naaaaaaaaaaaaaaaaame();
56+
57+
let arg_test = |big_argument_name, test123| {looooooooooooooooooong_function_naaaaaaaaaaaaaaaaame()};
58+
59+
let simple_closure = move || -> () {};
60+
61+
let closure = |input: Ty| -> Option<String> {
62+
foo()
63+
};
64+
65+
let closure_with_return_type = |aaaaaaaaaaaaaaaaaaaaaaarg1, aaaaaaaaaaaaaaaaaaaaaaarg2| -> Strong { "sup".to_owned() };
66+
67+
|arg1, arg2, _, _, arg3, arg4| { let temp = arg4 + arg3;
68+
arg2 * arg1 - temp };
69+
70+
}

tests/target/closure.rs renamed to tests/target/closure_block_style.rs

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
1+
// rustfmt-indent_style: Block
12
// rustfmt-normalize_comments: true
23
// Closures
34

45
fn main() {
56
let square = (|i: i32| i * i);
67

7-
let commented = |// first
8-
a, // argument
9-
// second
10-
b: WithType, // argument
11-
// ignored
12-
_| {
8+
let commented = |
9+
// first
10+
a, // argument
11+
// second
12+
b: WithType, // argument
13+
// ignored
14+
_,
15+
| {
1316
(
1417
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
1518
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
1619
)
1720
};
1821

19-
let block_body = move |xxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
20-
ref yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy| {
21-
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx + yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
22-
};
22+
let block_body = move |
23+
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
24+
ref yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
25+
| { xxxxxxxxxxxxxxxxxxxxxxxxxxxxx + yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy };
2326

2427
let loooooooooooooong_name = |field| {
2528
// format comments.
@@ -248,3 +251,23 @@ fn issue2262() {
248251
slave: None,
249252
})?;
250253
}
254+
255+
fn issue_3865() {
256+
{
257+
let write_status = |
258+
status: &mut Vec<ansi_term::ANSIString>,
259+
diff: &Diff,
260+
heading: &str,
261+
color: &Style,
262+
show_hints: bool,
263+
hints: &[&str],
264+
| -> Option<bool> { Some(true) };
265+
}
266+
let baz = |foo: bool| -> Option<bool> { Some(true) };
267+
let write_status = |
268+
status: &mut Vec<ansi_term::ANSIString>,
269+
diff: &Diff,
270+
heading: &str,
271+
color: &Style,
272+
| -> Option<bool> { Some(true) };
273+
}

tests/target/closure_block_style_comma.rs

Lines changed: 0 additions & 25 deletions
This file was deleted.

tests/target/closure_block_style_no_comma.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// rustfmt-indent_style: Block
22
// rustfmt-trailing_comma: Never
3-
// rustfmt-version: Two
43

54
fn foo() {
65
{

tests/target/closure_visual_style.rs

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// rustfmt-indent_style: Visual
2-
// rustfmt-version: Two
2+
// rustfmt-normalize_comments: true
33

44
fn foo() {
55
{
@@ -21,3 +21,70 @@ fn bar() {
2121
-> Option<bool> { Some(true) };
2222
let baz = |foo: bool| -> Option<bool> { Some(true) };
2323
}
24+
25+
fn main() {
26+
let square = (|i: i32| i * i);
27+
28+
let commented = |// first
29+
a, // argument
30+
// second
31+
b: WithType, // argument
32+
// ignored
33+
_| {
34+
(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb)
35+
};
36+
37+
let commented2 =
38+
|// first
39+
a, // argument
40+
// second
41+
b: WithType, // argument
42+
// ignored
43+
_| (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb);
44+
45+
let block_body = move |xxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
46+
ref yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy| {
47+
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx + yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
48+
};
49+
50+
let loooooooooooooong_name = |field| {
51+
// format comments.
52+
if field.node.attrs.len() > 0 {
53+
field.node.attrs[0].span.lo()
54+
} else {
55+
field.span.lo()
56+
}
57+
};
58+
59+
let unblock_me = |trivial| closure();
60+
61+
let empty = |arg| {};
62+
63+
let simple = |arg| {
64+
// comment formatting
65+
foo(arg)
66+
};
67+
68+
let test = || {
69+
do_something();
70+
do_something_else();
71+
};
72+
73+
let arg_test =
74+
|big_argument_name, test123| looooooooooooooooooong_function_naaaaaaaaaaaaaaaaame();
75+
76+
let arg_test =
77+
|big_argument_name, test123| looooooooooooooooooong_function_naaaaaaaaaaaaaaaaame();
78+
79+
let simple_closure = move || -> () {};
80+
81+
let closure = |input: Ty| -> Option<String> { foo() };
82+
83+
let closure_with_return_type =
84+
|aaaaaaaaaaaaaaaaaaaaaaarg1, aaaaaaaaaaaaaaaaaaaaaaarg2| -> Strong { "sup".to_owned() };
85+
86+
|arg1, arg2, _, _, arg3, arg4| {
87+
let temp = arg4 + arg3;
88+
arg2 * arg1 - temp
89+
};
90+
}

tests/target/fn-param-attributes.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ impl MutStruct {
2828
}
2929

3030
fn main() {
31-
let c = |#[allow(C)] a: u32,
32-
#[cfg(something)] b: i32,
33-
#[cfg_attr(something, cfg(nothing))]
34-
#[deny(C)]
35-
c: i32| {};
31+
let c = |
32+
#[allow(C)] a: u32,
33+
#[cfg(something)] b: i32,
34+
#[cfg_attr(something, cfg(nothing))]
35+
#[deny(C)]
36+
c: i32,
37+
| {};
3638
let _ = c(1, 2);
3739
}
3840

tests/target/mulit-file.rs renamed to tests/target/multi-file.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// crash.
33

44
#[cfg(all(foo))]
5-
#[path = "closure.rs"]
5+
#[path = "closure_block_style.rs"]
66
pub mod imp;
77

88
#[cfg(all(bar))]
9-
#[path = "closure.rs"]
9+
#[path = "closure_block_style.rs"]
1010
pub mod imp;

0 commit comments

Comments
 (0)