You are viewing a plain text version of this content. The canonical link for it is here.
Posted to doxia-commits@maven.apache.org by lt...@apache.org on 2007/12/16 21:23:22 UTC
svn commit: r604693 - in
/maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src:
main/java/org/apache/maven/doxia/module/twiki/
main/java/org/apache/maven/doxia/module/twiki/parser/
test/java/org/apache/maven/doxia/module/twiki/parser/
Author: ltheussl
Date: Sun Dec 16 12:23:21 2007
New Revision: 604693
URL: http://svn.apache.org/viewvc?rev=604693&view=rev
Log:
[DOXIA-196] Support for <verbatim> block
Submitted by: Juan F. Codagnone, Christian Nardi
Added:
maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/VerbatimBlock.java (with props)
maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/VerbatimBlockParser.java (with props)
maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/test/java/org/apache/maven/doxia/module/twiki/parser/VerbatimTest.java (with props)
Modified:
maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/TWikiParser.java
maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/ParagraphBlockParser.java
maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/SectionBlockParser.java
maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/test/java/org/apache/maven/doxia/module/twiki/parser/AbstractBlockTestCase.java
maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/test/java/org/apache/maven/doxia/module/twiki/parser/SectionTest.java
Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/TWikiParser.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/TWikiParser.java?rev=604693&r1=604692&r2=604693&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/TWikiParser.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/TWikiParser.java Sun Dec 16 12:23:21 2007
@@ -29,13 +29,13 @@
import org.apache.maven.doxia.module.twiki.parser.SectionBlockParser;
import org.apache.maven.doxia.module.twiki.parser.TableBlockParser;
import org.apache.maven.doxia.module.twiki.parser.TextParser;
+import org.apache.maven.doxia.module.twiki.parser.VerbatimBlockParser;
import org.apache.maven.doxia.module.twiki.parser.XHTMLWikiWordLinkResolver;
import org.apache.maven.doxia.parser.AbstractTextParser;
import org.apache.maven.doxia.parser.ParseException;
import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.doxia.util.ByLineReaderSource;
import org.apache.maven.doxia.util.ByLineSource;
-import org.codehaus.plexus.util.StringUtils;
import java.io.Reader;
import java.util.ArrayList;
@@ -54,6 +54,7 @@
public class TWikiParser
extends AbstractTextParser
{
+ private static final int EXTENSION_LENGTH = 6;
/**
* paragraph parser. stateless
*/
@@ -89,6 +90,11 @@
private final TableBlockParser tableParser = new TableBlockParser();
/**
+ * verbatim parser
+ */
+ private final VerbatimBlockParser verbatimParser = new VerbatimBlockParser();
+
+ /**
* list of parsers to try to apply to the toplevel
*/
private final BlockParser [] parsers;
@@ -103,8 +109,10 @@
paraParser.setTextParser( formatTextParser );
paraParser.setHrulerParser( hrulerParser );
paraParser.setTableBlockParser( tableParser );
+ paraParser.setVerbatimParser( verbatimParser );
sectionParser.setParaParser( paraParser );
sectionParser.setHrulerParser( hrulerParser );
+ sectionParser.setVerbatimBlockParser( verbatimParser );
listParser.setTextParser( formatTextParser );
formatTextParser.setTextParser( textParser );
tableParser.setTextParser( formatTextParser );
@@ -112,6 +120,7 @@
parsers = new BlockParser[]{
sectionParser,
hrulerParser,
+ verbatimParser,
paraParser,
};
}
@@ -177,7 +186,7 @@
sink.head();
final String title = getTitle( blocks, source );
- if( title != null )
+ if ( title != null )
{
sink.title();
sink.text( title );
@@ -210,25 +219,25 @@
{
final Block block = (Block) it.next();
- if( block instanceof SectionBlock )
+ if ( block instanceof SectionBlock )
{
final SectionBlock sectionBlock = (SectionBlock) block;
title = sectionBlock.getTitle();
}
}
- if( title == null )
+ if ( title == null )
{
String name = source.getName();
- if( name != null )
+ if ( name != null )
{
name = name.trim();
- if( name.length() != 0 )
+ if ( name.length() != 0 )
{
- if(name.endsWith(".twiki"))
+ if ( name.endsWith( ".twiki" ) )
{
- title = name.substring( 0, name.length() - 6 );
+ title = name.substring( 0, name.length() - EXTENSION_LENGTH );
}
else
{
Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/ParagraphBlockParser.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/ParagraphBlockParser.java?rev=604693&r1=604692&r2=604693&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/ParagraphBlockParser.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/ParagraphBlockParser.java Sun Dec 16 12:23:21 2007
@@ -61,6 +61,11 @@
* {@link TableBlockParser} to use. injected
*/
private TableBlockParser tableBlockParser;
+
+ /**
+ * {@link TableBlockParser} to use. injected
+ */
+ private VerbatimBlockParser verbatimParser;
/**
* no operation block
@@ -69,14 +74,22 @@
/**
* @see BlockParser#accept(String)
+ * @param line text line
+ * @return <code>true</code> if this class can handle this line
*/
public final boolean accept( final String line )
{
- return !sectionParser.accept( line ) && !hrulerParser.accept( line );
+ return !sectionParser.accept( line )
+ && !hrulerParser.accept( line )
+ && !verbatimParser.accept( line );
}
/**
* @see BlockParser#visit(String, ByLineSource)
+ * @param line a line of text
+ * @param source the source of lines
+ * @return a block
+ * @throws ParseException on error
*/
public final Block visit( final String line, final ByLineSource source )
throws ParseException
@@ -97,11 +110,7 @@
if ( m.lookingAt() )
{
- if ( !sawText )
- {
- // ignore
- }
- else
+ if ( sawText )
{
break;
}
@@ -131,8 +140,9 @@
sb.append( " " );
}
}
+ l = source.getNextLine();
}
- while ( ( l = source.getNextLine() ) != null && accept( l ) );
+ while ( l != null && accept( l ) );
if ( line != null )
{
@@ -160,76 +170,92 @@
/**
* Sets the sectionParser.
*
- * @param sectionParser <code>SectionBlockParser</code> with the sectionParser.
+ * @param aSectionParser <code>SectionBlockParser</code> with the sectionParser.
*/
- public final void setSectionParser( final SectionBlockParser sectionParser )
+ public final void setSectionParser( final SectionBlockParser aSectionParser )
{
- if ( sectionParser == null )
+ if ( aSectionParser == null )
{
throw new IllegalArgumentException( "arg can't be null" );
}
- this.sectionParser = sectionParser;
+ this.sectionParser = aSectionParser;
}
/**
* Sets the listParser.
*
- * @param listParser <code>ListBlockParser</code> with the listParser.
+ * @param aListParser <code>ListBlockParser</code> with the listParser.
*/
- public final void setListParser( final GenericListBlockParser listParser )
+ public final void setListParser( final GenericListBlockParser aListParser )
{
- if ( listParser == null )
+ if ( aListParser == null )
{
throw new IllegalArgumentException( "arg can't be null" );
}
- this.listParser = listParser;
+ this.listParser = aListParser;
}
/**
* Sets the formatTextParser.
*
- * @param textParser <code>FormatedTextParser</code>
+ * @param aTextParser <code>FormatedTextParser</code>
* with the formatTextParser.
*/
- public final void setTextParser( final FormatedTextParser textParser )
+ public final void setTextParser( final FormatedTextParser aTextParser )
{
- if ( textParser == null )
+ if ( aTextParser == null )
{
throw new IllegalArgumentException( "arg can't be null" );
}
- this.textParser = textParser;
+ this.textParser = aTextParser;
}
/**
* Sets the hrulerParser.
*
- * @param hrulerParser <code>HRuleBlockParser</code> with the hrulerParser.
+ * @param aHrulerParser <code>HRuleBlockParser</code> with the hrulerParser.
*/
- public final void setHrulerParser( final HRuleBlockParser hrulerParser )
+ public final void setHrulerParser( final HRuleBlockParser aHrulerParser )
{
- if ( hrulerParser == null )
+ if ( aHrulerParser == null )
{
throw new IllegalArgumentException( "arg can't be null" );
}
- this.hrulerParser = hrulerParser;
+ this.hrulerParser = aHrulerParser;
}
/**
- * @param tableBlockParser Table parser to use
+ * @param aTableBlockParser Table parser to use
*/
public final void setTableBlockParser(
- final TableBlockParser tableBlockParser )
+ final TableBlockParser aTableBlockParser )
{
- if ( tableBlockParser == null )
+ if ( aTableBlockParser == null )
{
throw new IllegalArgumentException( "arg can't be null" );
}
- this.tableBlockParser = tableBlockParser;
+ this.tableBlockParser = aTableBlockParser;
+ }
+
+ /**
+ * Sets the verbatimParser.
+ *
+ * @param aVerbatimParser <code>VerbatimBlockParser</code> with the verbatimParser.
+ */
+ public final void setVerbatimParser( final VerbatimBlockParser aVerbatimParser )
+ {
+ if ( aVerbatimParser == null )
+ {
+ throw new IllegalArgumentException( "arg can't be null" );
+ }
+ this.verbatimParser = aVerbatimParser;
}
+
+
}
Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/SectionBlockParser.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/SectionBlockParser.java?rev=604693&r1=604692&r2=604693&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/SectionBlockParser.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/SectionBlockParser.java Sun Dec 16 12:23:21 2007
@@ -49,6 +49,9 @@
* {@link ParagraphBlockParser} to use. injected
*/
private HRuleBlockParser hrulerParser;
+
+ /** {@link VerbatimBlockParser} */
+ private VerbatimBlockParser verbatimBlockParser;
/**
* @see BlockParser#accept(String)
@@ -84,7 +87,11 @@
}
else
{
- blocks.add( paraParser.visit( newLine, source ) );
+ if(verbatimBlockParser.accept( newLine )) {
+ blocks.add( verbatimBlockParser.visit( newLine, source ) );
+ } else {
+ blocks.add( paraParser.visit( newLine, source ) );
+ }
}
}
@@ -144,4 +151,17 @@
this.hrulerParser = hrulerParser;
}
+ /**
+ * Sets the verbatimBlockParser.
+ *
+ * @param verbatimBlockParser <code>VerbatimBlockParser</code> with the verbatimBlockParser.
+ */
+ public final void setVerbatimBlockParser(VerbatimBlockParser verbatimBlockParser) {
+ if ( verbatimBlockParser == null )
+ {
+ throw new IllegalArgumentException( "argument can't be null" );
+ }
+ this.verbatimBlockParser = verbatimBlockParser;
+ }
+
}
Added: maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/VerbatimBlock.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/VerbatimBlock.java?rev=604693&view=auto
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/VerbatimBlock.java (added)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/VerbatimBlock.java Sun Dec 16 12:23:21 2007
@@ -0,0 +1,64 @@
+package org.apache.maven.doxia.module.twiki.parser;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.doxia.sink.Sink;
+
+
+/**
+ * Represents a verbatim block
+ *
+ * @author Christian Nardi
+ * @since Nov 8, 2007
+ */
+public class VerbatimBlock extends AbstractFatherBlock
+{
+
+ /**
+ * Creates the VerbatimBlock.
+ *
+ * @param childBlocks child blocks
+ */
+ public VerbatimBlock( final Block [] childBlocks )
+ {
+ super( childBlocks );
+ }
+
+
+ /**
+ * @see AbstractFatherBlock#before(org.apache.maven.doxia.sink.Sink)
+ * @param sink a sink to fill
+ */
+
+ public final void before( final Sink sink )
+ {
+ sink.verbatim( true );
+ }
+
+ /**
+ * @see AbstractFatherBlock#after(org.apache.maven.doxia.sink.Sink)
+ * @param sink a sink to fill
+ */
+
+ public final void after( final Sink sink )
+ {
+ sink.verbatim_();
+ }
+}
Propchange: maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/VerbatimBlock.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/VerbatimBlock.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/VerbatimBlockParser.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/VerbatimBlockParser.java?rev=604693&view=auto
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/VerbatimBlockParser.java (added)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/VerbatimBlockParser.java Sun Dec 16 12:23:21 2007
@@ -0,0 +1,94 @@
+package org.apache.maven.doxia.module.twiki.parser;
+
+/*
+ * 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.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.maven.doxia.parser.ParseException;
+import org.apache.maven.doxia.util.ByLineSource;
+
+
+/**
+ * Parse verbatim blocks
+ *
+ * @author Christian Nardi
+ * @since Nov 8, 2007
+ */
+public class VerbatimBlockParser implements BlockParser
+{
+ /**
+ * pattern to detect verbatim start tags
+ */
+ private static final Pattern VERBATIM_START_PATTERN =
+ Pattern.compile( "\\s*<verbatim>" );
+
+ private static final Pattern VERBATIM_END_PATTERN =
+ Pattern.compile( "</verbatim>" );
+
+ /**
+ * @see BlockParser#accept(String)
+ * @param line text line
+ * @return <code>true</code> if this class can handle this line
+ */
+ public final boolean accept( final String line )
+ {
+ return VERBATIM_START_PATTERN.matcher( line ).lookingAt();
+ }
+
+ /**
+ * @see BlockParser#visit(String, ByLineSource)
+ * @param line a line of text
+ * @param source the source of lines
+ * @return a block
+ * @throws ParseException on error
+ */
+ public final Block visit( final String line, final ByLineSource source )
+ throws ParseException
+ {
+
+ if ( !accept( line ) )
+ {
+ throw new IllegalAccessError( "call accept before this ;)" );
+ }
+
+ final List lines = new ArrayList();
+ Matcher matcher = VERBATIM_START_PATTERN.matcher( line );
+ matcher.find();
+ String l = line.substring( matcher.end() );
+
+ while ( l != null )
+ {
+ matcher = VERBATIM_END_PATTERN.matcher( l );
+ if ( matcher.find() )
+ {
+ lines.add( new TextBlock( l.substring( 0, matcher.start() ) + "\n" ) );
+ break;
+ }
+ lines.add( new TextBlock( l + "\n" ) );
+ l = source.getNextLine();
+ }
+
+
+ return new VerbatimBlock( (Block[]) lines.toArray( new Block[]{} ) );
+ }
+}
Propchange: maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/VerbatimBlockParser.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/VerbatimBlockParser.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/test/java/org/apache/maven/doxia/module/twiki/parser/AbstractBlockTestCase.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/AbstractBlockTestCase.java?rev=604693&r1=604692&r2=604693&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/test/java/org/apache/maven/doxia/module/twiki/parser/AbstractBlockTestCase.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/test/java/org/apache/maven/doxia/module/twiki/parser/AbstractBlockTestCase.java Sun Dec 16 12:23:21 2007
@@ -68,7 +68,10 @@
* TWiki used in all the tests
*/
protected final TWikiParser twikiParser = new TWikiParser();
-
+ /**
+ * Parser for verbatim blocks
+ */
+ private final VerbatimBlockParser verbatimParser = new VerbatimBlockParser();
/**
* Creates the AbstractBlockTestCase.
*/
@@ -81,8 +84,19 @@
paraParser.setTextParser( formatTextParser );
paraParser.setHrulerParser( hruleParser );
paraParser.setTableBlockParser( tableParser );
+ paraParser.setVerbatimParser( verbatimParser );
+ sectionParser.setVerbatimBlockParser( new VerbatimBlockParser() );
listParser.setTextParser( formatTextParser );
formatTextParser.setTextParser( textParser );
tableParser.setTextParser( formatTextParser );
+ }
+ /**
+ * Returns the verbatimParser.
+ *
+ * @return <code>VerbatimBlockParser</code> with the verbatimParser.
+ */
+ protected final VerbatimBlockParser getVerbatimParser()
+ {
+ return verbatimParser;
}
}
Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/test/java/org/apache/maven/doxia/module/twiki/parser/SectionTest.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/SectionTest.java?rev=604693&r1=604692&r2=604693&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/test/java/org/apache/maven/doxia/module/twiki/parser/SectionTest.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/test/java/org/apache/maven/doxia/module/twiki/parser/SectionTest.java Sun Dec 16 12:23:21 2007
@@ -150,6 +150,7 @@
+ "Fine!! thanks";
final SectionBlockParser parser = sectionParser;
+ parser.setVerbatimBlockParser( new VerbatimBlockParser() );
final ByLineReaderSource source = new ByLineReaderSource(
new StringReader( text ) );
final SectionBlock block = (SectionBlock) parser.visit( source
Added: maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/test/java/org/apache/maven/doxia/module/twiki/parser/VerbatimTest.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/VerbatimTest.java?rev=604693&view=auto
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/test/java/org/apache/maven/doxia/module/twiki/parser/VerbatimTest.java (added)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/test/java/org/apache/maven/doxia/module/twiki/parser/VerbatimTest.java Sun Dec 16 12:23:21 2007
@@ -0,0 +1,135 @@
+package org.apache.maven.doxia.module.twiki.parser;
+
+import java.io.StringReader;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.maven.doxia.parser.ParseException;
+import org.apache.maven.doxia.util.ByLineReaderSource;
+import org.apache.maven.doxia.util.ByLineSource;
+
+/*
+ * 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.
+ */
+
+
+
+/**
+ * Tests the {@link org.apache.maven.doxia.module.twiki.parser.VerbatimBlock}
+ *
+ * @author Christian Nardi
+ * @since Nov 8, 2007
+ */
+public class VerbatimTest extends AbstractBlockTestCase
+{
+
+ /**
+ * unit test the regex
+ */
+ public final void testRegex()
+ {
+ assertTrue( getVerbatimParser().accept( "<verbatim>" ) );
+ assertTrue( getVerbatimParser().accept( " <verbatim>" ) );
+ assertTrue( getVerbatimParser().accept( "<verbatim> a word" ) );
+ assertTrue( getVerbatimParser().accept( "<verbatim> another Word" ) );
+ }
+
+
+ /**
+ * @throws ParseException if the parser does not accept the line
+ *
+ */
+ public void testVerbatim() throws ParseException
+ {
+ final StringReader sw = new StringReader( ""
+ + " <verbatim> hello, \n"
+ + " this is a verbatim text \n"
+ + " which i would like to test \n"
+ + " Thanks </verbatim>"
+ );
+
+ final ByLineSource source = new ByLineReaderSource( sw );
+
+ Block block, expected;
+ expected = new VerbatimBlock( new Block[]{
+ new TextBlock( " hello, \n" ) ,
+ new TextBlock( " this is a verbatim text \n" ) ,
+ new TextBlock( " which i would like to test \n" ) ,
+ new TextBlock( " Thanks \n" ) ,
+ } );
+
+ block = getVerbatimParser().visit( source.getNextLine(), source );
+ assertEquals( block, expected );
+ }
+
+ /**
+ * @throws Exception .
+ */
+ public void testTwiki() throws Exception
+ {
+ final StringReader sw = new StringReader( "hello this is a paragraph \n"
+ + " <verbatim> hello, \n"
+ + " this is a verbatim text \n"
+ + " which i would like to test \n"
+ + " Thanks </verbatim>"
+ );
+ final ByLineSource source = new ByLineReaderSource( sw );
+
+ Block[] expected;
+ expected = new Block[]{
+ new ParagraphBlock( new Block[] {
+ new TextBlock( "hello this is a paragraph" ),
+ } ),
+ new VerbatimBlock( new Block[]{
+ new TextBlock( " hello, \n" ) ,
+ new TextBlock( " this is a verbatim text \n" ) ,
+ new TextBlock( " which i would like to test \n" ) ,
+ new TextBlock( " Thanks \n" ) ,
+ } )
+ };
+
+ List block = twikiParser.parse( source );
+ assertTrue( Arrays.equals(
+ block.toArray(), expected ) );
+
+
+ }
+
+ /** test */
+ public void testVerbatimAfterSection() throws ParseException
+ {
+ final StringReader sw = new StringReader( "---++ fooo\n"
+ + " <verbatim> hello, \n"
+ + " Thanks </verbatim>"
+ );
+ final ByLineSource source = new ByLineReaderSource( sw );
+
+ Block[] expected;
+ expected = new Block[]{
+ new SectionBlock( "foo", 2, new Block[] {
+ new VerbatimBlock( new Block[]{
+ new TextBlock( " hello, \n" ) ,
+ new TextBlock( " Thanks \n" ) ,
+ } )
+ } ),
+ };
+
+ List block = twikiParser.parse( source );
+ assertTrue( Arrays.equals( block.toArray(), expected ) );
+ }
+}
Propchange: maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/test/java/org/apache/maven/doxia/module/twiki/parser/VerbatimTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/doxia/doxia/trunk/doxia-modules/doxia-module-twiki/src/test/java/org/apache/maven/doxia/module/twiki/parser/VerbatimTest.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"