001package org.apache.maven.doxia.module.twiki.parser; 002 003import static org.junit.Assert.assertArrayEquals; 004 005import java.io.StringReader; 006import java.util.List; 007 008import org.apache.maven.doxia.parser.ParseException; 009import org.apache.maven.doxia.util.ByLineReaderSource; 010import org.apache.maven.doxia.util.ByLineSource; 011 012/* 013 * Licensed to the Apache Software Foundation (ASF) under one 014 * or more contributor license agreements. See the NOTICE file 015 * distributed with this work for additional information 016 * regarding copyright ownership. The ASF licenses this file 017 * to you under the Apache License, Version 2.0 (the 018 * "License"); you may not use this file except in compliance 019 * with the License. You may obtain a copy of the License at 020 * 021 * http://www.apache.org/licenses/LICENSE-2.0 022 * 023 * Unless required by applicable law or agreed to in writing, 024 * software distributed under the License is distributed on an 025 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 026 * KIND, either express or implied. See the License for the 027 * specific language governing permissions and limitations 028 * under the License. 029 */ 030 031/** 032 * Tests the {@link org.apache.maven.doxia.module.twiki.parser.VerbatimBlock} 033 * 034 * @author Christian Nardi 035 * @since Nov 8, 2007 036 */ 037public class VerbatimTest 038 extends AbstractBlockTestCase 039{ 040 041 /** 042 * unit test the regex 043 */ 044 public final void testRegex() 045 { 046 assertTrue( getVerbatimParser().accept( "<verbatim>" ) ); 047 assertTrue( getVerbatimParser().accept( " <verbatim>" ) ); 048 assertTrue( getVerbatimParser().accept( "<verbatim> a word" ) ); 049 assertTrue( getVerbatimParser().accept( "<verbatim> another Word" ) ); 050 } 051 052 /** 053 * @throws ParseException if the parser does not accept the line 054 * 055 */ 056 public void testVerbatim() 057 throws ParseException 058 { 059 final StringReader sw = 060 new StringReader( "" + " <verbatim> hello, \n" + " this is a verbatim text \n" 061 + " which i would like to test \n" + " Thanks </verbatim>" ); 062 063 final ByLineSource source = new ByLineReaderSource( sw ); 064 065 Block block, expected; 066 expected = 067 new VerbatimBlock( new Block[] { new TextBlock( " hello, \n" ), 068 new TextBlock( " this is a verbatim text \n" ), new TextBlock( " which i would like to test \n" ), 069 new TextBlock( " Thanks \n" ) } ); 070 071 block = getVerbatimParser().visit( source.getNextLine(), source ); 072 assertEquals( block, expected ); 073 } 074 075 /** 076 * @throws Exception . 077 */ 078 public void testTwiki() 079 throws Exception 080 { 081 final StringReader sw = 082 new StringReader( "hello this is a paragraph \n" + " <verbatim> hello, \n" 083 + " this is a verbatim text \n" + " which i would like to test \n" + " Thanks </verbatim>" ); 084 final ByLineSource source = new ByLineReaderSource( sw ); 085 086 Block[] expected; 087 expected = 088 new Block[] { 089 new ParagraphBlock( new Block[] { new TextBlock( "hello this is a paragraph" ) } ), 090 new VerbatimBlock( new Block[] { new TextBlock( " hello, \n" ), 091 new TextBlock( " this is a verbatim text \n" ), 092 new TextBlock( " which i would like to test \n" ), new TextBlock( " Thanks \n" ) } ) }; 093 094 List<Block> block = twikiParser.parse( source ); 095 assertArrayEquals( expected, block.toArray() ); 096 097 } 098 099 /** test 100 * @throws org.apache.maven.doxia.parser.ParseException 101 */ 102 public void testVerbatimAfterSection() 103 throws ParseException 104 { 105 final StringReader sw = 106 new StringReader( "---++ fooo\n" + " <verbatim> hello, \n" + " Thanks </verbatim>" ); 107 final ByLineSource source = new ByLineReaderSource( sw ); 108 109 Block[] expected; 110 expected = 111 new Block[] { new SectionBlock( "foo", 2, new Block[] { new VerbatimBlock( new Block[] { 112 new TextBlock( " hello, \n" ), new TextBlock( " Thanks \n" ) } ) } ) }; 113 114 List<Block> block = twikiParser.parse( source ); 115 assertArrayEquals( expected, block.toArray() ); 116 } 117}