|
| 1 | +// Basic tests (using vectors) - list multiline post-comment is indented on its own |
1 | 2 | fn main() {
|
2 | 3 | let v = [
|
3 | 4 | "A", /* item A comment */
|
@@ -27,3 +28,136 @@ fn main() {
|
27 | 28 | "FFF", /* item F comment */
|
28 | 29 | ];
|
29 | 30 | }
|
| 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 | +} |
0 commit comments