This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch bugfix/verbatim-with-code
in repository https://gitbox.apache.org/repos/asf/maven-doxia.git

commit 03cc2defb0d19f7c151fedc99edad4f478fc662d
Author: Konrad Windszus <k...@apache.org>
AuthorDate: Sun Nov 24 20:06:51 2024 +0100

    [DOXIA-763] Distinguish between verbatim source and non-source in
    MarkdownSink
    
    Add non-source verbatim test for all Sink implementations
---
 .../maven/doxia/sink/impl/AbstractSinkTest.java    | 30 +++++++++++++++++++++-
 .../apache/maven/doxia/module/apt/AptSinkTest.java |  5 ++++
 .../maven/doxia/module/markdown/MarkdownSink.java  |  9 +++++--
 .../doxia/module/markdown/MarkdownSinkTest.java    | 15 ++++++++---
 .../maven/doxia/module/xdoc/XdocSinkTest.java      |  5 ++++
 .../maven/doxia/module/xhtml5/Xhtml5SinkTest.java  |  5 ++++
 6 files changed, 62 insertions(+), 7 deletions(-)

diff --git 
a/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/AbstractSinkTest.java
 
b/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/AbstractSinkTest.java
index eddc4958..755b43c3 100644
--- 
a/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/AbstractSinkTest.java
+++ 
b/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/AbstractSinkTest.java
@@ -856,6 +856,26 @@ public abstract class AbstractSinkTest extends 
AbstractModuleTest {
         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
@@ -873,7 +893,7 @@ public abstract class AbstractSinkTest extends 
AbstractModuleTest {
         String actual = testWriter.toString();
         String expected = getVerbatimSourceBlock(text);
 
-        assertEquals(expected, actual, "Wrong verbatim!");
+        assertEquals(expected, actual, "Wrong verbatim source block!");
     }
 
     /**
@@ -1486,6 +1506,14 @@ public abstract class AbstractSinkTest extends 
AbstractModuleTest {
      * 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);
diff --git 
a/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptSinkTest.java
 
b/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptSinkTest.java
index 58caaaf4..c3a06156 100644
--- 
a/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptSinkTest.java
+++ 
b/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptSinkTest.java
@@ -243,6 +243,11 @@ public class AptSinkTest extends AbstractSinkTest {
         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
diff --git 
a/doxia-modules/doxia-module-markdown/src/main/java/org/apache/maven/doxia/module/markdown/MarkdownSink.java
 
b/doxia-modules/doxia-module-markdown/src/main/java/org/apache/maven/doxia/module/markdown/MarkdownSink.java
index 0c1b6b5b..48c36f88 100644
--- 
a/doxia-modules/doxia-module-markdown/src/main/java/org/apache/maven/doxia/module/markdown/MarkdownSink.java
+++ 
b/doxia-modules/doxia-module-markdown/src/main/java/org/apache/maven/doxia/module/markdown/MarkdownSink.java
@@ -28,6 +28,7 @@ import java.util.Collection;
 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;
@@ -552,9 +553,13 @@ public class MarkdownSink extends AbstractTextSink 
implements MarkdownMarkup {
 
     @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());
     }
 
diff --git 
a/doxia-modules/doxia-module-markdown/src/test/java/org/apache/maven/doxia/module/markdown/MarkdownSinkTest.java
 
b/doxia-modules/doxia-module-markdown/src/test/java/org/apache/maven/doxia/module/markdown/MarkdownSinkTest.java
index bafae03e..7cffac3d 100644
--- 
a/doxia-modules/doxia-module-markdown/src/test/java/org/apache/maven/doxia/module/markdown/MarkdownSinkTest.java
+++ 
b/doxia-modules/doxia-module-markdown/src/test/java/org/apache/maven/doxia/module/markdown/MarkdownSinkTest.java
@@ -233,10 +233,16 @@ public class MarkdownSinkTest extends AbstractSinkTest {
     }
 
     /** {@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;
@@ -548,9 +554,10 @@ public class MarkdownSinkTest extends AbstractSinkTest {
             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!");
     }
 
diff --git 
a/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocSinkTest.java
 
b/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocSinkTest.java
index d1c5ad77..2d4929e0 100644
--- 
a/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocSinkTest.java
+++ 
b/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocSinkTest.java
@@ -258,6 +258,11 @@ public class XdocSinkTest extends AbstractSinkTest {
         return "<div>" + text + "</div>";
     }
 
+    /** {@inheritDoc} */
+    protected String getVerbatimBlock(String text) {
+        return "<pre>" + text + "</pre>";
+    }
+
     /** {@inheritDoc} */
     protected String getVerbatimSourceBlock(String text) {
         return "<source>" + text + "</source>";
diff --git 
a/doxia-modules/doxia-module-xhtml5/src/test/java/org/apache/maven/doxia/module/xhtml5/Xhtml5SinkTest.java
 
b/doxia-modules/doxia-module-xhtml5/src/test/java/org/apache/maven/doxia/module/xhtml5/Xhtml5SinkTest.java
index c5c1bf36..47789cd6 100644
--- 
a/doxia-modules/doxia-module-xhtml5/src/test/java/org/apache/maven/doxia/module/xhtml5/Xhtml5SinkTest.java
+++ 
b/doxia-modules/doxia-module-xhtml5/src/test/java/org/apache/maven/doxia/module/xhtml5/Xhtml5SinkTest.java
@@ -253,6 +253,11 @@ public class Xhtml5SinkTest extends AbstractSinkTest {
         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>";

Reply via email to