From 160baa2f9d1160b3e5bb7720dd8c3668589776c3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 1 Apr 2011 11:26:05 +0200 Subject: [PATCH] Add test case for the improved link parser. --- .../sone/text/FreenetLinkParserTest.java | 78 ++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/test/java/net/pterodactylus/sone/text/FreenetLinkParserTest.java 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()); + } + +} -- 2.7.4