Skip to content

Commit 578a262

Browse files
Praveen7294romani
authored andcommitted
Issue #16869: Added missing test for InputIndentationInvalidArrayInitIndent.java
1 parent 3e81a4a commit 578a262

File tree

4 files changed

+310
-105
lines changed

4 files changed

+310
-105
lines changed

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

Lines changed: 180 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,28 +1510,34 @@ public void testInvalidArrayInitWithTrueStrictCondition()
15101510
"22:7: " + getCheckMessage(MSG_ERROR, "member def type", 6, 4),
15111511
"24:3: " + getCheckMessage(MSG_ERROR, "member def type", 2, 4),
15121512
"28:7: " + getCheckMessage(MSG_ERROR, "member def type", 6, 4),
1513-
"29:9: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 8, 10),
1513+
"29:9: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 8,
1514+
"10, 34, 36"),
15141515
"30:5: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 4, "6, 10"),
1515-
"33:10: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 9, 8),
1516-
"34:8: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 7, 8),
1517-
"35:10: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 9, 8),
1516+
"33:10: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 9,
1517+
"8, 31, 33"),
1518+
"34:8: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 7,
1519+
"8, 31, 33"),
1520+
"35:10: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 9,
1521+
"8, 31, 33"),
15181522
"40:3: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization lcurly", 2, "4, 8"),
15191523
"44:7: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 6, "4, 8"),
15201524
"48:3: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization lcurly", 2, "4, 8"),
15211525
"52:21: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 20,
15221526
"8, 31, 33"),
15231527
"53:5: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization",
15241528
4, "8, 31, 33"),
1525-
"58:7: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 6, 8),
1529+
"58:7: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization",
1530+
6, "8, 31, 33"),
15261531
"63:3: " + getCheckMessage(MSG_ERROR, "member def type", 2, 4),
15271532
"65:7: " + getCheckMessage(MSG_ERROR, "member def type", 6, 4),
15281533
"66:3: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 2, "6, 10"),
1529-
"69:7: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 6, 8),
1530-
"76:11: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 10, 12),
1534+
"69:7: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization",
1535+
6, "8, 36, 38"),
1536+
"76:11: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization",
1537+
10, "12, 24, 26"),
15311538
};
15321539

1533-
// Test input for this test case is not checked due to issue #693.
1534-
verify(checkConfig, fileName, expected);
1540+
verifyWarns(checkConfig, fileName, expected);
15351541
}
15361542

