svn commit: r1807920 - in /maven/doxia/doxia/trunk: doxia-core/src/main/java/org/apache/maven/doxia/index/ doxia-core/src/test/java/org/apache/maven/doxia/parser/ doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/ doxia-mod...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1807920 - in /maven/doxia/doxia/trunk: doxia-core/src/main/java/org/apache/maven/doxia/index/ doxia-core/src/test/java/org/apache/maven/doxia/parser/ doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/ doxia-mod...

hboutemy
Author: hboutemy
Date: Sat Sep  9 19:33:43 2017
New Revision: 1807920

URL: http://svn.apache.org/viewvc?rev=1807920&view=rev
Log:
[DOXIA-559] fixed TOC macro when missing section levels

Added:
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-markdown/src/test/resources/macro-toc-DOXIA-559.md
Modified:
    maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/index/IndexingSink.java
    maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/parser/AbstractParserTest.java
    maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/parser/XhtmlBaseParserTest.java
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptParserTest.java
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-markdown/src/test/java/org/apache/maven/doxia/module/markdown/MarkdownParserTest.java
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/test/java/org/apache/maven/doxia/module/twiki/parser/TwikiParserTest.java
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java

Modified: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/index/IndexingSink.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/index/IndexingSink.java?rev=1807920&r1=1807919&r2=1807920&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/index/IndexingSink.java (original)
+++ maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/index/IndexingSink.java Sat Sep  9 19:33:43 2017
@@ -70,9 +70,6 @@ public class IndexingSink
     /** The stack. */
     private final Stack<IndexEntry> stack;
 
-    /** The current type. */
-    private IndexEntry currentEntry;
-
     /**
      * Default constructor.
      *
@@ -107,9 +104,14 @@ public class IndexingSink
     }
 
     /** {@inheritDoc} */
+    public void section1()
+    {
+        pushNewEntry();
+    }
+
+    /** {@inheritDoc} */
     public void sectionTitle1()
     {
-        this.currentEntry = null;
         this.type = TYPE_SECTION_1;
     }
 
@@ -131,9 +133,14 @@ public class IndexingSink
     }
 
     /** {@inheritDoc} */
+    public void section2()
+    {
+        pushNewEntry();
+    }
+
+    /** {@inheritDoc} */
     public void sectionTitle2()
     {
-        this.currentEntry = null;
         this.type = TYPE_SECTION_2;
     }
 
@@ -149,9 +156,14 @@ public class IndexingSink
     }
 
     /** {@inheritDoc} */
+    public void section3()
+    {
+        pushNewEntry();
+    }
+
+    /** {@inheritDoc} */
     public void sectionTitle3()
     {
-        this.currentEntry = null;
         this.type = TYPE_SECTION_3;
     }
 
@@ -167,9 +179,14 @@ public class IndexingSink
     }
 
     /** {@inheritDoc} */
+    public void section4()
+    {
+        pushNewEntry();
+    }
+
+    /** {@inheritDoc} */
     public void sectionTitle4()
     {
-        this.currentEntry = null;
         this.type = TYPE_SECTION_4;
     }
 
@@ -185,9 +202,14 @@ public class IndexingSink
     }
 
     /** {@inheritDoc} */
+    public void section5()
+    {
+        pushNewEntry();
+    }
+
+    /** {@inheritDoc} */
     public void sectionTitle5()
     {
-        this.currentEntry = null;
         this.type = TYPE_SECTION_5;
     }
 
@@ -234,25 +256,14 @@ public class IndexingSink
                 // Sanitize the id. The most important step is to remove any blanks
                 // -----------------------------------------------------------------------
 
-                if ( this.currentEntry == null )
-                {
-                    this.currentEntry = new IndexEntry( peek(), HtmlTools.encodeId( text ) );
-
-                    this.currentEntry.setTitle( text );
-
-                    push( currentEntry );
-                }
-                else
-                {
-                    IndexEntry entry = (IndexEntry) stack.lastElement();
-
-                    String title = currentEntry.getTitle() + text;
-                    title = title.replaceAll( "[\\r\\n]+", "" );
+                // append text to current entry
+                IndexEntry entry = (IndexEntry) stack.lastElement();
 
-                    entry.setId( HtmlTools.encodeId( title ) );
+                String title = entry.getTitle() + text;
+                title = title.replaceAll( "[\\r\\n]+", "" );
+                entry.setTitle( title );
 
-                    entry.setTitle( title );
-                }
+                entry.setId( HtmlTools.encodeId( title ) );
 
                 break;
             // Dunno how to handle these yet
