@Test public void testHasIntersectionWithBlockComment() { final FileContents fileContents = new FileContents(new FileText(new File("filename"), Arrays.asList(" /* */ ", " ", " /* test ", " */ ", " "))); fileContents.reportCComment(1, 2, 1, 5); fileContents.reportCComment(3, 2, 4, 2); assertTrue("Should return true when comments intersect", fileContents.hasIntersectionWithComment(2, 2, 3, 6)); }
@Test public void testExtractBlockComment() { final FileContents fileContents = new FileContents( new FileText(new File("filename"), Arrays.asList(" ", " ", " /* test ", " */ ", " "))); fileContents.reportCComment(3, 2, 4, 2); final Map<Integer, List<TextBlock>> blockComments = fileContents.getBlockComments(); final String[] text = blockComments.get(3).get(0).getText(); assertArrayEquals("Invalid comment text", new String[] {"/* test ", " *"}, text); }
@Test public void testReportComment() { final FileContents fileContents = new FileContents( new FileText(new File("filename"), Collections.singletonList(" // "))); fileContents.reportCComment(1, 2, 1, 2); final Map<Integer, List<TextBlock>> comments = fileContents.getCComments(); assertEquals("Invalid comment", new Comment(new String[] {"/"}, 2, 1, 2).toString(), comments.get(1).get(0).toString()); }
@Test public void testHasIntersectionWithBlockComment2() { final FileContents fileContents = new FileContents( new FileText(new File("filename"), Arrays.asList(" /* */ ", " ", " "))); fileContents.reportCComment(1, 2, 1, 5); assertFalse("Should return false when there is no intersection", fileContents.hasIntersectionWithComment(2, 2, 3, 6)); }
@Test public void testReportJavadocComment() { final FileContents fileContents = new FileContents( new FileText(new File("filename"), Collections.singletonList(" /** */ "))); fileContents.reportCComment(1, 2, 1, 6); final TextBlock comment = fileContents.getJavadocBefore(2); assertEquals("Invalid comment", new Comment(new String[] {"/** *"}, 2, 1, 6).toString(), comment.toString()); }
@Test public void testDeprecatedAbbreviatedMethod() { // just to make UT coverage 100% final FileContents fileContents = new FileContents("filename", "123", "456"); fileContents.reportCppComment(1, 1); fileContents.reportCComment(1, 1, 1, 1); final Comment cppComment = new Comment(new String[] {"23"}, 1, 1, 2); final Comment cComment = new Comment(new String[] {"2"}, 1, 1, 1); assertEquals("Invalid cpp comment", cppComment.toString(), fileContents.getCppComments().get(1).toString()); assertEquals("Invalid c comment", cComment.toString(), fileContents.getCComments().get(1).get(0).toString()); }
@Test public void testReportJavadocComment2() { final FileContents fileContents = new FileContents("filename", " /** */ "); fileContents.reportCComment(1, 2, 1, 6); final TextBlock comment = fileContents.getJavadocBefore(2); assertEquals("Invalid comment", new Comment(new String[] {"/** *"}, 2, 1, 6).toString(), comment.toString()); }