15371543
@Test
@@ -1550,29 +1556,184 @@ public void testInvalidArrayInitWithTrueStrictCondition1()
15501556
final String fileName = getPath("InputIndentationInvalidArrayInitIndent1.java");
15511557
final String[] expected = {
15521558
"28:9: " + getCheckMessage(MSG_ERROR, "1", 8, 12),
1553-
"39:11: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 10, 12),
1554-
"40:15: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 14, 12),
1555-
"43:11: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 10, 12),
1556-
"44:15: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 14, 12),
1559+
"39:11: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 10,
1560+
"12, 30, 32"),
1561+
"40:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 14,
1562+
"12, 30, 32"),
1563+
"43:11: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 10,
1564+
"12, 31, 32"),
1565+
"44:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 14,
1566+
"12, 31, 32"),
15571567
"45:7: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 6, "8, 12"),
15581568
"48:7: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization lcurly", 6, "8, 12"),
1559-
"49:15: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 14, 12),
1560-
"50:11: " + getCheckMessage(MSG_CHILD_ERROR, "array initialization", 10, 12),
1569+
"49:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 14,
1570+
"8, 10, 12"),
1571+
"51:7: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 6, "8, 12"),
1572+
// following are tests for annotation array initialization
1573+
"59:13: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1574+
12, "16, 46, 48"),
1575+
"67:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1576+
14, "16, 28, 30"),
1577+
"68:9: " + getCheckMessage(MSG_ERROR_MULTI, "annotation array initialization rcurly",
1578+
8, "12, 16"),
1579+
"70:13: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1580+
12, "16, 29, 31"),
1581+
};
1582+
1583+
verifyWarns(checkConfig, fileName, expected);
1584+
}
1585+
1586+
@Test
1587+
public void testInvalidArrayInitWithFalseStrictCondition()
1588+
throws Exception {
1589+
final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1590+
1591+
checkConfig.addProperty("arrayInitIndent", "4");
1592+
checkConfig.addProperty("basicOffset", "4");
1593+
checkConfig.addProperty("braceAdjustment", "0");
1594+
checkConfig.addProperty("caseIndent", "4");
1595+
checkConfig.addProperty("forceStrictCondition", "false");
1596+
checkConfig.addProperty("lineWrappingIndentation", "4");
1597+
checkConfig.addProperty("tabWidth", "4");
1598+
checkConfig.addProperty("throwsIndent", "4");
1599+
final String fileName = getPath("InputIndentationInvalidArrayInitIndent.java");
1600+
final String[] expected = {
1601+
"21:3: " + getCheckMessage(MSG_ERROR, "member def type", 2, 4),
1602+
"22:7: " + getCheckMessage(MSG_ERROR, "member def type", 6, 4),
1603+
"24:3: " + getCheckMessage(MSG_ERROR, "member def type", 2, 4),
1604+
"28:7: " + getCheckMessage(MSG_ERROR, "member def type", 6, 4),
1605+
"29:9: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 8,
1606+
"10, 34, 36"),
1607+
"30:5: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 4, "6, 10"),
1608+
"33:10: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 9,
1609+
"8, 31, 33"),
1610+
"34:8: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 7,
1611+
"8, 31, 33"),
1612+
"35:10: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 9,
1613+
"8, 31, 33"),
1614+
"40:3: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization lcurly", 2, "4, 8"),
1615+
"44:7: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 6, "4, 8"),
1616+
"48:3: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization lcurly", 2, "4, 8"),
1617+
"52:21: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 20,
1618+
"8, 31, 33"),
1619+
"53:5: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization",
1620+
4, "8, 31, 33"),
1621+
"58:7: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization",
1622+
6, "8, 31, 33"),
1623+
"63:3: " + getCheckMessage(MSG_ERROR, "member def type", 2, 4),
1624+
"65:7: " + getCheckMessage(MSG_ERROR, "member def type", 6, 4),
1625+
"66:3: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 2, "6, 10"),
1626+
"69:7: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization",
1627+
6, "8, 36, 38"),
1628+
"76:11: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization",
1629+
10, "12, 24, 26"),
1630+
};
1631+
1632+
verifyWarns(checkConfig, fileName, expected);
1633+
}
1634+
1635+
@Test
1636+
public void testInvalidArrayInitWithFalseStrictCondition1()
1637+
throws Exception {
1638+
final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1639+
1640+
checkConfig.addProperty("arrayInitIndent", "4");
1641+
checkConfig.addProperty("basicOffset", "4");
1642+
checkConfig.addProperty("braceAdjustment", "0");
1643+
checkConfig.addProperty("caseIndent", "4");
1644+
checkConfig.addProperty("forceStrictCondition", "false");
1645+
checkConfig.addProperty("lineWrappingIndentation", "4");
1646+
checkConfig.addProperty("tabWidth", "4");
1647+
checkConfig.addProperty("throwsIndent", "4");
1648+
final String fileName = getPath("InputIndentationInvalidArrayInitIndent1.java");
1649+
final String[] expected = {
1650+
"28:9: " + getCheckMessage(MSG_ERROR, "1", 8, 12),
1651+
"39:11: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 10,
1652+
"12, 30, 32"),
1653+
"40:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 14,
1654+
"12, 30, 32"),
1655+
"43:11: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 10,
1656+
"12, 31, 32"),
1657+
"44:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 14,
1658+
"12, 31, 32"),
1659+
"45:7: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 6, "8, 12"),
1660+
"48:7: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization lcurly", 6, "8, 12"),
1661+
"49:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "array initialization", 14,
1662+
"8, 10, 12"),
15611663
"51:7: " + getCheckMessage(MSG_ERROR_MULTI, "array initialization rcurly", 6, "8, 12"),
15621664
// following are tests for annotation array initialization
15631665
"59:13: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
15641666
12, "16, 46, 48"),
1565-
"63:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1566-
14, "12, 16"),
15671667
"67:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
15681668
14, "16, 28, 30"),
15691669
"68:9: " + getCheckMessage(MSG_ERROR_MULTI, "annotation array initialization rcurly",
15701670
8, "12, 16"),
1571-
"70:13: " + getCheckMessage(MSG_CHILD_ERROR, "annotation array initialization",
1671+
"70:13: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1672+
12, "16, 29, 31"),
1673+
};
1674+
1675+
verifyWarns(checkConfig, fileName, expected);
1676+
}
1677+
1678+
// Test Input without trailing comment and usage of 'verify' method is due to #16906
1679+
@Test
1680+
public void testInvalidArrayInitIndentNoCommentsTrueStrictCondition()
1681+
throws Exception {
1682+
final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1683+
1684+
checkConfig.addProperty("arrayInitIndent", "4");
1685+
checkConfig.addProperty("basicOffset", "4");
1686+
checkConfig.addProperty("braceAdjustment", "0");
1687+
checkConfig.addProperty("caseIndent", "4");
1688+
checkConfig.addProperty("forceStrictCondition", "true");
1689+
checkConfig.addProperty("lineWrappingIndentation", "4");
1690+
checkConfig.addProperty("tabWidth", "4");
1691+
checkConfig.addProperty("throwsIndent", "4");
1692+
final String fileName = getPath(
1693+
"InputIndentationInvalidArrayInitIndentWithoutTrailingComments.java");
1694+
final String[] expected = {
1695+
"28:13: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1696+
12, "16, 46, 48"),
1697+
"32:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1698+
14, "12, 16"),
1699+
"36:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1700+
14, "16, 28, 30"),
1701+
"37:9: " + getCheckMessage(MSG_ERROR_MULTI, "annotation array initialization rcurly",
1702+
8, "12, 16"),
1703+
"39:13: " + getCheckMessage(MSG_CHILD_ERROR, "annotation array initialization",
15721704
12, 16),
15731705
};
1706+
verify(checkConfig, fileName, expected);
1707+
}
15741708