@@ -265,6 +276,20 @@ public class IndexingSink
     }
 
     /**
+     * Creates and pushes a new IndexEntry onto the top of this stack.
+     *
+     * @param entry to put.
+     */
+    public void pushNewEntry()
+    {
+        IndexEntry entry = new IndexEntry( peek(), "" );
+
+        entry.setTitle( "" );
+
+        stack.push( entry );
+    }
+
+    /**
      * Pushes an IndexEntry onto the top of this stack.
      *
      * @param entry to put.

Modified: maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/parser/AbstractParserTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/parser/AbstractParserTest.java?rev=1807920&r1=1807919&r2=1807920&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/parser/AbstractParserTest.java (original)
+++ maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/parser/AbstractParserTest.java Sat Sep  9 19:33:43 2017
@@ -143,6 +143,24 @@ public abstract class AbstractParserTest
         for ( String name : names )
         {
             expected.append( name ).append( '\n' );
+        }
+
+        while ( it.hasNext() )
+        {
+            actual.append( it.next().getName() ).append( '\n' );
+        }
+
+        assertEquals( expected.toString(), actual.toString() );
+    }
+
+    protected void assertStartsWith( Iterator<SinkEventElement> it, String... names )
+    {
+        StringBuilder expected = new StringBuilder();
+        StringBuilder actual = new StringBuilder();
+
+        for ( String name : names )
+        {
+            expected.append( name ).append( '\n' );
             if ( it.hasNext() )
             {
                 actual.append( it.next().getName() ).append( '\n' );
@@ -150,6 +168,4 @@ public abstract class AbstractParserTest
         }
         assertEquals( expected.toString(), actual.toString() );
     }
-
-
 }

Modified: maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/parser/XhtmlBaseParserTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/parser/XhtmlBaseParserTest.java?rev=1807920&r1=1807919&r2=1807920&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/parser/XhtmlBaseParserTest.java (original)
+++ maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/parser/XhtmlBaseParserTest.java Sat Sep  9 19:33:43 2017
@@ -752,16 +752,15 @@ public class XhtmlBaseParserTest
         parser.parse( text, sink );
 
         Iterator<SinkEventElement> it = sink.getEventList().iterator();
-        assertEquals( it, "definitionList", "definitionListItem", "definedTerm", "text", "definedTerm_", "definition",
-                      "text", "definition_", "definitionListItem_", "definitionList_" );
+        assertStartsWith( it, "definitionList", "definitionListItem", "definedTerm", "text", "definedTerm_",
+                          "definition", "text", "definition_", "definitionListItem_", "definitionList_" );
+        assertStartsWith( it, "definitionList", "definitionListItem", "definition", "text", "definition_",
+                          "definitionListItem_", "definitionList_" );
+        assertStartsWith( it, "definitionList", "definitionListItem", "definedTerm", "text", "definedTerm_",
+                          "definitionListItem_", "definitionList_" );
+        assertStartsWith( it, "definitionList", "definitionList_" );
         assertEquals( it, "definitionList", "definitionListItem", "definition", "text", "definition_",
-                      "definitionListItem_", "definitionList_" );
-        assertEquals( it, "definitionList", "definitionListItem", "definedTerm", "text", "definedTerm_",
-                      "definitionListItem_", "definitionList_" );
-        assertEquals( it, "definitionList", "definitionList_" );
-        assertEquals( it, "definitionList", "definitionListItem", "definition", "text", "definition_",
-                      "definitionListItem_", "definitionListItem", "definedTerm", "text", "definedTerm_",
-                      "definitionListItem_", "definitionList_" );
-        assertFalse( it.hasNext() );
+                          "definitionListItem_", "definitionListItem", "definedTerm", "text", "definedTerm_",
+                          "definitionListItem_", "definitionList_" );
     }
 }

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptParserTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptParserTest.java?rev=1807920&r1=1807919&r2=1807920&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptParserTest.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptParserTest.java Sat Sep  9 19:33:43 2017
@@ -135,8 +135,6 @@ public class AptParserTest
         assertEquals( it, "head", "head_", "body", "list", "listItem", "text", "verbatim", "text", "verbatim_",
                       "paragraph", "text", "paragraph_", "listItem_", "listItem", "text", "verbatim", "text",
                       "verbatim_", "paragraph", "text", "paragraph_", "listItem_", "list_", "body_" );
-
-        assertFalse( it.hasNext() );
     }
 
 
@@ -154,8 +152,6 @@ public class AptParserTest
         Iterator<SinkEventElement> it = sink.getEventList().iterator();
 
         assertEquals( it, "head", "head_", "body", "verbatim", "text", "verbatim_", "body_" );
-
-        assertFalse( it.hasNext() );
     }
 
     /** @throws Exception  */
@@ -210,14 +206,12 @@ public class AptParserTest
 
         Iterator<SinkEventElement> it = sink.getEventList().iterator();
 
-        assertEquals( it, "head", "head_", "body" );
+        assertStartsWith( it, "head", "head_", "body" );
         assertEquals( it.next(), "verbatim", SinkEventAttributeSet.BOXED );
-        assertEquals( it, "text", "verbatim_" );
+        assertStartsWith( it, "text", "verbatim_" );
 
         assertEquals( it.next(), "verbatim", new Object[] { null } );
         assertEquals( it, "text", "verbatim_", "body_" );
-
-        assertFalse( it.hasNext() );
     }
 
     /** @throws Exception  */
@@ -241,36 +235,34 @@ public class AptParserTest
 
         Iterator<SinkEventElement> it = sink.getEventList().iterator();
 
-        assertEquals( it, "head", "head_", "body", "table", "tableRows", "tableRow", "tableCell" );
+        assertStartsWith( it, "head", "head_", "body", "table", "tableRows", "tableRow", "tableCell" );
         assertEquals( it.next(), "text", "cell 1, 1" );
 
-        assertEquals( it, "tableCell_", "tableCell" );
+        assertStartsWith( it, "tableCell_", "tableCell" );
         assertEquals( it.next(), "text", "cell 1,2" );
 
-        assertEquals( it, "tableCell_", "tableCell" );
+        assertStartsWith( it, "tableCell_", "tableCell" );
         assertEquals( it.next(), "text", "cell 1,3" );
 
-        assertEquals( it, "tableCell_", "tableRow_", "tableRow", "tableCell" );
+        assertStartsWith( it, "tableCell_", "tableRow_", "tableRow", "tableCell" );
         assertEquals( it.next(), "text", "cell 2,1" );
 
