Skip to content

Commit 5666118

Browse files
jungmrnveach
authored andcommitted
supplemental: Update tests for Issue #14014
1 parent 509be35 commit 5666118

File tree

3 files changed

+98
-74
lines changed

3 files changed

+98
-74
lines changed

src/test/java/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckTest.java

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2816,28 +2816,38 @@ public void testIndentationSwitchExpressionDeclaration() throws Exception {
28162816
checkConfig.addProperty("caseIndent", "4");
28172817
checkConfig.addProperty("lineWrappingIndentation", "8");
28182818
final String[] expected = {
2819-
"49:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
2820-
"50:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
2821-
"58:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
2822-
"59:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
2823-
"66:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
2824-
"67:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
2825-
"74:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
2826-
"75:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
2827-
"82:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
2828-
"83:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
2829-
"91:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
2830-
"92:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
2831-
"99:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
2832-
"100:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
2833-
"108:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
2834-
"109:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
2819+
"33:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
2820+
"34:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
2821+
"41:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
2822+
"42:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
2823+
"49:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
2824+
"50:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
2825+
"57:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
2826+
"58:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
28352827
};
28362828
verifyWarns(checkConfig,
28372829
getNonCompilablePath("InputIndentationCheckSwitchExpressionDeclaration.java"),
28382830
expected);
28392831
}
28402832

2833+
@Test
2834+
public void testIndentationSwitchExpressionDeclarationLeftCurlyNewLine() throws Exception {
2835+
final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
2836+
checkConfig.addProperty("tabWidth", "4");
2837+
checkConfig.addProperty("caseIndent", "4");
2838+
checkConfig.addProperty("lineWrappingIndentation", "8");
2839+
final String[] expected = {
2840+
"34:5: " + getCheckMessage(MSG_ERROR, "switch lcurly", 4, 8),
2841+
"42:5: " + getCheckMessage(MSG_ERROR, "switch lcurly", 4, 8),
2842+
"50:13: " + getCheckMessage(MSG_ERROR, "switch lcurly", 12, 8),
2843+
"58:13: " + getCheckMessage(MSG_ERROR, "switch lcurly", 12, 8),
2844+
};
2845+
verifyWarns(checkConfig,
2846+
getNonCompilablePath(
2847+
"InputIndentationCheckSwitchExpressionDeclarationLCurlyNewLine.java"),
2848+
expected);
2849+
}
2850+
28412851
@Test
28422852
public void testIndentationRecords() throws Exception {
28432853
final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);

src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/checks/indentation/indentation/InputIndentationCheckSwitchExpressionDeclaration.java

