maven-doxia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ltheu...@apache.org
Subject svn commit: r629497 - in /maven/doxia/doxia/trunk: doxia-core/src/main/java/org/apache/maven/doxia/parser/ doxia-core/src/test/java/org/apache/maven/doxia/parser/ doxia-core/src/test/java/org/apache/maven/doxia/sink/ doxia-modules/doxia-module-fml/src/...
Date Wed, 20 Feb 2008 15:07:29 GMT
Author: ltheussl
Date: Wed Feb 20 07:07:25 2008
New Revision: 629497

URL: http://svn.apache.org/viewvc?rev=629497&view=rev
Log:
Add some event sequence tests for xml parsers

Added:
    maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/parser/XhtmlBaseParserTest.java
  (with props)
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/test/resources/simpleFaq.fml
  (with props)
Modified:
    maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/XhtmlBaseParser.java
    maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/sink/SinkEventElement.java
    maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/sink/SinkEventTestingSink.java
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/test/java/org/apache/maven/doxia/module/fml/FmlParserTest.java
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlParserTest.java

Modified: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/XhtmlBaseParser.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/XhtmlBaseParser.java?rev=629497&r1=629496&r2=629497&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/XhtmlBaseParser.java
(original)
+++ maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/XhtmlBaseParser.java
Wed Feb 20 07:07:25 2008
@@ -206,16 +206,19 @@
         {
             sink.definition();
         }
-        else if ( ( parser.getName().equals( Tag.B.toString() ) ) || ( parser.getName().equals(
Tag.STRONG.toString() ) ) )
+        else if ( ( parser.getName().equals( Tag.B.toString() ) )
+                || ( parser.getName().equals( Tag.STRONG.toString() ) ) )
         {
             sink.bold();
         }
-        else if ( ( parser.getName().equals( Tag.I.toString() ) ) || ( parser.getName().equals(
Tag.EM.toString() ) ) )
+        else if ( ( parser.getName().equals( Tag.I.toString() ) )
+                || ( parser.getName().equals( Tag.EM.toString() ) ) )
         {
             sink.italic();
         }
-        else if ( ( parser.getName().equals( Tag.CODE.toString() ) ) || ( parser.getName().equals(
Tag.SAMP.toString() ) ) ||
-            ( parser.getName().equals( Tag.TT.toString() ) ) )
+        else if ( ( parser.getName().equals( Tag.CODE.toString() ) )
+                || ( parser.getName().equals( Tag.SAMP.toString() ) )
+                || ( parser.getName().equals( Tag.TT.toString() ) ) )
         {
             sink.monospaced();
         }
@@ -436,16 +439,19 @@
             sink.definition_();
             sink.definitionListItem_();
         }
-        else if ( ( parser.getName().equals( Tag.B.toString() ) ) || ( parser.getName().equals(
Tag.STRONG.toString() ) ) )
+        else if ( ( parser.getName().equals( Tag.B.toString() ) )
+                || ( parser.getName().equals( Tag.STRONG.toString() ) ) )
         {
             sink.bold_();
         }
-        else if ( ( parser.getName().equals( Tag.I.toString() ) ) || ( parser.getName().equals(
Tag.EM.toString() ) ) )
+        else if ( ( parser.getName().equals( Tag.I.toString() ) )
+                || ( parser.getName().equals( Tag.EM.toString() ) ) )
         {
             sink.italic_();
         }
-        else if ( ( parser.getName().equals( Tag.CODE.toString() ) ) || ( parser.getName().equals(
Tag.SAMP.toString() ) ) ||
-            ( parser.getName().equals( Tag.TT.toString() ) ) )
+        else if ( ( parser.getName().equals( Tag.CODE.toString() ) )
+                || ( parser.getName().equals( Tag.SAMP.toString() ) )
+                || ( parser.getName().equals( Tag.TT.toString() ) ) )
         {
             sink.monospaced_();
         }
@@ -557,14 +563,7 @@
     {
         if ( !baseEndTag( parser, sink ) )
         {
-            if ( getLog().isWarnEnabled() )
-            {
-                String position = "[" + parser.getLineNumber() + ":"
-                    + parser.getColumnNumber() + "]";
-                String tag = "<" + parser.getName() + ">";
-
-                getLog().warn( "Unrecognized xml tag: " + tag + " at " + position );
-            }
+            // unrecognized tag is already logged in StartTag
         }
     }
 

