1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.puppycrawl.tools.checkstyle.checks.whitespace;
21
22 import static com.google.common.truth.Truth.assertWithMessage;
23 import static com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAroundCheck.MSG_WS_NOT_FOLLOWED;
24 import static com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAroundCheck.MSG_WS_NOT_PRECEDED;
25
26 import org.junit.jupiter.api.Test;
27
28 import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
29 import com.puppycrawl.tools.checkstyle.api.TokenTypes;
30 import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
31
32 public class WhitespaceAroundCheckTest
33 extends AbstractModuleTestSupport {
34
35 @Override
36 protected String getPackageLocation() {
37 return "com/puppycrawl/tools/checkstyle/checks/whitespace/whitespacearound";
38 }
39
40 @Test
41 public void testGetRequiredTokens() {
42 final WhitespaceAroundCheck checkObj = new WhitespaceAroundCheck();
43 assertWithMessage(
44 "WhitespaceAroundCheck#getRequiredTokens should return empty array by default")
45 .that(checkObj.getRequiredTokens())
46 .isEmpty();
47 }
48
49 @Test
50 public void testKeywordsAndOperators()
51 throws Exception {
52 final String[] expected = {
53 "32:22: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
54 "32:22: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
55 "34:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
56 "42:14: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
57 "43:10: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
58 "43:10: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
59 "44:10: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+="),
60 "44:10: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+="),
61 "45:11: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "-="),
62 "53:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "synchronized"),
63 "55:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "try"),
64 "55:12: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
65 "57:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "catch"),
66 "57:34: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
67 "74:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "if"),
68 "92:13: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "return"),
69 "113:29: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "?"),
70 "113:29: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "?"),
71 "113:34: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ":"),
72 "113:34: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, ":"),
73 "114:15: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "=="),
74 "114:15: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "=="),
75 "120:19: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "*"),
76 "120:21: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "*"),
77 "135:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "%"),
78 "136:19: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "%"),
79 "137:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "%"),
80 "137:18: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "%"),
81 "139:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "/"),
82 "140:19: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "/"),
83 "141:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "/"),
84 "141:18: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "/"),
85 "167:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "assert"),
86 "170:20: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ":"),
87 "170:20: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, ":"),
88 "276:13: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "}"),
89 "305:24: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
90 "305:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
91 "305:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
92 "305:28: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
93 };
94 verifyWithInlineConfigParser(
95 getPath("InputWhitespaceAroundKeywordsAndOperators.java"), expected);
96 }
97
98 @Test
99 public void testSimpleInput()
100 throws Exception {
101 final String[] expected = {
102 "168:26: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
103 "169:26: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
104 "170:26: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
105 "171:26: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
106 "172:26: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
107 "173:26: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
108 };
109 verifyWithInlineConfigParser(
110 getPath("InputWhitespaceAroundSimple.java"), expected);
111 }
112
113 @Test
114 public void testStartOfTheLine()
115 throws Exception {
116 final String[] expected = {
117 "25:2: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
118 };
119 verifyWithInlineConfigParser(
120 getPath("InputWhitespaceAroundStartOfTheLine.java"), expected);
121 }
122
123 @Test
124 public void testBraces()
125 throws Exception {
126 final String[] expected = {
127 "53:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "while"),
128 "70:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "for"),
129
130
131 "127:42: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
132 "127:43: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
133 "130:39: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
134 "130:40: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
135 "134:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "if"),
136 "134:17: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
137 "134:17: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
138 "134:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
139 };
140 verifyWithInlineConfigParser(
141 getPath("InputWhitespaceAroundBraces.java"), expected);
142 }
143
144 @Test
145 public void testBracesInMethodsAndConstructors()
146 throws Exception {
147 final String[] expected = {
148 "53:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "while"),
149 "70:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "for"),
150 "134:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "if"),
151 "134:17: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
152 "134:17: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
153 "134:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
154 };
155 verifyWithInlineConfigParser(
156 getPath("InputWhitespaceAroundBraces2.java"), expected);
157 }
158
159 @Test
160 public void testArrayInitialization()
161 throws Exception {
162 final String[] expected = {
163 "21:39: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
164 "25:37: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
165 "28:30: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
166 "36:42: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
167 "36:59: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
168 "38:40: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
169 "38:41: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
170 "43:20: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
171 };
172 verifyWithInlineConfigParser(
173 getPath("InputWhitespaceAroundArrayInitialization.java"), expected);
174 }
175
176 @Test
177 public void testGenericsTokensAreFlagged()
178 throws Exception {
179 final String[] expected = {
180 "27:16: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "&"),
181 "27:16: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "&"),
182 };
183 verifyWithInlineConfigParser(
184 getPath("InputWhitespaceAroundGenerics.java"), expected);
185 }
186
187 @Test
188 public void test1322879And1649038() throws Exception {
189 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
190 verifyWithInlineConfigParser(
191 getPath("InputWhitespaceAround1.java"),
192 expected);
193 }
194
195 @Test
196 public void testAllowDoubleBraceInitialization() throws Exception {
197 final String[] expected = {
198 "31:33: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
199 "32:27: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
200 "34:27: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
201 "34:88: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
202 "37:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "}"),
203 "37:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
204 };
205 verifyWithInlineConfigParser(
206 getPath("InputWhitespaceAroundDoubleBraceInitialization.java"),
207 expected);
208 }
209
210 @Test
211 public void testIgnoreEnhancedForColon() throws Exception {
212 final String[] expected = {
213 "39:20: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ":"),
214 };
215 verifyWithInlineConfigParser(
216 getPath("InputWhitespaceAround2.java"),
217 expected);
218 }
219
220 @Test
221 public void testEmptyTypes() throws Exception {
222 final String[] expected = {
223 "45:94: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
224 "45:95: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
225 "46:32: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
226 "46:33: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
227 "47:20: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
228 "47:21: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
229 };
230 verifyWithInlineConfigParser(
231 getPath("InputWhitespaceAroundEmptyTypesAndCycles.java"),
232 expected);
233 }
234
235 @Test
236 public void testEmptyLoops() throws Exception {
237 final String[] expected = {
238 "56:65: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
239 "56:66: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
240 "58:17: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
241 "58:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
242 "60:20: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
243 "60:21: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
244 "66:35: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
245 "66:36: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
246 "76:18: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
247 "76:19: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
248 };
249 verifyWithInlineConfigParser(
250 getPath("InputWhitespaceAroundEmptyTypesAndCycles2.java"),
251 expected);
252 }
253
254 @Test
255 public void testSwitchWhitespaceAround() throws Exception {
256 final String[] expected = {
257 "26:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "switch"),
258 };
259 verifyWithInlineConfigParser(
260 getPath("InputWhitespaceAroundSwitch.java"), expected);
261 }
262
263 @Test
264 public void testSwitchExpressionWhitespaceAround() throws Exception {
265 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
266 verifyWithInlineConfigParser(
267 getNonCompilablePath("InputWhitespaceAroundSwitchExpressions.java"), expected);
268 }
269
270 @Test
271 public void testDoWhileWhitespaceAround() throws Exception {
272 final String[] expected = {
273 "29:11: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "while"),
274 };
275 verifyWithInlineConfigParser(
276 getPath("InputWhitespaceAroundDoWhile.java"), expected);
277 }
278
279 @Test
280 public void allowEmptyMethods() throws Exception {
281 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
282 verifyWithInlineConfigParser(
283 getPath("InputWhitespaceAround3.java"), expected);
284 }
285
286 @Test
287 public void testGetAcceptableTokens() {
288 final WhitespaceAroundCheck whitespaceAroundCheckObj = new WhitespaceAroundCheck();
289 final int[] actual = whitespaceAroundCheckObj.getAcceptableTokens();
290 final int[] expected = {
291 TokenTypes.ASSIGN,
292 TokenTypes.ARRAY_INIT,
293 TokenTypes.BAND,
294 TokenTypes.BAND_ASSIGN,
295 TokenTypes.BOR,
296 TokenTypes.BOR_ASSIGN,
297 TokenTypes.BSR,
298 TokenTypes.BSR_ASSIGN,
299 TokenTypes.BXOR,
300 TokenTypes.BXOR_ASSIGN,
301 TokenTypes.COLON,
302 TokenTypes.DIV,
303 TokenTypes.DIV_ASSIGN,
304 TokenTypes.DO_WHILE,
305 TokenTypes.EQUAL,
306 TokenTypes.GE,
307 TokenTypes.GT,
308 TokenTypes.LAMBDA,
309 TokenTypes.LAND,
310 TokenTypes.LCURLY,
311 TokenTypes.LE,
312 TokenTypes.LITERAL_CATCH,
313 TokenTypes.LITERAL_DO,
314 TokenTypes.LITERAL_ELSE,
315 TokenTypes.LITERAL_FINALLY,
316 TokenTypes.LITERAL_FOR,
317 TokenTypes.LITERAL_IF,
318 TokenTypes.LITERAL_RETURN,
319 TokenTypes.LITERAL_SWITCH,
320 TokenTypes.LITERAL_SYNCHRONIZED,
321 TokenTypes.LITERAL_TRY,
322 TokenTypes.LITERAL_WHILE,
323 TokenTypes.LOR,
324 TokenTypes.LT,
325 TokenTypes.MINUS,
326 TokenTypes.MINUS_ASSIGN,
327 TokenTypes.MOD,
328 TokenTypes.MOD_ASSIGN,
329 TokenTypes.NOT_EQUAL,
330 TokenTypes.PLUS,
331 TokenTypes.PLUS_ASSIGN,
332 TokenTypes.QUESTION,
333 TokenTypes.RCURLY,
334 TokenTypes.SL,
335 TokenTypes.SLIST,
336 TokenTypes.SL_ASSIGN,
337 TokenTypes.SR,
338 TokenTypes.SR_ASSIGN,
339 TokenTypes.STAR,
340 TokenTypes.STAR_ASSIGN,
341 TokenTypes.LITERAL_ASSERT,
342 TokenTypes.TYPE_EXTENSION_AND,
343 TokenTypes.WILDCARD_TYPE,
344 TokenTypes.GENERIC_START,
345 TokenTypes.GENERIC_END,
346 TokenTypes.ELLIPSIS,
347 TokenTypes.LITERAL_WHEN,
348 };
349 assertWithMessage("Default acceptable tokens are invalid")
350 .that(actual)
351 .isEqualTo(expected);
352 }
353
354 @Test
355 public void testAllowEmptyTypesIsSetToFalseAndNonEmptyClasses() throws Exception {
356 final String[] expected = {
357 "31:20: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
358 "35:32: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
359 "39:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
360 "41:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
361 "41:24: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
362 "41:31: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
363 "43:30: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "}"),
364 "45:17: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
365 "45:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
366 "47:68: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
367 "47:69: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
368 "49:19: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
369 "52:12: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
370 "52:13: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
371 "56:34: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
372 };
373 verifyWithInlineConfigParser(
374 getPath("InputWhitespaceAroundAllowEmptyTypesAndNonEmptyClasses.java"),
375 expected);
376 }
377
378 @Test
379 public void testAllowEmptyTypesIsSetToTrueAndNonEmptyClasses() throws Exception {
380 final String[] expected = {
381 "30:20: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
382 "34:32: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
383 "38:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
384 "40:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
385 "40:24: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
386 "40:31: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
387 "42:30: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "}"),
388 "48:23: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
389 "51:12: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
390 "51:13: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
391 "55:35: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
392 };
393 verifyWithInlineConfigParser(
394 getPath("InputWhitespaceAroundAllowEmptyTypesAndNonEmptyClasses2.java"),
395 expected);
396 }
397
398 @Test
399 public void testNotAllowEmptyLambdaExpressionsByDefault() throws Exception {
400 final String[] expected = {
401 "27:27: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
402 "27:28: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
403 "32:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
404 "32:30: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
405 "33:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
406 "33:42: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
407 };
408 verifyWithInlineConfigParser(
409 getPath("InputWhitespaceAroundAllowEmptyLambdaExpressions.java"),
410 expected);
411 }
412
413 @Test
414 public void testAllowEmptyLambdaExpressionsWithAllowEmptyLambdaParameter() throws Exception {
415 final String[] expected = {
416 "32:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
417 "32:30: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
418 "33:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
419 "33:42: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
420 };
421 verifyWithInlineConfigParser(
422 getPath("InputWhitespaceAroundAllowEmptyLambdaExpressions2.java"),
423 expected);
424 }
425
426 @Test
427 public void testWhitespaceAroundLambda() throws Exception {
428 final String[] expected = {
429 "28:48: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "->"),
430 "28:48: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "->"),
431 };
432 verifyWithInlineConfigParser(
433 getPath("InputWhitespaceAroundLambda.java"), expected);
434 }
435
436 @Test
437 public void testWhitespaceAroundEmptyCatchBlock() throws Exception {
438 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
439 verifyWithInlineConfigParser(
440 getPath("InputWhitespaceAroundCatch.java"),
441 expected);
442 }
443
444 @Test
445 public void testWhitespaceAroundVarargs() throws Exception {
446 final String[] expected = {
447 "19:29: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "..."),
448 "20:37: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "..."),
449 "21:36: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "..."),
450 "21:36: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "..."),
451 "23:28: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "..."),
452 "23:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "..."),
453 "24:39: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "..."),
454 "24:39: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "..."),
455 };
456 verifyWithInlineConfigParser(
457 getPath("InputWhitespaceAroundVarargs.java"), expected);
458 }
459
460 @Test
461 public void testWhitespaceAroundRecords()
462 throws Exception {
463 final String[] expected = {
464 "26:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
465 "26:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
466 "34:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
467 "34:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
468 "35:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
469 "35:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
470 "36:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
471 "36:29: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
472 "41:23: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
473 "43:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
474 "44:14: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
475 "44:14: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
476 "53:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
477 "54:14: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
478 "54:14: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
479 "62:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
480 "63:14: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
481 "63:14: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
482 "70:21: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
483 "74:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
484 "74:29: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
485 };
486 verifyWithInlineConfigParser(
487 getNonCompilablePath("InputWhitespaceAroundRecords.java"), expected);
488 }
489
490 @Test
491 public void testWhitespaceAroundAllowEmptyCompactCtors()
492 throws Exception {
493 final String[] expected = {
494 "26:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
495 "26:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
496 "34:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
497 "34:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
498 "35:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
499 "35:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
500 "36:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
501 "36:29: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
502 "41:23: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
503 "43:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
504 "44:14: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
505 "44:14: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
506 "53:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
507 "54:14: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
508 "54:14: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
509 "67:21: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
510 "80:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
511 "84:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
512 "84:18: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
513 "84:40: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
514 "89:23: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
515 };
516 verifyWithInlineConfigParser(
517 getNonCompilablePath("InputWhitespaceAroundAllowEmptyCompactCtors.java"),
518 expected);
519 }
520
521 @Test
522 public void testWhitespaceAroundRecordsAllowEmptyTypes()
523 throws Exception {
524 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
525 verifyWithInlineConfigParser(
526 getNonCompilablePath("InputWhitespaceAroundRecordsAllowEmptyTypes.java"),
527 expected);
528 }
529
530 @Test
531 public void testWhitespaceAroundAllTokens() throws Exception {
532 final String[] expected = {
533 "27:29: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "<"),
534 "27:29: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "<"),
535 "27:35: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "<"),
536 "27:35: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "<"),
537 "27:36: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "?"),
538 "27:36: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "?"),
539 "27:37: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, ">"),
540 "27:37: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ">"),
541 "27:38: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ">"),
542 };
543 verifyWithInlineConfigParser(
544 getPath("InputWhitespaceAroundAllTokens.java"), expected);
545 }
546
547 @Test
548 public void testWhitespaceAroundAfterEmoji() throws Exception {
549 final String[] expected = {
550 "25:22: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
551 "26:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
552 "27:22: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
553 "27:22: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
554 "29:19: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
555 "29:19: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
556 "29:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
557 "29:23: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
558 "29:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
559 "29:28: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
560 "29:32: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
561 "29:32: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
562 "29:36: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
563 "29:36: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
564 "29:40: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "+"),
565 "29:40: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "+"),
566 };
567 verifyWithInlineConfigParser(
568 getPath("InputWhitespaceAroundAfterEmoji.java"), expected);
569 }
570
571 @Test
572 public void testLiteralWhen() throws Exception {
573 final String[] expected = {
574 "21:28: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "when"),
575 "23:27: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "when"),
576 "25:39: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "when"),
577 "30:38: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "when"),
578 "30:38: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "when"),
579 "34:38: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "when"),
580 "34:38: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "when"),
581 "53:27: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "when"),
582 "64:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "when"),
583 "67:38: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "when"),
584 };
585 verifyWithInlineConfigParser(
586 getNonCompilablePath("InputWhitespaceAroundLiteralWhen.java"),
587 expected);
588 }
589
590 @Test
591 public void testWhitespaceAroundAfterPermitsList() throws Exception {
592 final String[] expected = {
593 "25:53: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
594 "25:53: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
595 "25:54: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
596 "26:40: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
597 "26:40: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
598 "26:41: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
599 "27:48: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
600 "27:48: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
601 "27:49: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
602 };
603 verifyWithInlineConfigParser(
604 getNonCompilablePath("InputWhitespaceAroundAfterPermitsList.java"), expected);
605 }
606
607 @Test
608 public void testWhitespaceAroundUnnamedPatterns() throws Exception {
609 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
610 verifyWithInlineConfigParser(
611 getNonCompilablePath("InputWhitespaceAroundUnnamedPattern.java"), expected);
612 }
613
614 @Test
615 public void testSwitchCasesParens() throws Exception {
616 final String[] expected = {
617 "33:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
618 "33:22: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
619 "37:22: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
620 "37:23: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
621 "47:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
622 "47:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
623 "51:24: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
624 "51:25: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
625 "59:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
626 "59:48: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
627 "68:22: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
628 "68:47: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
629 "76:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
630 "76:10: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
631 "81:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
632 "81:34: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
633 "89:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
634 "89:22: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
635 "89:24: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
636 "89:25: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
637 "96:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
638 "96:23: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
639 "100:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
640 "100:22: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
641 "100:22: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
642 "100:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "}"),
643 "100:23: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
644 "100:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
645 "108:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
646 "108:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
647 "115:13: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "}"),
648 };
649 verifyWithInlineConfigParser(
650 getNonCompilablePath("InputWhitespaceAroundSwitchCasesParens.java"),
651 expected);
652 }
653
654 @Test
655 public void testSwitchCasesParensWithAllowEmptySwitchBlockStatements() throws Exception {
656 final String fileName =
657 "InputWhitespaceAroundSwitchCasesParensWithAllowEmptySwitchBlockStatements.java";
658
659 final String[] expected = {
660 "49:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
661 "49:48: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
662 "59:22: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
663 "59:47: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
664 "68:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
665 "68:10: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
666 "73:9: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
667 "73:34: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
668 "84:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
669 "84:23: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
670 "88:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
671 "88:22: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
672 "88:22: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
673 "88:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "}"),
674 "88:23: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
675 "88:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
676 "96:23: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
677 "96:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
678 };
679 verifyWithInlineConfigParser(
680 getNonCompilablePath(fileName),
681 expected);
682 }
683 }