1575-
// Test input for this test case is not checked due to issue #693.
1709+
// Test Input without trailing comment and usage of 'verify' method is due to #16906
1710+
@Test
1711+
public void testInvalidArrayInitIndentNoCommentsFalseStrictCondition()
1712+
throws Exception {
1713+
final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
1714+
1715+
checkConfig.addProperty("arrayInitIndent", "4");
1716+
checkConfig.addProperty("basicOffset", "4");
1717+
checkConfig.addProperty("braceAdjustment", "0");
1718+
checkConfig.addProperty("caseIndent", "4");
1719+
checkConfig.addProperty("forceStrictCondition", "false");
1720+
checkConfig.addProperty("lineWrappingIndentation", "4");
1721+
checkConfig.addProperty("tabWidth", "4");
1722+
checkConfig.addProperty("throwsIndent", "4");
1723+
final String fileName = getPath(
1724+
"InputIndentationInvalidArrayInitIndentWithoutTrailingComments.java");
1725+
final String[] expected = {
1726+
"28:13: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1727+
12, "16, 46, 48"),
1728+
"32:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1729+
14, "12, 16"),
1730+
"36:15: " + getCheckMessage(MSG_CHILD_ERROR_MULTI, "annotation array initialization",
1731+
14, "16, 28, 30"),
1732+
"37:9: " + getCheckMessage(MSG_ERROR_MULTI, "annotation array initialization rcurly",
1733+
8, "12, 16"),
1734+
"39:13: " + getCheckMessage(MSG_CHILD_ERROR, "annotation array initialization",
1735+
12, 16),
1736+
};
15761737
verify(checkConfig, fileName, expected);
15771738
}
15781739

