X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftext%2FSoneTextParserTest.java;fp=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftext%2FSoneTextParserTest.java;h=f0b0e1bd9464549fb23eb3d2f9530bd99c5b67e9;hb=6b9c7c806fd1fc168e598d6e4eb6ee46ad2aa6fd;hp=0000000000000000000000000000000000000000;hpb=ff0704341bf464cf0d15125962b082e71a038ab7;p=Sone.git
diff --git a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java
new file mode 100644
index 0000000..f0b0e1b
--- /dev/null
+++ b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java
@@ -0,0 +1,74 @@
+/*
+ * Sone - SoneTextParserTest.java - Copyright © 2011 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;
+
+/**
+ * JUnit test case for {@link SoneTextParser}.
+ *
+ * @author David âBombeâ Roden
+ */
+public class SoneTextParserTest extends TestCase {
+
+ /**
+ * Tests basic plain-text operation of the parser.
+ *
+ * @throws IOException
+ * if an I/O error occurs
+ */
+ public void testPlainText() throws IOException {
+ SoneTextParser soneTextParser = new SoneTextParser(null, null);
+ Iterable parts;
+ StringBuilder text = new StringBuilder();
+
+ /* check basic operation. */
+ text.setLength(0);
+ parts = soneTextParser.parse(null, new StringReader("Test."));
+ assertNotNull("Parts", parts);
+ for (Part part : parts) {
+ assertTrue("Part is PlainTextPart", part instanceof PlainTextPart);
+ text.append(((PlainTextPart) part).getText());
+ }
+ assertEquals("Part Text", "Test.", text.toString());
+
+ /* check empty lines at start and end. */
+ text.setLength(0);
+ parts = soneTextParser.parse(null, new StringReader("\nTest.\n\n"));
+ assertNotNull("Parts", parts);
+ for (Part part : parts) {
+ assertTrue("Part is PlainTextPart", part instanceof PlainTextPart);
+ text.append(((PlainTextPart) part).getText());
+ }
+ assertEquals("Part Text", "Test.", text.toString());
+
+ /* check duplicate empty lines in the text. */
+ text.setLength(0);
+ parts = soneTextParser.parse(null, new StringReader("\nTest.\n\n\nTest."));
+ assertNotNull("Parts", parts);
+ for (Part part : parts) {
+ assertTrue("Part is PlainTextPart", part instanceof PlainTextPart);
+ text.append(((PlainTextPart) part).getText());
+ }
+ assertEquals("Part Text", "Test.\n\nTest.", text.toString());
+ }
+
+}