-        assertEquals( it, "tableCell_", "tableCell" );
+        assertStartsWith( it, "tableCell_", "tableCell" );
         assertEquals( it.next(), "text", "cell 2, 2" );
 
-        assertEquals( it, "tableCell_", "tableCell" );
+        assertStartsWith( it, "tableCell_", "tableCell" );
         assertEquals( it.next(), "text", "cell 2,3" );
         
-        assertEquals( it, "tableCell_", "tableRow_", "tableRow", "tableCell" );
+        assertStartsWith( it, "tableCell_", "tableRow_", "tableRow", "tableCell" );
         assertEquals( it.next(), "text", "cell 3,1" );
 
-        assertEquals( it, "tableCell_", "tableCell" );
+        assertStartsWith( it, "tableCell_", "tableCell" );
         assertEquals( it.next(), "text", "cell 3,2" );
 
-        assertEquals( it, "tableCell_", "tableCell" );
+        assertStartsWith( it, "tableCell_", "tableCell" );
         assertEquals( it.next(), "text", "cell 3, 3" );
 
         assertEquals( it, "tableCell_", "tableRow_", "tableRows_", "table_", "body_" );
-
-        assertFalse( it.hasNext() );
     }
 
     /** @throws Exception  */
@@ -294,45 +286,43 @@ public class AptParserTest
 
         Iterator<SinkEventElement> it = sink.getEventList().iterator();
 
-        assertEquals( it, "head", "head_", "body", "table", "tableRows", "tableRow", "tableCell" );
+        assertStartsWith( it, "head", "head_", "body", "table", "tableRows", "tableRow", "tableCell" );
         assertEquals( it.next(), "text", "cell 1,\u00A0" );
 
         assertEquals( it.next().getName(), "lineBreak" );
         assertEquals( it.next(), "text", "1" );
 
-        assertEquals( it, "tableCell_", "tableCell" );
+        assertStartsWith( it, "tableCell_", "tableCell" );
         assertEquals( it.next(), "text", "cell 1,2" );
 
-        assertEquals( it, "tableCell_", "tableCell" );
+        assertStartsWith( it, "tableCell_", "tableCell" );
         assertEquals( it.next(), "text", "cell 1,3" );
 
-        assertEquals( it, "tableCell_", "tableRow_", "tableRow", "tableCell" );
+        assertStartsWith( it, "tableCell_", "tableRow_", "tableRow", "tableCell" );
         assertEquals( it.next(), "text", "cell 2,1" );
 
-        assertEquals( it, "tableCell_", "tableCell" );
+        assertStartsWith( it, "tableCell_", "tableCell" );
         assertEquals( it.next(), "text", "cell 2,\u00A0" );
 
         assertEquals( it.next().getName(), "lineBreak" );
         assertEquals( it.next(), "text", "2" );
 
-        assertEquals( it, "tableCell_", "tableCell" );
+        assertStartsWith( it, "tableCell_", "tableCell" );
         assertEquals( it.next(), "text", "cell 2,3" );
 
-        assertEquals( it, "tableCell_", "tableRow_", "tableRow", "tableCell" );
+        assertStartsWith( it, "tableCell_", "tableRow_", "tableRow", "tableCell" );
         assertEquals( it.next(), "text", "cell 3,1" );
 
-        assertEquals( it, "tableCell_", "tableCell" );
+        assertStartsWith( it, "tableCell_", "tableCell" );
         assertEquals( it.next(), "text", "cell 3,2" );
 
-        assertEquals( it, "tableCell_", "tableCell" );
+        assertStartsWith( it, "tableCell_", "tableCell" );
         assertEquals( it.next(), "text", "cell 3,\u00A0" );
 
         assertEquals( it.next().getName(), "lineBreak" );
         assertEquals( it.next(), "text", "3" );
 
         assertEquals( it, "tableCell_", "tableRow_", "tableRows_", "table_", "body_" );
-
-        assertFalse( it.hasNext() );
     }
 
     /** @throws Exception  */
@@ -352,7 +342,7 @@ public class AptParserTest
 
         Iterator<SinkEventElement> it = sink.getEventList().iterator();
 
-        assertEquals( it, "head", "head_", "body", "table", "tableRows", "tableRow" );
+        assertStartsWith( it, "head", "head_", "body", "table", "tableRows", "tableRow" );
         assertAttributeEquals( it.next(), "tableCell", SinkEventAttributeSet.ALIGN, "center" );
         assertEquals( it.next(), "text", "Centered" );
         assertEquals( it.next().getName(), "tableCell_" );
@@ -363,7 +353,7 @@ public class AptParserTest
         
         assertAttributeEquals( it.next(), "tableCell", SinkEventAttributeSet.ALIGN, "center" );
         assertEquals( it.next(), "text", "Centered" );
-        assertEquals( it, "tableCell_", "tableRow_", "tableRow" );
+        assertStartsWith( it, "tableCell_", "tableRow_", "tableRow" );
         
         assertAttributeEquals( it.next(), "tableCell", SinkEventAttributeSet.ALIGN, "center" );
         assertEquals( it.next(), "text", "Centered" );
@@ -376,8 +366,6 @@ public class AptParserTest
         assertAttributeEquals( it.next(), "tableCell", SinkEventAttributeSet.ALIGN, "right" );
         assertEquals( it.next(), "text", "Right-aligned" );
         assertEquals( it, "tableCell_", "tableRow_", "tableRows_", "table_", "body_" );