Lines changed: 8 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -12,101 +12,51 @@
1212
* forceStrictCondition = false //indent:1 exp:1
1313
*/ //indent:1 exp:1
1414
public class InputIndentationCheckSwitchExpressionDeclaration { //indent:0 exp:0
15-
15+
//indent:82 exp:82
1616
public void validDeclare() { //indent:4 exp:4
1717
String requestId = switch ("in") { //indent:8 exp:8
1818
case "correct" -> "true"; //indent:12 exp:12
1919
default -> "also correct"; //indent:12 exp:12
2020
}; //indent:8 exp:8
2121
} //indent:4 exp:4
22-
23-
public void validDeclareLeftCurlyOnNewLine() { //indent:4 exp:4
24-
String requestId = switch ("in") //indent:8 exp:8
25-
{ //indent:8 exp:8
26-
case "correct" -> "true"; //indent:12 exp:12
27-
default -> "also correct"; //indent:12 exp:12
28-
}; //indent:8 exp:8
29-
} //indent:4 exp:4
30-
22+
//indent:82 exp:82
3123
public void validAssign(String result) { //indent:4 exp:4
3224
result = switch ("in") { //indent:8 exp:8
3325
case "correct" -> "true"; //indent:12 exp:12
3426
default -> "also correct"; //indent:12 exp:12
3527
}; //indent:8 exp:8
3628
} //indent:4 exp:4
37-
38-
public void validAssignLeftCurlyOnNewLine(String result) { //indent:4 exp:4
39-
result = switch ("in") //indent:8 exp:8
40-
{ //indent:8 exp:8
41-
case "correct" -> "true"; //indent:12 exp:12
42-
default -> "also correct"; //indent:12 exp:12
43-
}; //indent:8 exp:8
44-
} //indent:4 exp:4
45-
29+
//indent:82 exp:82
4630
public void invalidDeclareWithBiggerIndent() { //indent:4 exp:4
4731
String requestId = switch ("in") { //indent:8 exp:8
4832
case "correct" -> "true"; //indent:12 exp:12
4933
case "incorrect" -> "true"; //indent:16 exp:12 warn
5034
default -> "also incorrect"; //indent:16 exp:12 warn
5135
}; //indent:8 exp:8
5236
} //indent:4 exp:4
53-
54-
public void invalidDeclareWithBiggerIndentLeftCurlyOnNewLine() { //indent:4 exp:4
55-
String requestId = switch ("in") //indent:8 exp:8
56-
{ //indent:8 exp:8
57-
case "correct" -> "true"; //indent:12 exp:12
58-
case "incorrect" -> "true"; //indent:16 exp:12 warn
59-
default -> "also incorrect"; //indent:16 exp:12 warn
60-
}; //indent:8 exp:8
61-
} //indent:4 exp:4
62-
37+
//indent:82 exp:82
6338
public void invalidAssignWithBiggerIndent(String result) { //indent:4 exp:4
6439
result = switch ("in") { //indent:8 exp:8
6540
case "correct" -> "true"; //indent:12 exp:12
6641
case "incorrect" -> "true"; //indent:16 exp:12 warn
6742
default -> "also incorrect"; //indent:16 exp:12 warn
6843
}; //indent:8 exp:8
6944
} //indent:4 exp:4
70-
public void invalidAssignWithBiggerIndentLeftCurlyOnNewLine(String result) { //indent:4 exp:4
71-
result = switch ("in") //indent:8 exp:8
72-
{ //indent:8 exp:8
73-
case "correct" -> "true"; //indent:12 exp:12
74-
case "incorrect" -> "true"; //indent:16 exp:12 warn
75-
default -> "also incorrect"; //indent:16 exp:12 warn
76-
}; //indent:8 exp:8
77-
} //indent:4 exp:4
78-
45+
//indent:82 exp:82
7946
public void invalidDeclareWithLesserIndent() { //indent:4 exp:4
8047
String requestId = switch ("in") { //indent:8 exp:8
8148
case "correct" -> "true"; //indent:12 exp:12
8249
case "incorrect" -> "true"; //indent:8 exp:12 warn
8350
default -> "also incorrect"; //indent:8 exp:12 warn
8451
}; //indent:8 exp:8
8552
} //indent:4 exp:4
86-
87-
public void invalidDeclareWithLesserIndentLeftCurlyOnNewLine() { //indent:4 exp:4
88-
String requestId = switch ("in") //indent:8 exp:8
89-
{ //indent:8 exp:8
90-
case "correct" -> "true"; //indent:12 exp:12
91-
case "incorrect" -> "true"; //indent:8 exp:12 warn
92-
default -> "also incorrect"; //indent:8 exp:12 warn
93-
}; //indent:8 exp:8
94-
} //indent:4 exp:4
95-
53+
//indent:82 exp:82
9654
public void invalidAssignWithLesserIndent(String result) { //indent:4 exp:4
9755
result = switch ("in") { //indent:8 exp:8
9856
case "correct" -> "true"; //indent:12 exp:12
9957
case "incorrect" -> "true"; //indent:8 exp:12 warn
10058
default -> "also incorrect"; //indent:8 exp:12 warn
10159
}; //indent:8 exp:8
10260
} //indent:4 exp:4
103-
104-
public void invalidAssignWithLesserIndentLeftCurlyOnNewLine(String result) { //indent:4 exp:4
105-
result = switch ("in") //indent:8 exp:8
106-
{ //indent:8 exp:8
107-
case "correct" -> "true"; //indent:12 exp:12
108-
case "incorrect" -> "true"; //indent:8 exp:12 warn
109-
default -> "also incorrect"; //indent:8 exp:12 warn
110-
}; //indent:8 exp:8
111-
} //indent:4 exp:4
112-
} //indent:0 exp:0
61+
} //indent:0 exp:0
62+
//indent:82 exp:82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//non-compiled with javac: Compilable with Java14 //indent:0 exp:0
2+
package com.puppycrawl.tools.checkstyle.checks.indentation.indentation; //indent:0 exp:0
3+
4+
/* Config: //indent:0 exp:0
5+
* //indent:1 exp:1
6+
* basicOffset = 4 //indent:1 exp:1
7+
* braceAdjustment = 0 //indent:1 exp:1
8+
* caseIndent = 4 //indent:1 exp:1
9+
* throwsIndent = 4 //indent:1 exp:1
10+
* arrayInitIndent = 4 //indent:1 exp:1
11+
* lineWrappingIndentation = 4 //indent:1 exp:1
12+
* forceStrictCondition = false //indent:1 exp:1
13+
*/ //indent:1 exp:1
14+
public class InputIndentationCheckSwitchExpressionDeclarationLCurlyNewLine { //indent:0 exp:0
15+
16+
public void validDeclare() { //indent:4 exp:4
17+
String requestId = switch ("in") //indent:8 exp:8
18+
{ //indent:8 exp:8
19+
case "correct" -> "true"; //indent:12 exp:12
20+
default -> "also correct"; //indent:12 exp:12
21+
}; //indent:8 exp:8
22+
} //indent:4 exp:4
23+
24+
public void validAssign(String result) { //indent:4 exp:4
25+
result = switch ("in") //indent:8 exp:8
26+
{ //indent:8 exp:8
27+
case "correct" -> "true"; //indent:12 exp:12
28+
default -> "also correct"; //indent:12 exp:12
29+
}; //indent:8 exp:8
30+
} //indent:4 exp:4
31+
32+
public void invalidAssignLeftCurlyWithLesserIndent(String result) { //indent:4 exp:4
33+
result = switch ("in") //indent:8 exp:8
34+
{ //indent:4 exp:8 warn
35+
case "correct" -> "true"; //indent:12 exp:12
36+
case "incorrect" -> "true"; //indent:12 exp:12
37+
default -> "also incorrect"; //indent:12 exp:12
38+
}; //indent:8 exp:8
39+
} //indent:4 exp:4
40+
public void invalidDeclareLeftCurlyWithLesserIndent() { //indent:4 exp:4
41+
String result = switch ("in") //indent:8 exp:8
42+
{ //indent:4 exp:8 warn
43+
case "correct" -> "true"; //indent:12 exp:12
44+
case "incorrect" -> "true"; //indent:12 exp:12
45+
default -> "also incorrect"; //indent:12 exp:12
46+
}; //indent:8 exp:8
47+
} //indent:4 exp:4
48+
public void invalidAssignLeftCurlyWithBiggerIndent(String result) { //indent:4 exp:4
49+
result = switch ("in") //indent:8 exp:8
50+
{ //indent:12 exp:8 warn
51+
case "correct" -> "true"; //indent:12 exp:12
52+
case "incorrect" -> "true"; //indent:12 exp:12
53+
default -> "also incorrect"; //indent:12 exp:12
54+
}; //indent:8 exp:8
55+
} //indent:4 exp:4
56+
public void invalidDeclareLeftCurlyWithBiggerIndent() { //indent:4 exp:4
57+
String result = switch ("in") //indent:8 exp:8
58+
{ //indent:12 exp:8 warn
59+
case "correct" -> "true"; //indent:12 exp:12
60+
case "incorrect" -> "true"; //indent:12 exp:12
61+
default -> "also incorrect"; //indent:12 exp:12
62+
}; //indent:8 exp:8
63+
} //indent:4 exp:4
64+
} //indent:0 exp:0

0 commit comments

Comments
 (0)