Skip to content

Commit d2d3712

Browse files
davidBar-Oncalebcartwright
authored andcommitted
Additional test cases
1 parent 155f6ee commit d2d3712

File tree

3 files changed

+272
-2
lines changed

3 files changed

+272
-2
lines changed

src/formatting/lists.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,8 @@ where
461461

462462
let mut formatted_comment = rewrite_post_comment(&mut item_max_width)?;
463463

464-
// Mmultiline comments are not included in a previous "indentation group".
465-
// Each multiline comment is a considered as a separage group.
464+
// Multiline comments are not included in a previous "indentation group".
465+
// Each multiline comment is considered as a separate group.
466466
if formatted_comment.contains('\n') {
467467
item_max_width = None;
468468
formatted_comment = rewrite_post_comment(&mut item_max_width)?;

tests/source/issue-4546.rs

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Basic tests (using vectors) - list multiline post-comment is indented on its own
12
fn main() {
23
let v = [
34
"A", /* item A comment */
@@ -27,3 +28,136 @@ fn main() {
2728
"FFF", /* item F comment */
2829
];
2930
}
31+
32+
// Tests for Struct
33+
pub(crate) struct ListFormatting<'a> {
34+
tactic: DefinitiveListTactic,
35+
separator: &'a str, /* Comment */
36+
trailing_separator: SeparatorTactic, /* Comment */
37+
separator_place: SeparatorPlace, // Comment 1
38+
// Comment 2
39+
shape: Shape, /* Non-expressions, e.g., items, will have a new line at the end of the list.
40+
* Important for comment styles. */
41+
ends_with_newline: bool, // Remove newlines between list elements for expressions.
42+
preserve_newline: bool, // Nested import lists get some special handling for the "Mixed" list type
43+
nested: bool,
44+
// Whether comments should be visually aligned.
45+
align_comments: bool, /* comment */
46+
config: &'a Config,
47+
}
48+
49+
fn main() {
50+
l = ListItem {
51+
pre_comment, /* Comment */
52+
pre_comment_style, /* Multiline comment
53+
* Line 2 */
54+
/* New line comment */
55+
item: if self.inner.peek().is_none() && self.leave_last { /* Comment */
56+
None
57+
} else {
58+
(self.get_item_string)(&item)
59+
},
60+
post_comment, /* Comment */
61+
new_lines, /* Comment */
62+
}
63+
}
64+
65+
// Test for Function parameters
66+
pub(crate) fn new(shape: Shape, config: &'a Config) -> Self {
67+
ListFormatting {
68+
tactic: DefinitiveListTactic::Vertical, /* Comment */
69+
separator: ",", /* comment */
70+
trailing_separator: SeparatorTactic::Never, /* Multiline comment
71+
* second comment line */
72+
separator_place: SeparatorPlace::Back, // A longggggggggggggggggggggggggggggggggggggggggggggggggggg comment
73+
shape,
74+
/* New line comment */
75+
ends_with_newline: true, /* Comment */
76+
preserve_newline: false, /* Comment */
77+
nested: false, /* Comment */
78+
align_comments: true, /* Another Multiline comment
79+
* second comment line */
80+
config, /* Last comment */
81+
}
82+
}
83+
84+
// Test for `where`
85+
impl<'a, T, I, F1, F2, F3> Iterator for ListItems<'a, I, F1, F2, F3>
86+
where
87+
I: Iterator<Item = T>, /* Comment */
88+
F111111111: Fn(&T) -> BytePos, /* Comment */
89+
F2222222: Fn(&T) -> BytePos, /* Multiline comment
90+
* Line 2 */
91+
F3: Fn(&T) -> Option<String>, /* Comment */
92+
{}
93+
94+
// Test for some types of lists
95+
pub(crate) fn itemize_list<'a, T, I, F1, F2, F3>(
96+
snippet_provider: &'a SnippetProvider, /* Comment */
97+
inner: I, /* Comment */
98+
terminator: &'a str, /* Multiline comment
99+
* Line 2 */
100+
separator: &'a str, /* Comment */
101+
get_lo: F1, /* Comment */
102+
get_hi: F2,
103+
get_item_string: F3, /* Comment */
104+
prev_span_end: BytePos, /* Multiline comment
105+
* Line 2 */
106+
next_span_start: BytePos, /* Comment */
107+
leave_last: bool,
108+
) -> ListItems<'a, I, F1, F2, F3>
109+
where
110+
I: Iterator<Item = T>, /* Comment */
111+
F111111111: Fn(&T) -> BytePos, /* Multiline comment
112+
* Line 2 */
113+
F2222222: Fn(&T) -> BytePos,
114+
F3: Fn(&T) -> Option<String>, /* Comment */
115+
{
116+
ListItems {/* Comment to ListItems */
117+
snippet_provider, /* Multiline comment
118+
* Line 2 */
119+
inner: inner.peekable(), /* Another multiline comment
120+
* another Line 2 */
121+
get_lo, /* Comment */
122+
get_hi,
123+
get_item_string,
124+
prev_span_end, /* Comment */
125+
next_span_start,/* Comment */
126+
terminator,
127+
separator, /* Yet another multiline comment
128+
* yet another Line 2 */
129+
leave_last,/* Comment */
130+
}
131+
}
132+
133+
134+
// Tests when comment in the same line of the item will exceed line width
135+
fn main() {
136+
let v = [
137+
"A-Longgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg", /* item A comment */
138+
"BBB", /* item B Longgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg comment */
139+
"CCCCCC", /* item C comment line 1
140+
* item C comment line 2 */
141+
"D-Longggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg", /* item D comment line 1
142+
* item D comment line 2 */
143+
"EEEEE", /* item E comment */
144+
];
145+
}
146+
147+
// Test for nested items
148+
fn main() {
149+
let v1 = [
150+
"GG", /* item G comment line 1
151+
* item G comment line 2 */
152+
"AAAAA", /* item A comment */
153+
[
154+
"BBB", /* item B comment */
155+
"CCCCCC", /* item C comment line 1
156+
* item C comment line 2 */
157+
"D", /* item D comment line 1
158+
* item D comment line 2 */
159+
"E", /* item E comment */
160+
],
161+
"FFF", /* item F comment */
162+
];
163+
}