-
-        assertFalse( it.hasNext() );
     }
 
     /** @throws Exception  */
@@ -397,15 +385,13 @@ public class AptParserTest
 
         Iterator<SinkEventElement> it = sink.getEventList().iterator();
 
-        assertEquals( it, "head", "head_", "body", "paragraph" );
+        assertStartsWith( it, "head", "head_", "body", "paragraph" );
         assertEquals( it.next(), "text", "~ = - + * [ ] < > { } \\ \u2713" );
 
-        assertEquals( it, "paragraph_", "table", "tableRows", "tableRow", "tableCell" );
+        assertStartsWith( it, "paragraph_", "table", "tableRows", "tableRow", "tableCell" );
         assertEquals( it.next(), "text", "~ = - + * [ ] < > { } \\ \u2713" );
 
         assertEquals( it, "tableCell_", "tableCell", "text", "tableCell_", "tableRow_", "tableRows_", "table_", "body_" );
-
-        assertFalse( it.hasNext() );
     }
 
     /** @throws Exception  */
@@ -422,24 +408,22 @@ public class AptParserTest
 
         Iterator<SinkEventElement> it = sink.getEventList().iterator();
 
-        assertEquals( it, "head", "head_", "body", "paragraph" );
+        assertStartsWith( it, "head", "head_", "body", "paragraph" );
         assertEquals( it.next(), "anchor", "Anchor_with_spaces_and_brackets" );
 
         assertEquals( it.next(), "text", "Anchor with spaces (and brackets)" );
 
-        assertEquals( it, "anchor_", "text" );
+        assertStartsWith( it, "anchor_", "text" );
         assertEquals( it.next(), "link", "#Anchor_with_spaces_and_brackets" );
 
         assertEquals( it.next(), "text", "Anchor with spaces (and brackets)" );
 
-        assertEquals( it, "link_", "text" );
+        assertStartsWith( it, "link_", "text" );
         assertEquals( it.next(), "link", "http://fake.api#method(with, args)" );
 
         assertEquals( it.next(), "text", "method(with, args)" );
 
         assertEquals( it, "link_", "paragraph_", "body_" );
-
-        assertFalse( it.hasNext() );
     }
 
     /** @throws Exception  */
@@ -458,8 +442,6 @@ public class AptParserTest
 
         assertEquals( it, "head", "head_", "body", "section1", "sectionTitle1", "text", "sectionTitle1_", "section1_",
                       "section1", "sectionTitle1", "anchor", "text", "anchor_", "sectionTitle1_", "section1_", "body_" );
-
-        assertFalse( it.hasNext() );
     }
     
     /**
@@ -482,14 +464,14 @@ public class AptParserTest
 
         Iterator<SinkEventElement> it = sink.getEventList().iterator();
 
-        assertEquals( it, "head", "head_", "body", "table", "tableRows" );
-        assertEquals( it, "tableRow", "tableHeaderCell", "text", "tableHeaderCell_", "tableHeaderCell", "text",
-                      "tableHeaderCell_", "tableRow_" );
-        assertEquals( it, "tableRow", "tableCell", "text", "tableCell_", "tableCell", "text", "tableCell_", "tableRow_" );
-        assertEquals( it, "tableRow", "tableCell", "text", "tableCell_", "tableCell", "text", "tableCell_", "tableRow_" );
+        assertStartsWith( it, "head", "head_", "body", "table", "tableRows" );
+        assertStartsWith( it, "tableRow", "tableHeaderCell", "text", "tableHeaderCell_", "tableHeaderCell", "text",
+                          "tableHeaderCell_", "tableRow_" );
+        assertStartsWith( it, "tableRow", "tableCell", "text", "tableCell_", "tableCell", "text", "tableCell_",
+                          "tableRow_" );
+        assertStartsWith( it, "tableRow", "tableCell", "text", "tableCell_", "tableCell", "text", "tableCell_",
+                          "tableRow_" );
         assertEquals( it, "tableRows_", "table_", "body_" );
-
-        assertFalse( it.hasNext() );
     }
     
     public void testEscapedPipeInTableCell() throws Exception
@@ -504,12 +486,11 @@ public class AptParserTest
         parser.parse( text, sink );
 
         Iterator<SinkEventElement> it = sink.getEventList().iterator();
-        assertEquals( it, "head", "head_", "body", "table", "tableRows", "tableRow", "tableCell" );
+        assertStartsWith( it, "head", "head_", "body", "table", "tableRows", "tableRow", "tableCell" );
         assertEquals( it.next(), "text", "cell | pipe" );
-        assertEquals( it, "tableCell_", "tableCell" );
+        assertStartsWith( it, "tableCell_", "tableCell" );
         assertEquals( it.next(), "text", "next cell" );
         assertEquals( it, "tableCell_", "tableRow_", "tableRows_", "table_", "body_" );
-        assertFalse( it.hasNext() );
     }
 
     public void testLiteralAnchor()
@@ -524,12 +505,11 @@ public class AptParserTest
         parser.parse( text, sink );
 
         Iterator<SinkEventElement> it = sink.getEventList().iterator();
-        assertEquals( it, "head", "head_", "body", "section1", "sectionTitle1" );
+        assertStartsWith( it, "head", "head_", "body", "section1", "sectionTitle1" );
         assertEquals( it.next(), "link",
                       "../apidocs/groovyx/net/http/ParserRegistry.html#parseText(org.apache.http.HttpResponse)" );
         assertEquals( it.next(), "text", "ParserRegistry" );
         assertEquals( it, "link_", "sectionTitle1_", "section1_", "body_" );
-        assertFalse( it.hasNext() );
     }
 
     /** {@inheritDoc} */

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java?rev=1807920&r1=1807919&r2=1807920&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java Sat Sep  9 19:33:43 2017
@@ -252,32 +252,31 @@ public class ConfluenceParserTest
 
         Iterator<SinkEventElement> it = sink.getEventList().iterator();
 
