Skip to content

Commit

Permalink
supplemental: Update tests for Issue checkstyle#14014
Browse files Browse the repository at this point in the history
  • Loading branch information
jungm committed Nov 13, 2023
1 parent f5b01b9 commit a9d01fe
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2816,28 +2816,38 @@ public void testIndentationSwitchExpressionDeclaration() throws Exception {
checkConfig.addProperty("caseIndent", "4");
checkConfig.addProperty("lineWrappingIndentation", "8");
final String[] expected = {
"49:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
"50:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
"58:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
"59:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
"66:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
"67:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
"74:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
"75:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
"82:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
"83:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
"91:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
"92:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
"99:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
"100:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
"108:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
"109:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
"33:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
"34:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
"41:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
"42:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
"49:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
"50:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
"57:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
"58:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
};
verifyWarns(checkConfig,
getNonCompilablePath("InputIndentationCheckSwitchExpressionDeclaration.java"),
expected);
}

@Test
public void testIndentationSwitchExpressionDeclarationLeftCurlyNewLine() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
checkConfig.addProperty("tabWidth", "4");
checkConfig.addProperty("caseIndent", "4");
checkConfig.addProperty("lineWrappingIndentation", "8");
final String[] expected = {
"34:5: " + getCheckMessage(MSG_ERROR, "switch lcurly", 4, 8),
"42:5: " + getCheckMessage(MSG_ERROR, "switch lcurly", 4, 8),
"50:13: " + getCheckMessage(MSG_ERROR, "switch lcurly", 12, 8),
"58:13: " + getCheckMessage(MSG_ERROR, "switch lcurly", 12, 8),
};
verifyWarns(checkConfig,
getNonCompilablePath(
"InputIndentationCheckSwitchExpressionDeclarationLCurlyNewLine.java"),
expected);
}

@Test
public void testIndentationRecords() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,101 +12,51 @@
* forceStrictCondition = false //indent:1 exp:1
*/ //indent:1 exp:1
public class InputIndentationCheckSwitchExpressionDeclaration { //indent:0 exp:0

//indent:82 exp:82
public void validDeclare() { //indent:4 exp:4
String requestId = switch ("in") { //indent:8 exp:8
case "correct" -> "true"; //indent:12 exp:12
default -> "also correct"; //indent:12 exp:12
}; //indent:8 exp:8
} //indent:4 exp:4

public void validDeclareLeftCurlyOnNewLine() { //indent:4 exp:4
String requestId = switch ("in") //indent:8 exp:8
{ //indent:8 exp:8
case "correct" -> "true"; //indent:12 exp:12
default -> "also correct"; //indent:12 exp:12
}; //indent:8 exp:8
} //indent:4 exp:4

//indent:82 exp:82
public void validAssign(String result) { //indent:4 exp:4
result = switch ("in") { //indent:8 exp:8
case "correct" -> "true"; //indent:12 exp:12
default -> "also correct"; //indent:12 exp:12
}; //indent:8 exp:8
} //indent:4 exp:4

public void validAssignLeftCurlyOnNewLine(String result) { //indent:4 exp:4
result = switch ("in") //indent:8 exp:8
{ //indent:8 exp:8
case "correct" -> "true"; //indent:12 exp:12
default -> "also correct"; //indent:12 exp:12
}; //indent:8 exp:8
} //indent:4 exp:4

//indent:82 exp:82
public void invalidDeclareWithBiggerIndent() { //indent:4 exp:4
String requestId = switch ("in") { //indent:8 exp:8
case "correct" -> "true"; //indent:12 exp:12
case "incorrect" -> "true"; //indent:16 exp:12 warn
default -> "also incorrect"; //indent:16 exp:12 warn
}; //indent:8 exp:8
} //indent:4 exp:4

public void invalidDeclareWithBiggerIndentLeftCurlyOnNewLine() { //indent:4 exp:4
String requestId = switch ("in") //indent:8 exp:8
{ //indent:8 exp:8
case "correct" -> "true"; //indent:12 exp:12
case "incorrect" -> "true"; //indent:16 exp:12 warn
default -> "also incorrect"; //indent:16 exp:12 warn
}; //indent:8 exp:8
} //indent:4 exp:4

//indent:82 exp:82
public void invalidAssignWithBiggerIndent(String result) { //indent:4 exp:4
result = switch ("in") { //indent:8 exp:8
case "correct" -> "true"; //indent:12 exp:12
case "incorrect" -> "true"; //indent:16 exp:12 warn
default -> "also incorrect"; //indent:16 exp:12 warn
}; //indent:8 exp:8
} //indent:4 exp:4
public void invalidAssignWithBiggerIndentLeftCurlyOnNewLine(String result) { //indent:4 exp:4
result = switch ("in") //indent:8 exp:8
{ //indent:8 exp:8
case "correct" -> "true"; //indent:12 exp:12
case "incorrect" -> "true"; //indent:16 exp:12 warn
default -> "also incorrect"; //indent:16 exp:12 warn
}; //indent:8 exp:8
} //indent:4 exp:4

//indent:82 exp:82
public void invalidDeclareWithLesserIndent() { //indent:4 exp:4
String requestId = switch ("in") { //indent:8 exp:8
case "correct" -> "true"; //indent:12 exp:12
case "incorrect" -> "true"; //indent:8 exp:12 warn
default -> "also incorrect"; //indent:8 exp:12 warn
}; //indent:8 exp:8
} //indent:4 exp:4

public void invalidDeclareWithLesserIndentLeftCurlyOnNewLine() { //indent:4 exp:4
String requestId = switch ("in") //indent:8 exp:8
{ //indent:8 exp:8
case "correct" -> "true"; //indent:12 exp:12
case "incorrect" -> "true"; //indent:8 exp:12 warn
default -> "also incorrect"; //indent:8 exp:12 warn
}; //indent:8 exp:8
} //indent:4 exp:4

//indent:82 exp:82
public void invalidAssignWithLesserIndent(String result) { //indent:4 exp:4
result = switch ("in") { //indent:8 exp:8
case "correct" -> "true"; //indent:12 exp:12
case "incorrect" -> "true"; //indent:8 exp:12 warn
default -> "also incorrect"; //indent:8 exp:12 warn
}; //indent:8 exp:8
} //indent:4 exp:4

public void invalidAssignWithLesserIndentLeftCurlyOnNewLine(String result) { //indent:4 exp:4
result = switch ("in") //indent:8 exp:8
{ //indent:8 exp:8
case "correct" -> "true"; //indent:12 exp:12
case "incorrect" -> "true"; //indent:8 exp:12 warn
default -> "also incorrect"; //indent:8 exp:12 warn
}; //indent:8 exp:8
} //indent:4 exp:4
} //indent:0 exp:0
} //indent:0 exp:0
//indent:82 exp:82
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//non-compiled with javac: Compilable with Java14 //indent:0 exp:0
package com.puppycrawl.tools.checkstyle.checks.indentation.indentation; //indent:0 exp:0