tests/target/issue-4546.rs

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Basic tests (using vectors) - list multiline post-comment is indented on its own
12
fn main() {
23
let v = [
34
"A", /* item A comment */
@@ -27,3 +28,138 @@ fn main() {
2728
"FFF", /* item F comment */
2829
];
2930
}
31+
32+
// Tests for Struct
33+
pub(crate) struct ListFormatting<'a> {
34+
tactic: DefinitiveListTactic,
35+
separator: &'a str, /* Comment */
36+
trailing_separator: SeparatorTactic, /* Comment */
37+
separator_place: SeparatorPlace, // Comment 1
38+
// Comment 2
39+
shape: Shape, /* Non-expressions, e.g., items, will have a new line at the end of the list.
40+
* Important for comment styles. */
41+
ends_with_newline: bool, // Remove newlines between list elements for expressions.
42+
preserve_newline: bool, // Nested import lists get some special handling for the "Mixed" list type
43+
nested: bool,
44+
// Whether comments should be visually aligned.
45+
align_comments: bool, /* comment */
46+
config: &'a Config,
47+
}
48+
49+
fn main() {
50+
l = ListItem {
51+
pre_comment, /* Comment */
52+
pre_comment_style, /* Multiline comment
53+
* Line 2 */
54+
/* New line comment */
55+
item: if self.inner.peek().is_none() && self.leave_last {
56+
/* Comment */
57+
None
58+
} else {
59+
(self.get_item_string)(&item)
60+
},
61+
post_comment, /* Comment */
62+
new_lines, /* Comment */
63+
}
64+
}
65+
66+
// Test for Function parameters
67+
pub(crate) fn new(shape: Shape, config: &'a Config) -> Self {
68+
ListFormatting {
69+
tactic: DefinitiveListTactic::Vertical, /* Comment */
70+
separator: ",", /* comment */
71+
trailing_separator: SeparatorTactic::Never, /* Multiline comment
72+
* second comment line */
73+
separator_place: SeparatorPlace::Back, // A longggggggggggggggggggggggggggggggggggggggggggggggggggg comment
74+
shape,
75+
/* New line comment */
76+
ends_with_newline: true, /* Comment */
77+
preserve_newline: false, /* Comment */
78+
nested: false, /* Comment */
79+
align_comments: true, /* Another Multiline comment
80+
* second comment line */
81+
config, /* Last comment */
82+
}
83+
}
84+
85+
// Test for `where`
86+
impl<'a, T, I, F1, F2, F3> Iterator for ListItems<'a, I, F1, F2, F3>
87+
where
88+
I: Iterator<Item = T>, /* Comment */
89+
F111111111: Fn(&T) -> BytePos, /* Comment */
90+
F2222222: Fn(&T) -> BytePos, /* Multiline comment
91+
* Line 2 */
92+
F3: Fn(&T) -> Option<String>, /* Comment */
93+
{
94+
}
95+
96+
// Test for some types of lists
97+
pub(crate) fn itemize_list<'a, T, I, F1, F2, F3>(
98+
snippet_provider: &'a SnippetProvider, /* Comment */
99+
inner: I, /* Comment */
100+
terminator: &'a str, /* Multiline comment
101+
* Line 2 */
102+
separator: &'a str, /* Comment */
103+
get_lo: F1, /* Comment */
104+
get_hi: F2,
105+
get_item_string: F3, /* Comment */
106+
prev_span_end: BytePos, /* Multiline comment
107+
* Line 2 */
108+
next_span_start: BytePos, /* Comment */
109+
leave_last: bool,
110+
) -> ListItems<'a, I, F1, F2, F3>
111+
where
112+
I: Iterator<Item = T>, /* Comment */
113+
F111111111: Fn(&T) -> BytePos, /* Multiline comment
114+
* Line 2 */
115+
F2222222: Fn(&T) -> BytePos,
116+
F3: Fn(&T) -> Option<String>, /* Comment */
117+
{
118+
ListItems {
119+
/* Comment to ListItems */
120+
snippet_provider, /* Multiline comment
121+
* Line 2 */
122+
inner: inner.peekable(), /* Another multiline comment
123+
* another Line 2 */
124+
get_lo, /* Comment */
125+
get_hi,
126+
get_item_string,
127+
prev_span_end, /* Comment */
128+
next_span_start, /* Comment */
129+
terminator,
130+
separator, /* Yet another multiline comment
131+
* yet another Line 2 */
132+
leave_last, /* Comment */
133+
}
134+
}
135+
136+
// Tests when comment in the same line of the item will exceed line width
137+
fn main() {
138+
let v = [
139+
"A-Longgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg", /* item A comment */
140+
"BBB", /* item B Longgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg comment */
141+
"CCCCCC", /* item C comment line 1
142+
* item C comment line 2 */
143+
"D-Longggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg", /* item D comment line 1
144+
* item D comment line 2 */
145+
"EEEEE", /* item E comment */
146+
];
147+
}
148+
149+
// Test for nested items
150+
fn main() {
151+
let v1 = [
152+
"GG", /* item G comment line 1
153+
* item G comment line 2 */
154+
"AAAAA", /* item A comment */
155+
[
156+
"BBB", /* item B comment */
157+
"CCCCCC", /* item C comment line 1
158+
* item C comment line 2 */
159+
"D", /* item D comment line 1
160+
* item D comment line 2 */
161+
"E", /* item E comment */
162+
],
163+
"FFF", /* item F comment */
164+
];
165+
}

0 commit comments

Comments
 (0)