-        assertEquals( it, "head", "head_", "body", "paragraph" );
+        assertStartsWith( it, "head", "head_", "body", "paragraph" );
         assertEquals( it.next(), "text", "Simple paragraph." );
-        assertEquals( it, "paragraph_", "figure" );
+        assertStartsWith( it, "paragraph_", "figure" );
         assertEquals( it.next(), "figureGraphics", "images/photo.jpg" );
-        assertEquals( it, "figure_", "paragraph" );
+        assertStartsWith( it, "figure_", "paragraph" );
         assertEquals( it.next(), "text", "Simple paragraph with attempted inline !image.jpg! (should fail)." );
-        assertEquals( it, "paragraph_", "figure" );
+        assertStartsWith( it, "paragraph_", "figure" );
         assertEquals( it.next(), "figureGraphics", "images/photo.jpg" );
         assertEquals( it.next().getName(), "figureCaption" );
         assertEquals( it.next(), "text", "With caption on same line" );
-        assertEquals( it, "figureCaption_", "figure_", "figure" );
+        assertStartsWith( it, "figureCaption_", "figure_", "figure" );
         assertEquals( it.next(), "figureGraphics", "images/linebreak.jpg" );
         assertEquals( it.next().getName(), "figureCaption" );
         assertEquals( it.next(), "text", "With caption underneath and linebreak" );
-        assertEquals( it, "figureCaption_", "figure_", "figure" );
+        assertStartsWith( it, "figureCaption_", "figure_", "figure" );
         assertEquals( it.next(), "figureGraphics", "images/nolinebreak.jpg" );
         assertEquals( it.next().getName(), "figureCaption" );
         assertEquals( it.next(), "text", "With caption underneath and no linebreak" );
-        assertEquals( it, "figureCaption_", "figure_", "figure" );
+        assertStartsWith( it, "figureCaption_", "figure_", "figure" );
         assertEquals( it.next(), "figureGraphics", "images/bold.jpg" );
         assertEquals( it.next().getName(), "figureCaption" );
         assertEquals( it.next(), "text", "With *bold* caption underneath" );
-        assertEquals( it, "figureCaption_", "figure_", "figure" );
+        assertStartsWith( it, "figureCaption_", "figure_", "figure" );
         assertEquals( it.next(), "figureGraphics", "image.gif" );
         assertEquals( it, "figure_", "body_" );
-        assertFalse( it.hasNext() );
     }
 
     /** @throws Exception */
@@ -343,14 +342,13 @@ public class ConfluenceParserTest
 
         Iterator<SinkEventElement> it = sink.getEventList().iterator();
 
-        assertEquals( it, "head", "head_", "body", "paragraph" );
+        assertStartsWith( it, "head", "head_", "body", "paragraph" );
         assertEquals( it.next(), "text", "Table containing image in cell:" );
-        assertEquals( it, "paragraph_", "table", "tableRows", "tableRow", "tableHeaderCell", "bold" );
+        assertStartsWith( it, "paragraph_", "table", "tableRows", "tableRow", "tableHeaderCell", "bold" );
         assertEquals( it.next(), "text", "Header 1" );
-        assertEquals( it, "bold_", "tableHeaderCell_", "tableRow_", "tableRow", "tableCell", "figure" );
+        assertStartsWith( it, "bold_", "tableHeaderCell_", "tableRow_", "tableRow", "tableCell", "figure" );
         assertEquals( it.next(), "figureGraphics", "images/test/Image.png" );
         assertEquals( it, "figure_", "tableCell_", "tableRow_", "tableRows_", "table_", "body_" );
-        assertFalse( it.hasNext() );
     }
 
     /** @throws Exception */
@@ -619,11 +617,10 @@ public class ConfluenceParserTest
  createParser().parse(new StringReader(document), sink);
 
  Iterator<SinkEventElement> it = sink.getEventList().iterator();
- assertEquals(it, "head", "head_", "body", "paragraph");
+ assertStartsWith(it, "head", "head_", "body", "paragraph");
  assertEquals(it.next(), "text", "Linethrough",
  new SinkEventAttributeSet("decoration", "line-through"));
  assertEquals(it, "paragraph_", "body_");
