Skip to content
This repository has been archived by the owner on Sep 22, 2022. It is now read-only.

Commit

Permalink
Issue checkstyle#4398: increase coverage of pitest-checkstyle-tree-wa…
Browse files Browse the repository at this point in the history
…lker profile to 94%
  • Loading branch information
Nimfadora committed Jul 6, 2017
1 parent 92470b5 commit 0945cd5
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
5 changes: 4 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2078,7 +2078,10 @@
<param>com.puppycrawl.tools.checkstyle.checks.sizes.*</param>
<param>com.puppycrawl.tools.checkstyle.checks.whitespace.*</param>
</targetTests>
<mutationThreshold>89</mutationThreshold>
<excludedMethods>
<param>destroy</param>
</excludedMethods>
<mutationThreshold>94</mutationThreshold>
<timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor>
<timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant>
<threads>${pitest.plugin.threads}</threads>
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/puppycrawl/tools/checkstyle/TreeWalker.java
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,6 @@ private static DetailAST createSlCommentNode(Token token) {
slComment.setLineNo(token.getLine());

final DetailAST slCommentContent = new DetailAST();
slCommentContent.initialize(token);
slCommentContent.setType(TokenTypes.COMMENT_CONTENT);

// column counting begins from 0
Expand Down Expand Up @@ -658,7 +657,6 @@ private static DetailAST createBlockCommentNode(Token token) {
blockComment.setLineNo(token.getLine());

final DetailAST blockCommentContent = new DetailAST();
blockCommentContent.initialize(token);
blockCommentContent.setType(TokenTypes.COMMENT_CONTENT);

// column counting begins from 0
Expand Down
40 changes: 40 additions & 0 deletions src/test/java/com/puppycrawl/tools/checkstyle/TreeWalkerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -46,12 +47,14 @@
import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
import com.puppycrawl.tools.checkstyle.api.Context;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.checks.coding.HiddenFieldCheck;
import com.puppycrawl.tools.checkstyle.checks.indentation.CommentsIndentationCheck;
import com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck;
import com.puppycrawl.tools.checkstyle.checks.naming.ConstantNameCheck;
import com.puppycrawl.tools.checkstyle.checks.naming.TypeNameCheck;
import com.puppycrawl.tools.checkstyle.internal.TestUtils;
import com.puppycrawl.tools.checkstyle.utils.CommonUtils;

public class TreeWalkerTest extends BaseCheckTestSupport {
Expand Down Expand Up @@ -360,6 +363,43 @@ public void testBehaviourWithOrdinaryAndCommentChecks() throws Exception {
}
}

@Test
public void testAppendHiddenBlockCommentNodes() throws Exception {
final DetailAST root =
TestUtils.parseFile(new File(getPath("InputTreeWalkerHiddenComments.java")));

final Optional<DetailAST> blockComment = TestUtils.findTokenInAstByPredicate(root,
ast -> ast.getType() == TokenTypes.BLOCK_COMMENT_BEGIN);

assertTrue(blockComment.isPresent());

final DetailAST commentContent = blockComment.get().getFirstChild();
final DetailAST commentEnd = blockComment.get().getLastChild();

assertEquals("Unexpected line number", 3, commentContent.getLineNo());
assertEquals("Unexpected column number", 2, commentContent.getColumnNo());
assertEquals("Unexpected line number", 9, commentEnd.getLineNo());
assertEquals("Unexpected column number", 1, commentEnd.getColumnNo());
}

@Test
public void testAppendHiddenSingleLineCommentNodes() throws Exception {
final DetailAST root =
TestUtils.parseFile(new File(getPath("InputTreeWalkerHiddenComments.java")));

final Optional<DetailAST> singleLineComment = TestUtils.findTokenInAstByPredicate(root,
ast -> ast.getType() == TokenTypes.SINGLE_LINE_COMMENT);
assertTrue(singleLineComment.isPresent());

final DetailAST commentContent = singleLineComment.get().getFirstChild();

assertEquals("Unexpected token type", TokenTypes.COMMENT_CONTENT, commentContent.getType());
assertEquals("Unexpected line number", 13, commentContent.getLineNo());
assertEquals("Unexpected column number", 2, commentContent.getColumnNo());
assertTrue("Unexpected comment content",
commentContent.getText().startsWith(" inline comment"));
}

@Test
public void testFinishLocalSetupFullyInitialized() throws Exception {
final TreeWalker treeWalker = new TreeWalker();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.puppycrawl.tools.checkstyle;

/**
* Some Javadoc.
*
* <p>{@code function} will never be invoked with a null value.
*
* @since 8.0
*/
public class InputTreeWalkerHiddenComments {

}
// inline comment

0 comments on commit 0945cd5

Please sign in to comment.