src/test/resources/com/puppycrawl/tools/checkstyle/checks/indentation/indentation/InputIndentationInvalidArrayInitIndent.java

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,64 +16,64 @@
1616
*/ //indent:1 exp:1
1717
public class InputIndentationInvalidArrayInitIndent { //indent:0 exp:0
1818

19-
int[] array = new int[] {1, 2, 3};
19+
int[] array = new int[] {1, 2, 3}; //indent:4 exp:4
2020

21-
int[] arrayb = new int[] {1, 2, 3};
22-
int[] arrayc = new int[] {1, 2, 3};
21+
int[] arrayb = new int[] {1, 2, 3}; //indent:2 exp:4 warn
22+
int[] arrayc = new int[] {1, 2, 3}; //indent:6 exp:4 warn
2323

24-
int[] array2 = new int[] {
25-
1, 2, 3
26-
};
24+
int[] array2 = new int[] { //indent:2 exp:4 warn
25+
1, 2, 3 //indent:6 exp:6
26+
}; //indent:6 exp:6
2727

28-
int[] array2b = new int[] {
29-
1, 2, 3
30-
};
28+
int[] array2b = new int[] { //indent:6 exp:4 warn
29+
1, 2, 3 //indent:8 exp:10,34,36 warn
30+
}; //indent:4 exp:6,10 warn
3131

32-
int[] array3 = new int[] {
33-
1,
34-
2,
35-
3
36-
};
32+
int[] array3 = new int[] { //indent:4 exp:4
33+
1, //indent:9 exp:8,31,33 warn
34+
2, //indent:7 exp:8,31,33 warn
35+
3 //indent:9 exp:8,31,33 warn
36+
}; //indent:4 exp:4
3737

3838

39-
int[] array4 = new int[]
40-
{
41-
1,
42-
2,
43-
3
44-
};
39+
int[] array4 = new int[] //indent:4 exp:4
40+
{ //indent:2 exp:4,8 warn
41+
1, //indent:8 exp:8
42+
2, //indent:8 exp:8
43+
3 //indent:8 exp:8
44+
}; //indent:6 exp:4,8 warn
4545

4646

47-
int[] array5 = new int[]
48-
{1, 2, 3};
47+
int[] array5 = new int[] //indent:4 exp:4
48+
{1, 2, 3}; //indent:2 exp:4,8 warn
4949

5050

51-
int[] array6 = new int[] { 1, 2,
52-
3,
53-
4,};
51+
int[] array6 = new int[] { 1, 2, //indent:4 exp:4
52+
3, //indent:20 exp:8,31,33 warn
53+
4,}; //indent:4 exp:8,31,33 warn
5454

5555

5656

57-
int[] array7 = new int[] {
58-
1, 2,
59-
3
60-
};
57+
int[] array7 = new int[] { //indent:4 exp:4
58+
1, 2, //indent:6 exp:8,31,33 warn
59+
3 //indent:8 exp:8
60+
}; //indent:4 exp:4
6161

6262

63-
int[] array8 = new int[] { };
63+
int[] array8 = new int[] { }; //indent:2 exp:4 warn
6464

65-
int[] array9 = new int[] {
66-
};
65+
int[] array9 = new int[] { //indent:6 exp:4 warn
66+
}; //indent:2 exp:6,10 warn
6767

68-
int[][] array10 = new int[][] {
69-
new int[] { 1, 2, 3},
70-
new int[] { 1, 2, 3},
71-
};
68+
int[][] array10 = new int[][] { //indent:4 exp:4
69+
new int[] { 1, 2, 3}, //indent:6 exp:8,36,38 warn
70+
new int[] { 1, 2, 3}, //indent:8 exp:8
71+
}; //indent:4 exp:4
7272

7373

74-
int[][] array10b
75-
= new int[][] {
76-
new int[] { 1, 2, 3},
77-
new int[] { 1, 2, 3},
78-
};
74+
int[][] array10b //indent:4 exp:4
75+
= new int[][] { //indent:8 exp:8
76+
new int[] { 1, 2, 3}, //indent:10 exp:12,24,26 warn
77+
new int[] { 1, 2, 3}, //indent:12 exp:12
78+
}; //indent:8 exp:8
7979
} //indent:0 exp:0

0 commit comments

Comments
 (0)