- assertFalse(it.hasNext());
  }
 
  public void testUnderline() throws Exception {
@@ -633,11 +630,10 @@ public class ConfluenceParserTest
  createParser().parse(new StringReader(document), sink);
 
  Iterator<SinkEventElement> it = sink.getEventList().iterator();
- assertEquals(it, "head", "head_", "body", "paragraph");
+ assertStartsWith(it, "head", "head_", "body", "paragraph");
  assertEquals(it.next(), "text", "Underline", new SinkEventAttributeSet(
  "decoration", "underline"));
  assertEquals(it, "paragraph_", "body_");
- assertFalse(it.hasNext());
  }
 
  public void testSub() throws Exception {
@@ -647,11 +643,10 @@ public class ConfluenceParserTest
  createParser().parse(new StringReader(document), sink);
 
  Iterator<SinkEventElement> it = sink.getEventList().iterator();
- assertEquals(it, "head", "head_", "body", "paragraph");
+ assertStartsWith(it, "head", "head_", "body", "paragraph");
  assertEquals(it.next(), "text", "Sub", new SinkEventAttributeSet(
  "valign", "sub"));
  assertEquals(it, "paragraph_", "body_");
- assertFalse(it.hasNext());
  }
 
  public void testSup() throws Exception {
@@ -661,11 +656,10 @@ public class ConfluenceParserTest
  createParser().parse(new StringReader(document), sink);
 
  Iterator<SinkEventElement> it = sink.getEventList().iterator();
- assertEquals(it, "head", "head_", "body", "paragraph");
+ assertStartsWith(it, "head", "head_", "body", "paragraph");
  assertEquals(it.next(), "text", "Sup", new SinkEventAttributeSet(
  "valign", "sup"));
  assertEquals(it, "paragraph_", "body_");
- assertFalse(it.hasNext());
  }
 
     private void assertContainsLines( String message, String result, String lines )

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-markdown/src/test/java/org/apache/maven/doxia/module/markdown/MarkdownParserTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-markdown/src/test/java/org/apache/maven/doxia/module/markdown/MarkdownParserTest.java?rev=1807920&r1=1807919&r2=1807920&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-markdown/src/test/java/org/apache/maven/doxia/module/markdown/MarkdownParserTest.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-markdown/src/test/java/org/apache/maven/doxia/module/markdown/MarkdownParserTest.java Sat Sep  9 19:33:43 2017
@@ -301,9 +301,52 @@ public class MarkdownParserTest
         Iterator<SinkEventElement> it = parseFileToEventTestingSink( "macro-toc" ).getEventList().iterator();
 
         assertEquals( it, "head", "title", "text", "title_", "head_",
-                      "body", "list",
-                      "listItem", "link", "text", "link_", "listItem_",
-                      "listItem", "link", "text", "link_", "listItem_",
-                      "list_", "text", "section1", "section2" );
+                      "body",
+                      "list", // TOC start
+                      "listItem", "link", "text", "link_", // emtpy section 2 TOC entry
+                      "list", // sections 3 list start
+                      "listItem", "link", "text", "link_", "listItem_", // first section 3 TOC entry
+                      "listItem", "link", "text", "link_", "listItem_", // second section 3 TOC entry
+                      "list_", // sections 3 list end
+                      "listItem_", // emtpy section 2 TOC entry end
+                      "list_", // TOC end
+                      "text",
+                      "section1",
+                      "section2", "sectionTitle2", "text", "sectionTitle2_", "section2_",
+                      "section2", "sectionTitle2", "text", "sectionTitle2_", "section2_",
+                      "section1_",
+                      "body_" );
+    }
+
+    /**
+     * TOC macro fails with EmptyStackException when title 2 followed by title 4 then title 2
+     *
+     * @throws Exception
+     */
+    public void testTocMacroDoxia559()
+        throws Exception
+    {
+        Iterator<SinkEventElement> it = parseFileToEventTestingSink( "macro-toc-DOXIA-559" ).getEventList().iterator();
+
+        assertEquals( it, "head", "title", "text", "title_", "head_",
+                      "body",
+                      "list", // TOC start
+                      "listItem", "link", "text", "link_", // first section 2 TOC entry
+                      "list", // sections 3 list start
+                      "listItem", "link", "text", "link_", "listItem_", // empty section 3 TOC entry
+                      "list_", // sections 3 list end
+                      "listItem_", // first section 2 TOC entry end
+                      "listItem", "link", "text", "link_", "listItem_", // second section 2 TOC entry
+                      "list_", // TOC end
+                      "text",
+                      "section1", "sectionTitle1", "text", "sectionTitle1_",
+                      "section2",
+                      "section3", "sectionTitle3", "text", "sectionTitle3_",
+                      "section3_",
+                      "section2_",
+                      "section1_",
+                      "section1", "sectionTitle1", "text", "sectionTitle1_",
+                      "section1_",
+                      "body_" );
     }
 }

Added: maven/doxia/doxia/trunk/doxia-modules/doxia-module-markdown/src/test/resources/macro-toc-DOXIA-559.md
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-markdown/src/test/resources/macro-toc-DOXIA-559.md?rev=1807920&view=auto
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-markdown/src/test/resources/macro-toc-DOXIA-559.md (added)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-markdown/src/test/resources/macro-toc-DOXIA-559.md Sat Sep  9 19:33:43 2017
@@ -0,0 +1,8 @@
+
+<!-- MACRO{toc|fromDepth=1|toDepth=2} -->
+
+## level 2
+
+#### direct level 4
+
+## level 2

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/test/java/org/apache/maven/doxia/module/twiki/parser/TwikiParserTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/test/java/org/apache/maven/doxia/module/twiki/parser/TwikiParserTest.java?rev=1807920&r1=1807919&r2=1807920&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/test/java/org/apache/maven/doxia/module/twiki/parser/TwikiParserTest.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/test/java/org/apache/maven/doxia/module/twiki/parser/TwikiParserTest.java Sat Sep  9 19:33:43 2017
@@ -70,7 +70,7 @@ public class TwikiParserTest
 
         Iterator<SinkEventElement> it = sink.getEventList().iterator();
 
-        assertEquals( it, "head", "head_", "body", "paragraph" );
+        assertStartsWith( it, "head", "head_", "body", "paragraph" );
 
         assertEquals( "italic", ( it.next() ).getName() );
         assertEquals( it.next(), "text", "ita" );
@@ -89,6 +89,5 @@ public class TwikiParserTest
         assertEquals( it.next(), "rawText", "</font>" );
 
         assertEquals( it, "paragraph_", "body_", "flush", "close" );
