Store request in link parser context.
[Sone.git] / src / test / java / net / pterodactylus / sone / text / FreenetLinkParserTest.java
1 /*
2  * Sone - FreenetLinkParserTest.java - Copyright © 2010 David Roden
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 package net.pterodactylus.sone.text;
19
20 import java.io.IOException;
21 import java.io.StringReader;
22
23 import junit.framework.TestCase;
24 import net.pterodactylus.util.template.HtmlFilter;
25 import net.pterodactylus.util.template.TemplateContextFactory;
26
27 /**
28  * JUnit test case for {@link FreenetLinkParser}.
29  *
30  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
31  */
32 public class FreenetLinkParserTest extends TestCase {
33
34         /**
35          * Tests the parser.
36          *
37          * @throws IOException
38          *             if an I/O error occurs
39          */
40         public void testParser() throws IOException {
41                 TemplateContextFactory templateContextFactory = new TemplateContextFactory();
42                 templateContextFactory.addFilter("html", new HtmlFilter());
43                 FreenetLinkParser parser = new FreenetLinkParser(null, templateContextFactory);
44                 FreenetLinkParserContext context = new FreenetLinkParserContext(null, null);
45                 Part part;
46
47                 part = parser.parse(context, new StringReader("Text."));
48                 assertEquals("Text.", part.toString());
49
50                 part = parser.parse(context, new StringReader("Text.\nText."));
51                 assertEquals("Text.\nText.", part.toString());
52
53                 part = parser.parse(context, new StringReader("Text.\n\nText."));
54                 assertEquals("Text.\n\nText.", part.toString());
55
56                 part = parser.parse(context, new StringReader("Text.\n\n\nText."));
57                 assertEquals("Text.\n\nText.", part.toString());
58
59                 part = parser.parse(context, new StringReader("\nText.\n\n\nText."));
60                 assertEquals("Text.\n\nText.", part.toString());
61
62                 part = parser.parse(context, new StringReader("\nText.\n\n\nText.\n"));
63                 assertEquals("Text.\n\nText.", part.toString());
64
65                 part = parser.parse(context, new StringReader("\nText.\n\n\nText.\n\n"));
66                 assertEquals("Text.\n\nText.", part.toString());
67
68                 part = parser.parse(context, new StringReader("\nText.\n\n\n\nText.\n\n\n"));
69                 assertEquals("Text.\n\nText.", part.toString());
70
71                 part = parser.parse(context, new StringReader("\n\nText.\n\n\n\nText.\n\n\n"));
72                 assertEquals("Text.\n\nText.", part.toString());
73
74                 part = parser.parse(context, new StringReader("\n\nText. KSK@a text.\n\n\n\nText.\n\n\n"));
75                 assertEquals("Text. <a class=\"freenet\" href=\"/KSK@a\" title=\"KSK@a\">a</a> text.\n\nText.", part.toString());
76         }
77
78 }