Skip to content

Commit

Permalink
[DOXIA-763] Distinguish between verbatim source and non-source in
Browse files Browse the repository at this point in the history
MarkdownSink

Add non-source verbatim test for all Sink implementations
  • Loading branch information
kwin committed Nov 25, 2024
1 parent c36b516 commit ac99291
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,26 @@ public void testDivider() {
assertEquals(expected, actual, "Wrong division!");
}

/**
* Checks that the sequence <code>[verbatim(null), text(text),
* verbatim_()]</code>, invoked on the current sink, produces the
* same result as {@link #getVerbatimeBlock getVerbatimBlock}(text).
*/
@Test
public void testVerbatim() {
String text = "Text";
sink.verbatim(null);
sink.text(text);
sink.verbatim_();
sink.flush();
sink.close();

String actual = testWriter.toString();
String expected = getVerbatimBlock(text);

assertEquals(expected, actual, "Wrong verbatim!");
}

/**
* Checks that the sequence <code>[verbatim(SinkEventAttributeSet.SOURCE), text(text),
* verbatim_()]</code>, invoked on the current sink, produces the
Expand All @@ -873,7 +893,7 @@ public void testVerbatimSource() {
String actual = testWriter.toString();
String expected = getVerbatimSourceBlock(text);

assertEquals(expected, actual, "Wrong verbatim!");
assertEquals(expected, actual, "Wrong verbatim source block!");
}

/**
Expand Down Expand Up @@ -1486,6 +1506,14 @@ protected String getOutputDir() {
* Returns a Verbatim block generated by this sink.
* @param text The text to use.
* @return The result of invoking a Verbatim block on the current sink.
* @see #testVerbatim()
*/
protected abstract String getVerbatimBlock(String text);

/**
* Returns a Verbatim source block generated by this sink.
* @param text The text to use.
* @return The result of invoking a Verbatim source block on the current sink.
* @see #testVerbatimSource()
*/
protected abstract String getVerbatimSourceBlock(String text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ protected String getDivisionBlock(String text) {
return text;
}

/** {@inheritDoc} */
protected String getVerbatimBlock(String text) {
return EOL + EOL + AptMarkup.VERBATIM_START_MARKUP + EOL + text + EOL + AptMarkup.VERBATIM_START_MARKUP + EOL;
}

/** {@inheritDoc} */
protected String getVerbatimSourceBlock(String text) {
return EOL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Queue;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -552,9 +553,13 @@ public void paragraph_() {

@Override
public void verbatim(SinkEventAttributes attributes) {
// always assume is supposed to be monospaced (i.e. emitted inside a <pre><code>...</code></pre>)
// if no source attribute, then don't emit an info string
startContext(ElementContext.CODE_BLOCK);
writeUnescaped(VERBATIM_START_MARKUP + EOL);
writeUnescaped(VERBATIM_START_MARKUP);
if (attributes != null && attributes.containsAttributes(SinkEventAttributeSet.SOURCE)) {
writeUnescaped("unknown"); // unknown language
}
writeUnescaped(EOL);
writeUnescaped(getLinePrefix());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,16 @@ protected String getDivisionBlock(String text) {
}

/** {@inheritDoc} */
protected String getVerbatimSourceBlock(String text) {
protected String getVerbatimBlock(String text) {
return MarkdownMarkup.VERBATIM_START_MARKUP + EOL + text + EOL + MarkdownMarkup.VERBATIM_END_MARKUP + EOL + EOL;
}

/** {@inheritDoc} */
protected String getVerbatimSourceBlock(String text) {
return MarkdownMarkup.VERBATIM_START_MARKUP + "unknown" + EOL + text + EOL + MarkdownMarkup.VERBATIM_END_MARKUP
+ EOL + EOL;
}

/** {@inheritDoc} */
protected String getHorizontalRuleBlock() {
return MarkdownMarkup.HORIZONTAL_RULE_MARKUP + EOL + EOL;
Expand Down Expand Up @@ -548,9 +554,10 @@ public void testMultilineVerbatimSourceAfterListItem() {
sink.list_();
}

String expected = "- Before" + EOL + EOL + MarkdownMarkup.INDENT + MarkdownMarkup.VERBATIM_START_MARKUP + EOL
+ MarkdownMarkup.INDENT + "codeline1" + EOL + MarkdownMarkup.INDENT + "codeline2" + EOL
+ MarkdownMarkup.INDENT + MarkdownMarkup.VERBATIM_END_MARKUP + EOL + EOL + "After" + EOL;
String expected =
"- Before" + EOL + EOL + MarkdownMarkup.INDENT + MarkdownMarkup.VERBATIM_START_MARKUP + "unknown" + EOL
+ MarkdownMarkup.INDENT + "codeline1" + EOL + MarkdownMarkup.INDENT + "codeline2" + EOL
+ MarkdownMarkup.INDENT + MarkdownMarkup.VERBATIM_END_MARKUP + EOL + EOL + "After" + EOL;
assertEquals(expected, getSinkContent(), "Wrong verbatim!");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ protected String getDivisionBlock(String text) {
return "<div>" + text + "</div>";
}

/** {@inheritDoc} */
protected String getVerbatimBlock(String text) {
return "<pre>" + text + "</pre>";
}

/** {@inheritDoc} */
protected String getVerbatimSourceBlock(String text) {
return "<source>" + text + "</source>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ protected String getDivisionBlock(String text) {
return "<div>" + text + "</div>";
}

/** {@inheritDoc} */
protected String getVerbatimBlock(String text) {
return "<pre>" + text + "</pre>";
}

/** {@inheritDoc} */
protected String getVerbatimSourceBlock(String text) {
return "<pre><code>" + text + "</code></pre>";
Expand Down

0 comments on commit ac99291

Please sign in to comment.