Skip to content

Commit

Permalink
Issue checkstyle#5003: increase coverage of pitest-checks-whitespace …
Browse files Browse the repository at this point in the history
…to 99%
  • Loading branch information
Nimfadora authored and timurt committed Dec 19, 2017
1 parent 58a27de commit d2ba636
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -2072,7 +2072,7 @@
<targetTests>
<param>com.puppycrawl.tools.checkstyle.checks.whitespace.*</param>
</targetTests>
<mutationThreshold>98</mutationThreshold>
<mutationThreshold>99</mutationThreshold>
<timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor>
<timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant>
<threads>${pitest.plugin.threads}</threads>
Expand Down
Expand Up @@ -388,7 +388,7 @@ else if (ident.getLineNo() < ast.getLineNo()) {
}
//ident and lastTypeNode lay on one line
else {
if (ident.getColumnNo() > ast.getColumnNo()
if (ident.getColumnNo() >= ast.getColumnNo() + 1
|| lastTypeNode.getColumnNo() > ident.getColumnNo()) {
previousElement = lastTypeNode;
}
Expand Down
Expand Up @@ -140,12 +140,17 @@ private void visitEachToken(DetailAST node) {
while (sibling != null) {
final int columnNo = sibling.getColumnNo() - 1;

if (columnNo >= 0
// in such expression: "j =123", placed at the start of the string index of the second
// space character will be: 2 = 0(j) + 1(whitespace) + 1(whitespace). It is a minimal
// possible index for the second whitespace between non-whitespace characters.
final int minSecondWhitespaceColumnNo = 2;

if (columnNo >= minSecondWhitespaceColumnNo
&& !isTextSeparatedCorrectlyFromPrevious(getLine(sibling.getLineNo() - 1),
columnNo)) {
log(sibling.getLineNo(), columnNo, MSG_KEY);
}
if (sibling.getChildCount() > 0) {
if (sibling.getChildCount() >= 1) {
visitEachToken(sibling.getFirstChild());
}

Expand Down Expand Up @@ -212,8 +217,7 @@ private static boolean isSpace(String line, int columnNo) {
* {@code columnNo}.
*/
private static boolean isPrecededByMultipleWhitespaces(String line, int columnNo) {
return columnNo >= 1
&& Character.isWhitespace(line.charAt(columnNo))
return Character.isWhitespace(line.charAt(columnNo))
&& Character.isWhitespace(line.charAt(columnNo - 1));
}

Expand All @@ -239,7 +243,7 @@ private static boolean isWhitespace(String line, int columnNo) {
* text on the {@code line}.
*/
private static boolean isFirstInLine(String line, int columnNo) {
return CommonUtils.isBlank(line.substring(0, columnNo + 1));
return CommonUtils.isBlank(line.substring(0, columnNo));
}

/**
Expand Down
Expand Up @@ -20,6 +20,7 @@
package com.puppycrawl.tools.checkstyle.checks.whitespace;

import static com.puppycrawl.tools.checkstyle.checks.whitespace.SingleSpaceSeparatorCheck.MSG_KEY;
import static org.junit.Assert.assertArrayEquals;

import org.junit.Test;

Expand All @@ -41,6 +42,14 @@ public void testNoSpaceErrors() throws Exception {
CommonUtils.EMPTY_STRING_ARRAY);
}

@Test
public void testGetAcceptableTokens() {
final SingleSpaceSeparatorCheck check = new SingleSpaceSeparatorCheck();

assertArrayEquals("Invalid acceptable tockens",
CommonUtils.EMPTY_INT_ARRAY, check.getAcceptableTokens());
}

@Test
public void testSpaceErrors() throws Exception {
final DefaultConfiguration checkConfig =
Expand Down Expand Up @@ -101,6 +110,40 @@ public void testSpaceErrorsAroundComments() throws Exception {
verify(checkConfig, getPath("InputSingleSpaceSeparatorComments.java"), expected);
}

@Test
public void testSpaceErrorsInChildNodes() throws Exception {
final DefaultConfiguration checkConfig =
createModuleConfig(SingleSpaceSeparatorCheck.class);
final String[] expected = {
"5:15: " + getCheckMessage(MSG_KEY),
};

verify(checkConfig, getPath("InputSingleSpaceSeparatorChildNodes.java"), expected);
}

@Test
public void testMinColumnNo() throws Exception {
final DefaultConfiguration checkConfig =
createModuleConfig(SingleSpaceSeparatorCheck.class);
checkConfig.addAttribute("validateComments", String.valueOf(true));
final String[] expected = {
"5:3: " + getCheckMessage(MSG_KEY),
};

verify(checkConfig, getPath("InputSingleSpaceSeparatorMinColumnNo.java"), expected);
}

@Test
public void testWhitespaceInStartOfTheLine() throws Exception {
final DefaultConfiguration checkConfig =
createModuleConfig(SingleSpaceSeparatorCheck.class);
final String[] expected = {
"5:6: " + getCheckMessage(MSG_KEY),
};

verify(checkConfig, getPath("InputSingleSpaceSeparatorStartOfTheLine.java"), expected);
}

@Test
public void testSpaceErrorsIfCommentsIgnored() throws Exception {
final DefaultConfiguration checkConfig =
Expand Down
@@ -0,0 +1,6 @@
package com.puppycrawl.tools.checkstyle.checks.whitespace.singlespaceseparator;

public class InputSingleSpaceSeparatorChildNodes {
int j = 0;
int i = 1 + j;
}
@@ -0,0 +1,6 @@
package com.puppycrawl.tools.checkstyle.checks.whitespace.singlespaceseparator;

public class InputSingleSpaceSeparatorMinColumnNo {
int
j = 0;
}
@@ -0,0 +1,6 @@
package com.puppycrawl.tools.checkstyle.checks.whitespace.singlespaceseparator;

public class InputSingleSpaceSeparatorStartOfTheLine {
int
i = 0;
}

0 comments on commit d2ba636

Please sign in to comment.