Search in sources :

Example 11 with Comment

use of com.puppycrawl.tools.checkstyle.api.Comment in project checkstyle by checkstyle.

the class JavadocUtilsTest method testTagPositions.

@Test
public void testTagPositions() {
    final String[] text = { "/** @see elsewhere", "    also {@link Name value} */" };
    final Comment comment = new Comment(text, 1, 2, text[1].length());
    final List<JavadocTag> tags = JavadocUtils.getJavadocTags(comment, JavadocUtils.JavadocTagType.ALL).getValidTags();
    assertEquals(2, tags.size());
    for (final JavadocTag tag : tags) {
        if (JavadocTagInfo.SEE.getName().equals(tag.getTagName())) {
            assertEquals(1, tag.getLineNo());
            assertEquals(5, tag.getColumnNo());
        } else if (JavadocTagInfo.LINK.getName().equals(tag.getTagName())) {
            assertEquals(2, tag.getLineNo());
            assertEquals(10, tag.getColumnNo());
        } else {
            fail("Unexpected tag: " + tag);
        }
    }
}
Also used : Comment(com.puppycrawl.tools.checkstyle.api.Comment) JavadocTag(com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTag) Test(org.junit.Test)

Example 12 with Comment

use of com.puppycrawl.tools.checkstyle.api.Comment in project checkstyle by checkstyle.

the class CommentsTest method testToString.

@Test
public void testToString() {
    final Comment comment = new Comment(new String[] { "value" }, 1, 2, 3);
    assertWithMessage("Invalid toString result").that(comment.toString()).isEqualTo("Comment[text=[value], startLineNo=2, endLineNo=2, " + "startColNo=1, endColNo=3]");
}
Also used : Comment(com.puppycrawl.tools.checkstyle.api.Comment) Test(org.junit.jupiter.api.Test)

Example 13 with Comment

use of com.puppycrawl.tools.checkstyle.api.Comment in project checkstyle by checkstyle.

the class CommentsTest method testIntersects.

@Test
public void testIntersects() {
    final String[] commentText = { "// compute a single number for start and end", "// to simplify conditional logic" };
    final Comment comment = new Comment(commentText, 9, 89, 53);
    assertWithMessage("Invalid intersection result").that(comment.intersects(89, 9, 89, 41)).isTrue();
    assertWithMessage("Invalid intersection result").that(comment.intersects(89, 53, 90, 50)).isTrue();
    assertWithMessage("Invalid intersection result").that(comment.intersects(87, 7, 88, 9)).isTrue();
    assertWithMessage("Invalid intersection result").that(comment.intersects(90, 7, 91, 20)).isFalse();
    assertWithMessage("Invalid intersection result").that(comment.intersects(89, 56, 89, 80)).isFalse();
}
Also used : Comment(com.puppycrawl.tools.checkstyle.api.Comment) Test(org.junit.jupiter.api.Test)

Example 14 with Comment

use of com.puppycrawl.tools.checkstyle.api.Comment in project checkstyle by checkstyle.

the class JavadocUtilTest method testInlineTagMethodRef.

@Test
public void testInlineTagMethodRef() {
    final String[] text = { "/** {@link List#add(Object)}" };
    final Comment comment = new Comment(text, 1, 1, text[0].length());
    final List<JavadocTag> tags = JavadocUtil.getJavadocTags(comment, JavadocUtil.JavadocTagType.ALL).getValidTags();
    assertWithMessage("Invalid first arg").that(tags.get(0).getFirstArg()).isEqualTo("List#add(Object)");
}
Also used : Comment(com.puppycrawl.tools.checkstyle.api.Comment) InvalidJavadocTag(com.puppycrawl.tools.checkstyle.checks.javadoc.InvalidJavadocTag) JavadocTag(com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTag) Test(org.junit.jupiter.api.Test)

Example 15 with Comment

use of com.puppycrawl.tools.checkstyle.api.Comment in project checkstyle by checkstyle.

the class JavadocUtilTest method testTags.

@Test
public void testTags() {
    final String[] text = { "/** @see elsewhere ", " * {@link List }, {@link List link text }", "   {@link List#add(Object) link text}", " * {@link Class link text}" };
    final Comment comment = new Comment(text, 1, 4, text[3].length());
    final JavadocTags allTags = JavadocUtil.getJavadocTags(comment, JavadocUtil.JavadocTagType.ALL);
    assertWithMessage("Invalid valid tags size").that(allTags.getValidTags()).hasSize(5);
}
Also used : Comment(com.puppycrawl.tools.checkstyle.api.Comment) JavadocTags(com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTags) Test(org.junit.jupiter.api.Test)

Aggregations

Comment (com.puppycrawl.tools.checkstyle.api.Comment)18 Test (org.junit.jupiter.api.Test)11 JavadocTag (com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTag)8 JavadocTags (com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTags)7 Test (org.junit.Test)7 InvalidJavadocTag (com.puppycrawl.tools.checkstyle.checks.javadoc.InvalidJavadocTag)5