Added: 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=629497&view=auto
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/parser/XhtmlBaseParserTest.java
(added)
+++ maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/parser/XhtmlBaseParserTest.java
Wed Feb 20 07:07:25 2008
@@ -0,0 +1,141 @@
+package org.apache.maven.doxia.parser;
+
+/*
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ * 
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *  under the License.
+ */
+
+import java.util.Iterator;
+
+import org.apache.maven.doxia.sink.Sink;
+import org.apache.maven.doxia.sink.SinkEventElement;
+import org.apache.maven.doxia.sink.SinkEventTestingSink;
+
+import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.util.xml.pull.MXParser;
+
+/**
+ *
+ */
+public class XhtmlBaseParserTest
+    extends PlexusTestCase
+{
+    private XhtmlBaseParser parser;
+    private final SinkEventTestingSink sink = new SinkEventTestingSink();
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        parser = new XhtmlBaseParser();
+        sink.reset();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    /** @throws Exception  */
+    public void testHeadingEventsList()
+        throws Exception
+    {
+        String text = "<p><h2></h2><h3></h3><h4></h4><h5></h5><h6></h6><h2></h2></p>";
+
+        SinkEventTestingSink sink = new SinkEventTestingSink();
+
+        parser.parse( text, sink );
+
+        Iterator it = sink.getEventList().iterator();
+
+        assertEquals( "paragraph", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "section1", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "sectionTitle1", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "sectionTitle1_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "section2", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "sectionTitle2", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "sectionTitle2_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "section3", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "sectionTitle3", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "sectionTitle3_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "section4", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "sectionTitle4", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "sectionTitle4_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "section5", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "sectionTitle5", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "sectionTitle5_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "section5_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "section4_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "section3_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "section2_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "section1_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "section1", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "sectionTitle1", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "sectionTitle1_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "paragraph_", ( (SinkEventElement) it.next() ).getName() );
+        assertFalse( it.hasNext() );
+    }
+
+    /** @throws Exception  */
+    public void testFigureEventsList()
+        throws Exception
+    {
+        String text = "<img src=\"source\" title=\"caption\" />";
+
+        SinkEventTestingSink sink = new SinkEventTestingSink();
+
+        parser.parse( text, sink );
+
+        Iterator it = sink.getEventList().iterator();
+
+        assertEquals( "figure", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "figureGraphics", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "figureCaption", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "text", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "figureCaption_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "figure_", ( (SinkEventElement) it.next() ).getName() );
+        assertFalse( it.hasNext() );
+    }
+
+    /** @throws Exception  */
+    public void testTableEventsList()
+        throws Exception
+    {
+        // TODO: table caption, see DOXIA-177
+
+        String text = "<table align=\"center\"><tr><th>Header</th></tr><tr><td>cell</td></tr></table>";
+
+        SinkEventTestingSink sink = new SinkEventTestingSink();
+
+        parser.parse( text, sink );
+
+        Iterator it = sink.getEventList().iterator();
+
+        assertEquals( "table", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "tableRows", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "tableRow", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "tableHeaderCell", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "text", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "tableHeaderCell_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "tableRow_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "tableRow", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "tableCell", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "text", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "tableCell_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "tableRow_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "tableRows_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "table_", ( (SinkEventElement) it.next() ).getName() );
+        
+        assertFalse( it.hasNext() );
+    }
+
+
+}

Propchange: maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/parser/XhtmlBaseParserTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/parser/XhtmlBaseParserTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/sink/SinkEventElement.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/sink/SinkEventElement.java?rev=629497&r1=629496&r2=629497&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/sink/SinkEventElement.java
(original)
+++ maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/sink/SinkEventElement.java
Wed Feb 20 07:07:25 2008
@@ -55,14 +55,13 @@
     }
 
     /**
-     * Check the name of the this event.
+     * Return the name of the this event.
      *
-     * @param name The name of the sink event to check.
-     * @return true if the names are equal.
+     * @return The name of the sink event.
      */
-    public boolean eventIs( String name )
+    public String getName()
     {
-        return methodName.equals( name );
+        return this.methodName;
     }
 
     /**

Modified: maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/sink/SinkEventTestingSink.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/sink/SinkEventTestingSink.java?rev=629497&r1=629496&r2=629497&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/sink/SinkEventTestingSink.java
(original)
+++ maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/sink/SinkEventTestingSink.java
Wed Feb 20 07:07:25 2008
@@ -48,6 +48,16 @@
         return this.events;
     }
 
+    /** Clears the list of sink events. */
+    public void reset()
+    {
+        this.events.clear();
+    }
+
+      //
+     // sink methods
+    //
+
     /** {@inheritDoc} */
     public void head()
     {
@@ -603,7 +613,7 @@
     }
 
     /**
-     * Adds a no-arg event to the list of events.
+     * Adds an event to the list of events.
      *
      * @param string the name of the event.
      * @param arguments The array of arguments to the sink method.

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/test/java/org/apache/maven/doxia/module/fml/FmlParserTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/test/java/org/apache/maven/doxia/module/fml/FmlParserTest.java?rev=629497&r1=629496&r2=629497&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/test/java/org/apache/maven/doxia/module/fml/FmlParserTest.java
(original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/test/java/org/apache/maven/doxia/module/fml/FmlParserTest.java
Wed Feb 20 07:07:25 2008
@@ -19,9 +19,15 @@
  * under the License.
  */
 
+import java.io.Reader;
+
+import java.util.Iterator;
+
 import org.apache.maven.doxia.module.fml.FmlParser;
 import org.apache.maven.doxia.parser.AbstractParserTest;
 import org.apache.maven.doxia.parser.Parser;
+import org.apache.maven.doxia.sink.SinkEventElement;
+import org.apache.maven.doxia.sink.SinkEventTestingSink;
 
 /**
  * @author <a href="mailto:evenisse@codehaus.org">Emmanuel Venisse</a>
@@ -42,5 +48,84 @@
         return "fml";
     }
 
+    /** @throws Exception  */
+    public void testFaqEventsList()
+        throws Exception
+    {
+
+        SinkEventTestingSink sink = new SinkEventTestingSink();
+
+        Reader reader = null;
+
+        try
+        {
+            reader = getTestReader( "simpleFaq" );
+
+            createParser().parse( reader, sink );
+        }
+        finally
+        {
+            reader.close();
+        }
+
+        Iterator it = sink.getEventList().iterator();
+
+        assertEquals( "comment", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "head", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "title", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "text", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "title_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "head_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "body", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "section1", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "sectionTitle1", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "anchor", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "text", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "anchor_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "sectionTitle1_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "paragraph", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "bold", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "text", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "bold_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "paragraph_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "numberedList", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "numberedListItem", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "link", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "text", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "link_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "numberedListItem_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "numberedList_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "section1_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "section1", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "sectionTitle1", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "text", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "sectionTitle1_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "definitionList", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "definedTerm", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "anchor", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "text", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "anchor_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "definedTerm_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "definition", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "paragraph", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "text", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "paragraph_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "table", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "tableRows", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "tableRow", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "tableCell", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "link", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "text", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "link_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "tableCell_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "tableRow_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "tableRows_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "table_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "definition_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "definitionList_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "section1_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "body_", ( (SinkEventElement) it.next() ).getName() );
+        assertFalse( it.hasNext() );
+    }
 
 }

Added: maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/test/resources/simpleFaq.fml
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/test/resources/simpleFaq.fml?rev=629497&view=auto
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/test/resources/simpleFaq.fml
(added)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/test/resources/simpleFaq.fml
Wed Feb 20 07:07:25 2008
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<faqs title="Frequently Asked Questions">
+
+  <part id="general">
+    <title>General</title>
+
+    <faq id="maven-definition">
+      <question>What does Maven mean?</question>
+      <answer><p>A maven (yi.=meyvn) is an experienced or knowledgeable person,
such as an expert or freak.</p></answer>
+    </faq>
+
+  </part>
+
+</faqs>
+

Propchange: maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/test/resources/simpleFaq.fml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/test/resources/simpleFaq.fml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

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=629497&r1=629496&r2=629497&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
Wed Feb 20 07:07:25 2008
@@ -24,9 +24,14 @@
 import java.io.Reader;
 import java.io.Writer;
 
+import java.util.Iterator;
+
 import org.apache.maven.doxia.parser.AbstractParserTest;
 import org.apache.maven.doxia.parser.Parser;
 import org.apache.maven.doxia.sink.Sink;
+import org.apache.maven.doxia.sink.SinkEventElement;
+import org.apache.maven.doxia.sink.SinkEventTestingSink;
+
 import org.codehaus.plexus.util.IOUtil;
 
 /**
@@ -137,6 +142,89 @@
         // No section, only subsection 1 and 2
         assertTrue( noNewLine( content ).indexOf( "<a href=\"#Section_11\">Section
11</a>" ) != -1 );
         assertTrue( noNewLine( content ).indexOf( "<a href=\"#Section_1211\">Section
1211</a>" ) == -1 );
+    }
+
+    /** @throws Exception  */
+    public void testHeadEventsList()
+        throws Exception
+    {
+        // TODO: separate <head> from <properties>, see DOXIA-129
+        String text = "<properties><title>title</title><author email=\"a@b.c\">John
Doe</author></properties>";
+
+        SinkEventTestingSink sink = new SinkEventTestingSink();
+
+        parser.parse( text, sink );
+
+        Iterator it = sink.getEventList().iterator();
+
+        assertEquals( "head", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "title", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "text", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "title_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "author", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "text", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "author_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "head_", ( (SinkEventElement) it.next() ).getName() );
+        assertFalse( it.hasNext() );
+    }
+
+    /** @throws Exception  */
+    public void testDocumentBodyEventsList()
+        throws Exception
+    {
+        String text = "<document><body></body></document>";
+
+        SinkEventTestingSink sink = new SinkEventTestingSink();
+
+        parser.parse( text, sink );
+
+        Iterator it = sink.getEventList().iterator();
+
+        assertEquals( "body", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "body_", ( (SinkEventElement) it.next() ).getName() );
+        assertFalse( it.hasNext() );
+    }
+
+    /** @throws Exception  */
+    public void testSectionEventsList()
+        throws Exception
+    {
+        String text = "<section name=\"sec 1\"><subsection name=\"sub 1\"></subsection></section>";
+
+        SinkEventTestingSink sink = new SinkEventTestingSink();
+
+        parser.parse( text, sink );
+
+        Iterator it = sink.getEventList().iterator();
+
+        assertEquals( "section1", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "sectionTitle1", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "text", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "sectionTitle1_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "section2", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "sectionTitle2", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "text", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "sectionTitle2_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "section2_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "section1_", ( (SinkEventElement) it.next() ).getName() );
+        assertFalse( it.hasNext() );
+    }
+
+    /** @throws Exception  */
+    public void testSourceEventsList()
+        throws Exception
+    {
+        String text = "<source></source>";
+
+        SinkEventTestingSink sink = new SinkEventTestingSink();
+
+        parser.parse( text, sink );
+
+        Iterator it = sink.getEventList().iterator();
+
+        assertEquals( "verbatim", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "verbatim_", ( (SinkEventElement) it.next() ).getName() );
+        assertFalse( it.hasNext() );
     }
 
     /**

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlParserTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlParserTest.java?rev=629497&r1=629496&r2=629497&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlParserTest.java
(original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlParserTest.java
Wed Feb 20 07:07:25 2008
@@ -19,12 +19,14 @@
  * under the License.
  */
 
+import java.util.Iterator;
+
 import org.apache.maven.doxia.WellformednessCheckingSink;
 import org.apache.maven.doxia.parser.AbstractParserTest;
 import org.apache.maven.doxia.parser.Parser;
+import org.apache.maven.doxia.sink.SinkEventElement;
+import org.apache.maven.doxia.sink.SinkEventTestingSink;
 
-import java.io.FileReader;
-import java.io.Reader;
 
 /**
  * @author <a href="mailto:lars@trieloff.net">Lars Trieloff</a>
@@ -41,6 +43,66 @@
     protected String outputExtension()
     {
         return "xhtml";
+    }
+
+    /** @throws Exception  */
+    public void testDocumentBodyEventsList()
+        throws Exception
+    {
+        String text = "<html><body></body></html>";
+
+        SinkEventTestingSink sink = new SinkEventTestingSink();
+
+        ( (XhtmlParser) createParser() ).parse( text, sink );
+
+        Iterator it = sink.getEventList().iterator();
+
+        assertEquals( "body", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "body_", ( (SinkEventElement) it.next() ).getName() );
+        assertFalse( it.hasNext() );
+    }
+
+    /** @throws Exception  */
+    public void testHeadEventsList()
+        throws Exception
+    {
+        String text = "<head><title>Title</title><meta name=\"author\"
content=\"Author\" /><meta name=\"date\" content=\"Date\" /></head>";
+
+        SinkEventTestingSink sink = new SinkEventTestingSink();
+
+        ( (XhtmlParser) createParser() ).parse( text, sink );
+
+        Iterator it = sink.getEventList().iterator();
+
+        assertEquals( "head", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "title", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "text", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "title_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "author", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "text", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "author_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "date", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "text", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "date_", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "head_", ( (SinkEventElement) it.next() ).getName() );
+        assertFalse( it.hasNext() );
+    }
+
+    /** @throws Exception  */
+    public void testPreEventsList()
+        throws Exception
+    {
+        String text = "<pre></pre>";
+
+        SinkEventTestingSink sink = new SinkEventTestingSink();
+
+        ( (XhtmlParser) createParser() ).parse( text, sink );
+
+        Iterator it = sink.getEventList().iterator();
+
+        assertEquals( "verbatim", ( (SinkEventElement) it.next() ).getName() );
+        assertEquals( "verbatim_", ( (SinkEventElement) it.next() ).getName() );
+        assertFalse( it.hasNext() );
     }
 
 }



Mime
View raw message