@Test public void testTagRender() { Doc mockDoc = mock(Doc.class); Tag mockTag = mock(Tag.class); String tagName = "tagName"; String tagText = "tagText"; String asciidoctorRenderedString = "rendered"; when(mockTag.name()).thenReturn(tagName); when(mockTag.text()).thenReturn(tagText); when(mockDoc.getRawCommentText()).thenReturn("input"); when(mockDoc.commentText()).thenReturn("input"); when(mockDoc.tags()).thenReturn(new Tag[] {mockTag}); when(mockAsciidoctor.render(eq("input"), argThat(new OptionsMatcher(false)))) .thenReturn("input"); when(mockAsciidoctor.render(eq(tagText), argThat(new OptionsMatcher(true)))) .thenReturn(asciidoctorRenderedString); renderer.renderDoc(mockDoc); verify(mockAsciidoctor).render(eq("input"), argThat(new OptionsMatcher(false))); verify(mockAsciidoctor).render(eq(tagText), argThat(new OptionsMatcher(true))); verify(mockDoc).setRawCommentText("input"); verify(mockDoc).setRawCommentText("input\n" + tagName + " " + asciidoctorRenderedString + "\n"); }
/** * Determine if the program element is shown, according to the given level of visibility. * * @param ped The given program element. * @param visLevel The desired visibility level; "public", "protected", "package" or "private". If * null, only check for an exclude tag. * @return boolean Set if this element is shown. */ public boolean shownElement(Doc doc, String visLevel) { // If a doc block contains @exclude or a similar such tag, // then don't display it. if (doExclude && excludeTag != null && doc != null) { String rct = doc.getRawCommentText(); if (rct != null && rct.indexOf(excludeTag) != -1) { return false; } } if (visLevel == null) { return true; } ProgramElementDoc ped = null; if (doc instanceof ProgramElementDoc) { ped = (ProgramElementDoc) doc; } if (visLevel.compareTo("private") == 0) return true; // Show all that is not private if (visLevel.compareTo("package") == 0) return !ped.isPrivate(); // Show all that is not private or package if (visLevel.compareTo("protected") == 0) return !(ped.isPrivate() || ped.isPackagePrivate()); // Show all that is not private or package or protected, // i.e. all that is public if (visLevel.compareTo("public") == 0) return ped.isPublic(); return false; } // shownElement()
@Test public void testAtLiteralRender() { Doc mockDoc = mock(Doc.class); String convertedText = "Test"; String rawText = "@" + convertedText; when(mockDoc.getRawCommentText()).thenReturn(rawText); when(mockDoc.commentText()).thenReturn("input"); when(mockDoc.tags()).thenReturn(new Tag[] {}); when(mockAsciidoctor.render(anyString(), any(Options.class))).thenReturn("input"); renderer.renderDoc(mockDoc); verify(mockDoc).setRawCommentText("{@literal @}" + convertedText); verify(mockAsciidoctor).render(anyString(), any(Options.class)); }
@Test public void testParamTagWithTypeParameter() { String commentText = "comment"; String param1Name = "T"; String param1Desc = ""; String param1Text = "<" + param1Name + ">"; String param2Name = "X"; String param2Desc = "description"; String param2Text = "<" + param2Name + "> " + param2Desc; String sourceText = commentText + "\n@param " + param1Text + "\n@param " + param2Text; Doc mockDoc = mock(Doc.class); when(mockDoc.getRawCommentText()).thenReturn(sourceText); when(mockDoc.commentText()).thenReturn(commentText); Tag[] tags = new Tag[2]; ParamTag mockTag1 = mock(ParamTag.class); when(mockTag1.name()).thenReturn("@param"); when(mockTag1.isTypeParameter()).thenReturn(true); when(mockTag1.parameterName()).thenReturn(param1Name); when(mockTag1.parameterComment()).thenReturn(param1Desc); tags[0] = mockTag1; ParamTag mockTag2 = mock(ParamTag.class); when(mockTag2.name()).thenReturn("@param"); when(mockTag2.isTypeParameter()).thenReturn(true); when(mockTag2.parameterName()).thenReturn(param2Name); when(mockTag2.parameterComment()).thenReturn(param2Desc); tags[1] = mockTag2; when(mockDoc.tags()).thenReturn(tags); when(mockAsciidoctor.render(eq(commentText), any(Options.class))).thenReturn(commentText); when(mockAsciidoctor.render(eq(param2Desc), any(Options.class))).thenReturn(param2Desc); renderer.renderDoc(mockDoc); verify(mockAsciidoctor).render(eq(commentText), argThat(new OptionsMatcher(false))); verify(mockAsciidoctor).render(eq(param2Desc), argThat(new OptionsMatcher(true))); // fixture step verify(mockDoc).setRawCommentText(eq(sourceText)); // result step verify(mockDoc).setRawCommentText(eq(sourceText)); }
/** Returns true if the given element has an @hide or @pending annotation. */ private static boolean hasHideAnnotation(Doc doc) { String comment = doc.getRawCommentText(); return comment.indexOf("@hide") != -1 || comment.indexOf("@pending") != -1; }
public String getRawCommentText() { return mDoc.getRawCommentText(); }