@@ -32,48 +32,76 @@ class FormatTestCSharp : public ::testing::Test {
32
32
33
33
static std::string
34
34
format (llvm::StringRef Code,
35
- const FormatStyle &Style = getGoogleStyle (FormatStyle::LK_CSharp)) {
35
+ const FormatStyle &Style = getMicrosoftStyle (FormatStyle::LK_CSharp)) {
36
36
return format (Code, 0 , Code.size (), Style );
37
37
}
38
38
39
39
static FormatStyle getStyleWithColumns (unsigned ColumnLimit) {
40
- FormatStyle Style = getGoogleStyle (FormatStyle::LK_CSharp);
40
+ FormatStyle Style = getMicrosoftStyle (FormatStyle::LK_CSharp);
41
41
Style .ColumnLimit = ColumnLimit;
42
42
return Style ;
43
43
}
44
44
45
45
static void verifyFormat (
46
46
llvm::StringRef Code,
47
- const FormatStyle &Style = getGoogleStyle (FormatStyle::LK_CSharp)) {
47
+ const FormatStyle &Style = getMicrosoftStyle (FormatStyle::LK_CSharp)) {
48
48
EXPECT_EQ (Code.str (), format (Code, Style )) << " Expected code is not stable" ;
49
49
EXPECT_EQ (Code.str (), format (test::messUp (Code), Style ));
50
50
}
51
51
};
52
52
53
53
TEST_F (FormatTestCSharp, CSharpClass) {
54
- verifyFormat (" public class SomeClass {\n "
55
- " void f() {}\n "
56
- " int g() { return 0; }\n "
57
- " void h() {\n "
58
- " while (true) f();\n "
59
- " for (;;) f();\n "
60
- " if (true) f();\n "
61
- " }\n "
54
+ verifyFormat (" public class SomeClass\n "
55
+ " {\n "
56
+ " void f()\n "
57
+ " {\n "
58
+ " }\n "
59
+ " int g()\n "
60
+ " {\n "
61
+ " return 0;\n "
62
+ " }\n "
63
+ " void h()\n "
64
+ " {\n "
65
+ " while (true)\n "
66
+ " f();\n "
67
+ " for (;;)\n "
68
+ " f();\n "
69
+ " if (true)\n "
70
+ " f();\n "
71
+ " }\n "
62
72
" }" );
63
73
}
64
74
65
75
TEST_F (FormatTestCSharp, AccessModifiers) {
66
- verifyFormat (" public String toString() {}" );
67
- verifyFormat (" private String toString() {}" );
68
- verifyFormat (" protected String toString() {}" );
69
- verifyFormat (" internal String toString() {}" );
76
+ verifyFormat (" public String toString()\n "
77
+ " {\n "
78
+ " }" );
79
+ verifyFormat (" private String toString()\n "
80
+ " {\n "
81
+ " }" );
82
+ verifyFormat (" protected String toString()\n "
83
+ " {\n "
84
+ " }" );
85
+ verifyFormat (" internal String toString()\n "
86
+ " {\n "
87
+ " }" );
70
88
71
- verifyFormat (" public override String toString() {}" );
72
- verifyFormat (" private override String toString() {}" );
73
- verifyFormat (" protected override String toString() {}" );
74
- verifyFormat (" internal override String toString() {}" );
89
+ verifyFormat (" public override String toString()\n "
90
+ " {\n "
91
+ " }" );
92
+ verifyFormat (" private override String toString()\n "
93
+ " {\n "
94
+ " }" );
95
+ verifyFormat (" protected override String toString()\n "
96
+ " {\n "
97
+ " }" );
98
+ verifyFormat (" internal override String toString()\n "
99
+ " {\n "
100
+ " }" );
75
101
76
- verifyFormat (" internal static String toString() {}" );
102
+ verifyFormat (" internal static String toString()\n "
103
+ " {\n "
104
+ " }" );
77
105
}
78
106
79
107
TEST_F (FormatTestCSharp, NoStringLiteralBreaks) {
@@ -124,45 +152,70 @@ TEST_F(FormatTestCSharp, CSharpNullConditional) {
124
152
125
153
verifyFormat (" switch(args?.Length)" );
126
154
127
- verifyFormat (" public static void Main(string[] args) { string dirPath "
128
- " = args?[0]; }" );
155
+ verifyFormat (" public static void Main(string[] args)\n "
156
+ " {\n "
157
+ " string dirPath = args?[0];\n "
158
+ " }" );
129
159
}
130
160
131
161
TEST_F (FormatTestCSharp, Attributes) {
132
162
verifyFormat (" [STAThread]\n "
133
- " static void\n "
134
- " Main(string[] args) {}" );
163
+ " static void Main(string[] args)\n "
164
+ " {\n "
165
+ " }" );
135
166
136
167
verifyFormat (" [TestMethod]\n "
137
- " private class Test {}" );
168
+ " private class Test\n "
169
+ " {\n "
170
+ " }" );
138
171
139
172
verifyFormat (" [TestMethod]\n "
140
- " protected class Test {}" );
173
+ " protected class Test\n "
174
+ " {\n "
175
+ " }" );
141
176
142
177
verifyFormat (" [TestMethod]\n "
143
- " internal class Test {}" );
178
+ " internal class Test\n "
179
+ " {\n "
180
+ " }" );
144
181
145
182
verifyFormat (" [TestMethod]\n "
146
- " class Test {}" );
183
+ " class Test\n "
184
+ " {\n "
185
+ " }" );
147
186
148
187
verifyFormat (" [TestMethod]\n "
149
188
" [DeploymentItem(\" Test.txt\" )]\n "
150
- " public class Test {}" );
189
+ " public class Test\n "
190
+ " {\n "
191
+ " }" );
151
192
152
193
verifyFormat (" [System.AttributeUsage(System.AttributeTargets.Method)]\n "
153
194
" [System.Runtime.InteropServices.ComVisible(true)]\n "
154
- " public sealed class STAThreadAttribute : Attribute {}" );
195
+ " public sealed class STAThreadAttribute : Attribute\n "
196
+ " {\n "
197
+ " }" );
155
198
156
199
verifyFormat (" [Verb(\" start\" , HelpText = \" Starts the server listening on "
157
200
" provided port\" )]\n "
158
- " class Test {}" );
201
+ " class Test\n "
202
+ " {\n "
203
+ " }" );
159
204
160
205
verifyFormat (" [TestMethod]\n "
161
- " public string Host {\n set;\n get;\n }" );
206
+ " public string Host\n "
207
+ " {\n "
208
+ " set;\n "
209
+ " get;\n "
210
+ " }" );
162
211
163
212
verifyFormat (" [TestMethod(\" start\" , HelpText = \" Starts the server "
164
213
" listening on provided host\" )]\n "
165
- " public string Host {\n set;\n get;\n }" );
214
+ " public string Host\n "
215
+ " {\n "
216
+ " set;\n "
217
+ " get;\n "
218
+ " }" );
166
219
}
167
220
168
221
TEST_F (FormatTestCSharp, CSharpUsing) {
@@ -195,5 +248,57 @@ TEST_F(FormatTestCSharp, CSharpNullCoalescing) {
195
248
verifyFormat (" return _name ?? \" DEF\" ;" );
196
249
}
197
250
251
+ TEST_F (FormatTestCSharp, AttributesIndentation) {
252
+ FormatStyle Style = getMicrosoftStyle (FormatStyle::LK_CSharp);
253
+ Style .AlwaysBreakAfterReturnType = FormatStyle::RTBS_None;
254
+
255
+ verifyFormat (" [STAThread]\n "
256
+ " static void Main(string[] args)\n "
257
+ " {\n "
258
+ " }" ,
259
+ Style );
260
+
261
+ verifyFormat (" [STAThread]\n "
262
+ " void "
263
+ " veryLooooooooooooooongFunctionName(string[] args)\n "
264
+ " {\n "
265
+ " }" ,
266
+ Style );
267
+
268
+ verifyFormat (" [STAThread]\n "
269
+ " veryLoooooooooooooooooooongReturnType "
270
+ " veryLooooooooooooooongFunctionName(string[] args)\n "
271
+ " {\n "
272
+ " }" ,
273
+ Style );
274
+
275
+ verifyFormat (" [SuppressMessage(\" A\" , \" B\" , Justification = \" C\" )]\n "
276
+ " public override X Y()\n "
277
+ " {\n "
278
+ " }\n " ,
279
+ Style );
280
+
281
+ verifyFormat (" [SuppressMessage]\n "
282
+ " public X Y()\n "
283
+ " {\n "
284
+ " }\n " ,
285
+ Style );
286
+
287
+ verifyFormat (" [SuppressMessage]\n "
288
+ " public override X Y()\n "
289
+ " {\n "
290
+ " }\n " ,
291
+ Style );
292
+
293
+ verifyFormat (" public A(B b) : base(b)\n "
294
+ " {\n "
295
+ " [SuppressMessage]\n "
296
+ " public override X Y()\n "
297
+ " {\n "
298
+ " }\n "
299
+ " }\n " ,
300
+ Style );
301
+ }
302
+
198
303
} // namespace format
199
304
} // end namespace clang
0 commit comments