/* Config: //indent:0 exp:0
* //indent:1 exp:1
* basicOffset = 4 //indent:1 exp:1
* braceAdjustment = 0 //indent:1 exp:1
* caseIndent = 4 //indent:1 exp:1
* throwsIndent = 4 //indent:1 exp:1
* arrayInitIndent = 4 //indent:1 exp:1
* lineWrappingIndentation = 4 //indent:1 exp:1
* forceStrictCondition = false //indent:1 exp:1
*/ //indent:1 exp:1
public class InputIndentationCheckSwitchExpressionDeclarationLCurlyNewLine { //indent:0 exp:0

public void validDeclare() { //indent:4 exp:4
String requestId = switch ("in") //indent:8 exp:8
{ //indent:8 exp:8
case "correct" -> "true"; //indent:12 exp:12
default -> "also correct"; //indent:12 exp:12
}; //indent:8 exp:8
} //indent:4 exp:4

public void validAssign(String result) { //indent:4 exp:4
result = switch ("in") //indent:8 exp:8
{ //indent:8 exp:8
case "correct" -> "true"; //indent:12 exp:12
default -> "also correct"; //indent:12 exp:12
}; //indent:8 exp:8
} //indent:4 exp:4

public void invalidAssignLeftCurlyWithLesserIndent(String result) { //indent:4 exp:4
result = switch ("in") //indent:8 exp:8
{ //indent:4 exp:8 warn
case "correct" -> "true"; //indent:12 exp:12
case "incorrect" -> "true"; //indent:12 exp:12
default -> "also incorrect"; //indent:12 exp:12
}; //indent:8 exp:8
} //indent:4 exp:4
public void invalidDeclareLeftCurlyWithLesserIndent() { //indent:4 exp:4
String result = switch ("in") //indent:8 exp:8
{ //indent:4 exp:8 warn
case "correct" -> "true"; //indent:12 exp:12
case "incorrect" -> "true"; //indent:12 exp:12
default -> "also incorrect"; //indent:12 exp:12
}; //indent:8 exp:8
} //indent:4 exp:4
public void invalidAssignLeftCurlyWithBiggerIndent(String result) { //indent:4 exp:4
result = switch ("in") //indent:8 exp:8
{ //indent:12 exp:8 warn
case "correct" -> "true"; //indent:12 exp:12
case "incorrect" -> "true"; //indent:12 exp:12
default -> "also incorrect"; //indent:12 exp:12
}; //indent:8 exp:8
} //indent:4 exp:4
public void invalidDeclareLeftCurlyWithBiggerIndent() { //indent:4 exp:4
String result = switch ("in") //indent:8 exp:8
{ //indent:12 exp:8 warn
case "correct" -> "true"; //indent:12 exp:12
case "incorrect" -> "true"; //indent:12 exp:12
default -> "also incorrect"; //indent:12 exp:12
}; //indent:8 exp:8
} //indent:4 exp:4
} //indent:0 exp:0

0 comments on commit a9d01fe

Please sign in to comment.