From: David ‘Bombe’ Roden Date: Fri, 1 Apr 2011 09:26:05 +0000 (+0200) Subject: Add test case for the improved link parser. X-Git-Tag: 0.6^2~33 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=160baa2f9d1160b3e5bb7720dd8c3668589776c3 Add test case for the improved link parser. --- diff --git a/src/test/java/net/pterodactylus/sone/text/FreenetLinkParserTest.java b/src/test/java/net/pterodactylus/sone/text/FreenetLinkParserTest.java new file mode 100644 index 0000000..e350961 --- /dev/null +++ b/src/test/java/net/pterodactylus/sone/text/FreenetLinkParserTest.java @@ -0,0 +1,78 @@ +/* + * Sone - FreenetLinkParserTest.java - Copyright © 2010 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sone.text; + +import java.io.IOException; +import java.io.StringReader; + +import junit.framework.TestCase; +import net.pterodactylus.util.template.HtmlFilter; +import net.pterodactylus.util.template.TemplateContextFactory; + +/** + * JUnit test case for {@link FreenetLinkParser}. + * + * @author David ‘Bombe’ Roden + */ +public class FreenetLinkParserTest extends TestCase { + + /** + * Tests the parser. + * + * @throws IOException + * if an I/O error occurs + */ + public void testParser() throws IOException { + TemplateContextFactory templateContextFactory = new TemplateContextFactory(); + templateContextFactory.addFilter("html", new HtmlFilter()); + FreenetLinkParser parser = new FreenetLinkParser(templateContextFactory); + FreenetLinkParserContext context = new FreenetLinkParserContext(null); + Part part; + + part = parser.parse(context, new StringReader("Text.")); + assertEquals("Text.", part.toString()); + + part = parser.parse(context, new StringReader("Text.\nText.")); + assertEquals("Text.\nText.", part.toString()); + + part = parser.parse(context, new StringReader("Text.\n\nText.")); + assertEquals("Text.\n\nText.", part.toString()); + + part = parser.parse(context, new StringReader("Text.\n\n\nText.")); + assertEquals("Text.\n\nText.", part.toString()); + + part = parser.parse(context, new StringReader("\nText.\n\n\nText.")); + assertEquals("Text.\n\nText.", part.toString()); + + part = parser.parse(context, new StringReader("\nText.\n\n\nText.\n")); + assertEquals("Text.\n\nText.", part.toString()); + + part = parser.parse(context, new StringReader("\nText.\n\n\nText.\n\n")); + assertEquals("Text.\n\nText.", part.toString()); + + part = parser.parse(context, new StringReader("\nText.\n\n\n\nText.\n\n\n")); + assertEquals("Text.\n\nText.", part.toString()); + + part = parser.parse(context, new StringReader("\n\nText.\n\n\n\nText.\n\n\n")); + assertEquals("Text.\n\nText.", part.toString()); + + part = parser.parse(context, new StringReader("\n\nText. KSK@a text.\n\n\n\nText.\n\n\n")); + assertEquals("Text. a text.\n\nText.", part.toString()); + } + +}