-        assertFalse( it.hasNext() );
     }
 }
\ No newline at end of file

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java?rev=1807920&r1=1807919&r2=1807920&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java Sat Sep  9 19:33:43 2017
@@ -177,6 +177,16 @@ public class XdocParserTest
         assertTrue( content.indexOf( "<a href=\"#Section_1211\">Section 1211</a>" ) == -1 );
     }
 
+    private Iterator<SinkEventElement> parseText( String text )
+        throws ParseException
+    {
+        SinkEventTestingSink sink = new SinkEventTestingSink();
+
+        parser.parse( text, sink );
+
+        return sink.getEventList().iterator();
+    }
+
     /** @throws Exception  */
     public void testHeadEventsList()
         throws Exception
@@ -191,13 +201,9 @@ public class XdocParserTest
                 + "</head>"
                 + "<body></body></document>";
 
-        SinkEventTestingSink sink = new SinkEventTestingSink();
+        Iterator<SinkEventElement> it = parseText( text );
 
-        parser.parse( text, sink );
-
-        Iterator<SinkEventElement> it = sink.getEventList().iterator();
-
-        assertEquals( it, "head", "title", "text", "title_", "comment", "author", "text", "author_" );
+        assertStartsWith( it, "head", "title", "text", "title_", "comment", "author", "text", "author_" );
 
         SinkEventElement unknown = it.next();
         assertEquals( "unknown", unknown.getName() );
@@ -208,7 +214,6 @@ public class XdocParserTest
         assertEquals( "base", unknown.getArgs()[0] );
 
         assertEquals( it, "head_", "body", "body_" );
-        assertFalse( it.hasNext() );
 
         // DOXIA-359
         text = "<document>"
@@ -216,19 +221,15 @@ public class XdocParserTest
                 + "<head><title>head title</title></head>"
                 + "<body></body></document>";
 
-        sink.reset();
-        parser.parse( text, sink );
-
-        it = sink.getEventList().iterator();
+        it = parseText( text );
 
-        assertEquals( it, "head", "title" );
+        assertStartsWith( it, "head", "title" );
 
         SinkEventElement title = it.next();
         assertEquals( "text", title.getName() );
         assertEquals( "properties title", title.getArgs()[0] );
 
         assertEquals( it, "title_", "head_", "body",  "body_" );
-        assertFalse( it.hasNext() );
     }
 
     /** @throws Exception  */
@@ -237,14 +238,9 @@ public class XdocParserTest
     {
         String text = "<document><body></body></document>";
 
-        SinkEventTestingSink sink = new SinkEventTestingSink();
-
-        parser.parse( text, sink );
-
-        Iterator<SinkEventElement> it = sink.getEventList().iterator();
+        Iterator<SinkEventElement> it = parseText( text );
 
         assertEquals( it, "body", "body_" );
-        assertFalse( it.hasNext() );
     }
 
     /** @throws Exception  */
@@ -253,15 +249,10 @@ public class XdocParserTest
     {
         String text = "<section name=\"sec 1\"><subsection name=\"sub 1\"></subsection></section>";
 
-        SinkEventTestingSink sink = new SinkEventTestingSink();
-
-        parser.parse( text, sink );
-
-        Iterator<SinkEventElement> it = sink.getEventList().iterator();
+        Iterator<SinkEventElement> it = parseText( text );
 
         assertEquals( it, "section1", "sectionTitle1", "text", "sectionTitle1_", "section2", "sectionTitle2", "text",
                       "sectionTitle2_", "section2_", "section1_" );
-        assertFalse( it.hasNext() );
     }
 
     /** @throws Exception  */
@@ -271,13 +262,9 @@ public class XdocParserTest
         // DOXIA-448
         String text = "<section name=\"section name\" class=\"foo\" id=\"bar\"></section>";
 
-        SinkEventTestingSink sink = new SinkEventTestingSink();
-
-        parser.parse( text, sink );
-
-        Iterator<SinkEventElement> it = sink.getEventList().iterator();
+        Iterator<SinkEventElement> it = parseText( text );
 
-        assertEquals( it, "anchor", "anchor_" );
+        assertStartsWith( it, "anchor", "anchor_" );
 
         SinkEventElement next = it.next();
         assertEquals( "section1", next.getName() );
@@ -292,7 +279,6 @@ public class XdocParserTest
         assertNull( (SinkEventAttributeSet) next.getArgs()[0] );
 
         assertEquals( it, "text", "sectionTitle1_", "section1_" );
-        assertFalse( it.hasNext() );
     }
 
     /** @throws Exception  */
@@ -302,16 +288,11 @@ public class XdocParserTest
         // DOXIA-241
         String text = "<section name=\"section\"><h6>h6</h6><subsection name=\"subsection\"></subsection></section>";
 
-        SinkEventTestingSink sink = new SinkEventTestingSink();
-
-        parser.parse( text, sink );
-
-        Iterator<SinkEventElement> it = sink.getEventList().iterator();
+        Iterator<SinkEventElement> it = parseText( text );
 
         assertEquals( it, "section1", "sectionTitle1", "text", "sectionTitle1_", "section2", "section3", "section4",
                       "section5", "sectionTitle5", "text", "sectionTitle5_", "section5_", "section4_", "section3_",
                       "section2_", "section2", "sectionTitle2", "text", "sectionTitle2_", "section2_", "section1_" );
-        assertFalse( it.hasNext() );
     }
 
     /** @throws Exception  */
