001package org.apache.maven.doxia.module.twiki.parser; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.util.Iterator; 023import org.apache.maven.doxia.module.twiki.TWikiParser; 024import org.apache.maven.doxia.parser.AbstractParserTest; 025import org.apache.maven.doxia.parser.Parser; 026import org.apache.maven.doxia.sink.impl.SinkEventElement; 027import org.apache.maven.doxia.sink.impl.SinkEventTestingSink; 028 029/** 030 * @author ltheussl 031 */ 032public class TwikiParserTest 033 extends AbstractParserTest 034{ 035 private TWikiParser parser; 036 037 private static final String id = "twiki"; 038 039 @Override 040 protected void setUp() 041 throws Exception 042 { 043 super.setUp(); 044 045 this.parser = (TWikiParser) lookup( Parser.ROLE, id ); 046 } 047 048 @Override 049 protected Parser createParser() 050 { 051 return parser; 052 } 053 054 @Override 055 protected String outputExtension() 056 { 057 return id; 058 } 059 060 /** @throws Exception */ 061 public void testHtml() 062 throws Exception 063 { 064 // DOXIA-441 065 final String text = "_ita_, *b* and a bit of <font color=\"red\">red</font>"; 066 067 SinkEventTestingSink sink = new SinkEventTestingSink(); 068 069 parser.parse( text, sink ); 070 071 Iterator<SinkEventElement> it = sink.getEventList().iterator(); 072 073 assertStartsWith( it, "head", "head_", "body", "paragraph" ); 074 075 assertEquals( "italic", ( it.next() ).getName() ); 076 assertEquals( it.next(), "text", "ita" ); 077 assertEquals( "italic_", ( it.next() ).getName() ); 078 079 assertEquals( it.next(), "text", ", " ); 080 081 assertEquals( "bold", ( it.next() ).getName() ); 082 assertEquals( it.next(), "text", "b" ); 083 assertEquals( "bold_", ( it.next() ).getName() ); 084 085 assertEquals( it.next(), "text", " and a bit of " ); 086 087 assertEquals( it.next(), "rawText", "<font color=\"red\">" ); 088 assertEquals( it.next(), "text", "red" ); 089 assertEquals( it.next(), "rawText", "</font>" ); 090 091 assertEquals( it, "paragraph_", "body_", "flush", "close" ); 092 } 093}