@@ -320,29 +301,19 @@ public class XdocParserTest
     {
         String text = "<source><a href=\"what.html\">what</a></source>";
 
-        SinkEventTestingSink sink = new SinkEventTestingSink();
-
-        parser.parse( text, sink );
+        Iterator<SinkEventElement> it = parseText( text );
 
-        Iterator<SinkEventElement> it = sink.getEventList().iterator();
         assertEquals( it, "verbatim", "link", "text", "link_", "verbatim_" );
-        assertFalse( it.hasNext() );
 
         text = "<source><![CDATA[<a href=\"what.html\">what</a>]]></source>";
-        sink.reset();
-        parser.parse( text, sink );
+        it = parseText( text );
 
-        it = sink.getEventList().iterator();
         assertEquals( it, "verbatim", "text", "verbatim_" );
-        assertFalse( it.hasNext() );
 
         text = "<source><![CDATA[<source>what</source>]]></source>";
-        sink.reset();
-        parser.parse( text, sink );
+        it = parseText( text );
 
-        it = sink.getEventList().iterator();
         assertEquals( it, "verbatim", "text", "verbatim_" );
-        assertFalse( it.hasNext() );
     }
 
     /** @throws Exception  */
@@ -355,14 +326,9 @@ public class XdocParserTest
                           " \"http://java.sun.com/j2ee/dtds/web-app_2.2.dtd\">" +
                       "]]></source>";
 
-        SinkEventTestingSink sink = new SinkEventTestingSink();
-
-        parser.parse( text, sink );
+        Iterator<SinkEventElement> it = parseText( text );
 
-        Iterator<SinkEventElement> it = sink.getEventList().iterator();
         assertEquals( it, "verbatim", "text", "verbatim_" );
-        assertFalse( it.hasNext() );
-
     }
 
     /** @throws Exception  */
@@ -373,11 +339,7 @@ public class XdocParserTest
         String text = "<source><a href=\"what.html\">what</a>" + EOL
                 + "<a href=\"what.html\">what</a></source>";
 
-        SinkEventTestingSink sink = new SinkEventTestingSink();
-
-        parser.parse( text, sink );
-
-        Iterator<SinkEventElement> it = sink.getEventList().iterator();
+        Iterator<SinkEventElement> it = parseText( text );
 
         assertEquals( it, "verbatim", "link", "text", "link_", "text", "link", "text", "link_", "verbatim_" );
     }
@@ -393,21 +355,16 @@ public class XdocParserTest
         String text = "<section name=\"test\" id=\"test-id\">This is a test."
                 + "<subsection name=\"sub-test\" id=\"sub-id\">Sub-section</subsection></section>";
 
-        SinkEventTestingSink sink = new SinkEventTestingSink();
-
-        parser.parse( text, sink );
-
-        Iterator<SinkEventElement> it = sink.getEventList().iterator();
+        Iterator<SinkEventElement> it = parseText( text );
 
         assertEquals( it.next(), "anchor", "test-id" );
 
-        assertEquals( it, "anchor_", "section1", "sectionTitle1", "text", "sectionTitle1_", "text" );
+        assertStartsWith( it, "anchor_", "section1", "sectionTitle1", "text", "sectionTitle1_", "text" );
 
         assertEquals( it.next(), "anchor", "sub-id" );
 
         assertEquals( it, "anchor_", "section2", "sectionTitle2", "text", "sectionTitle2_", "text", "section2_",
                       "section1_" );
-        assertFalse( it.hasNext() );
     }
 
     /**
@@ -420,13 +377,8 @@ public class XdocParserTest
     {
         String text = "<script type=\"text/javascript\"><![CDATA[alert(\"Hello!\");]]></script>";
 
-        SinkEventTestingSink sink = new SinkEventTestingSink();
-
-        parser.parse( text, sink );
-
-        Iterator<SinkEventElement> it = sink.getEventList().iterator();
+        Iterator<SinkEventElement> it = parseText( text );
         assertEquals( it, "unknown", "unknown", "unknown" );
-        assertFalse( it.hasNext() );
     }
 
     /**
@@ -439,13 +391,8 @@ public class XdocParserTest
     {
         String text = "<applet><param name=\"name\" value=\"value\"/><unknown/></applet>";
 
-        SinkEventTestingSink sink = new SinkEventTestingSink();
-
-        parser.parse( text, sink );
-
-        Iterator<SinkEventElement> it = sink.getEventList().iterator();
+        Iterator<SinkEventElement> it = parseText( text );
         assertEquals( it, "unknown", "unknown", "unknown", "unknown", "unknown" );
-        assertFalse( it.hasNext() );
     }
 
     /**
@@ -491,11 +438,11 @@ public class XdocParserTest
 
         Iterator<SinkEventElement> it = sink.getEventList().iterator();
 
-        assertEquals( it, "section1", "sectionTitle1" );
+        assertStartsWith( it, "section1", "sectionTitle1" );
 
         assertEquals( it.next(), "text", "&\u0159\uD835\uDFED" );
 
-        assertEquals( it, "sectionTitle1_", "paragraph" );
+        assertStartsWith( it, "sectionTitle1_", "paragraph" );
 
         assertEquals( it.next(), "text", "&" );
 
@@ -504,7 +451,6 @@ public class XdocParserTest
         assertEquals( it.next(), "text", "\uD835\uDFED" );
 
         assertEquals( it, "paragraph_", "section1_" );
-        assertFalse( it.hasNext() );
     }
     
     public void testStyleWithCData() throws Exception