X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftext%2FSoneTextParserTest.java;h=97ed6b21a36f76978e3f2c83affb831bca85a222;hb=b7055ae17bee36504a02003b180788adae86b26a;hp=56e31abc331f9bbc4de18656e0155887508bd235;hpb=52513d6490a4c84c5a60f4232614f8222b9bdd57;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 index 56e31ab..97ed6b2 100644 --- a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java +++ b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java @@ -40,24 +40,13 @@ import org.junit.Test; */ public class SoneTextParserTest { - // - // ACTIONS - // + private final SoneTextParser soneTextParser = new SoneTextParser(null, null); - /** - * Tests basic plain-text operation of the parser. - * - * @throws IOException - * if an I/O error occurs - */ @SuppressWarnings("static-method") @Test public void testPlainText() throws IOException { - SoneTextParser soneTextParser = new SoneTextParser(null, null); - Iterable parts; - /* check basic operation. */ - parts = soneTextParser.parse("Test.", null); + Iterable parts = soneTextParser.parse("Test.", null); assertThat("Parts", parts, notNullValue()); assertThat("Part Text", "Test.", is(convertText(parts, PlainTextPart.class))); @@ -72,20 +61,11 @@ public class SoneTextParserTest { assertThat("Part Text", "Test.\n\nTest.", is(convertText(parts, PlainTextPart.class))); } - /** - * Tests parsing of KSK links. - * - * @throws IOException - * if an I/O error occurs - */ @SuppressWarnings("static-method") @Test public void testKSKLinks() throws IOException { - SoneTextParser soneTextParser = new SoneTextParser(null, null); - Iterable parts; - /* check basic links. */ - parts = soneTextParser.parse("KSK@gpl.txt", null); + Iterable parts = soneTextParser.parse("KSK@gpl.txt", null); assertThat("Parts", parts, notNullValue()); assertThat("Part Text", "[KSK@gpl.txt|gpl.txt|gpl.txt]", is(convertText(parts, FreenetLinkPart.class))); @@ -100,46 +80,64 @@ public class SoneTextParserTest { assertThat("Part Text", "Link is [KSK@gpl.txt|gpl.txt|gpl.txt]\n[KSK@test.dat|test.dat|test.dat]", is(convertText(parts, PlainTextPart.class, FreenetLinkPart.class))); } - /** - * Test case for a bug that was discovered in 0.6.7. - * - * @throws IOException - * if an I/O error occurs - */ @SuppressWarnings({ "synthetic-access", "static-method" }) @Test public void testEmptyLinesAndSoneLinks() throws IOException { SoneTextParser soneTextParser = new SoneTextParser(new TestSoneProvider(), null); - Iterable parts; /* check basic links. */ - parts = soneTextParser.parse("Some text.\n\nLink to sone://DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU and stuff.", null); + Iterable parts = soneTextParser.parse("Some text.\n\nLink to sone://DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU and stuff.", null); assertThat("Parts", parts, notNullValue()); assertThat("Part Text", "Some text.\n\nLink to [Sone|DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU] and stuff.", is(convertText(parts, PlainTextPart.class, SonePart.class))); } - /** - * Test for a bug discovered in Sone 0.8.4 where a plain “http://” would be - * parsed into a link. - * - * @throws IOException - * if an I/O error occurs - */ @SuppressWarnings({ "synthetic-access", "static-method" }) @Test public void testEmpyHttpLinks() throws IOException { SoneTextParser soneTextParser = new SoneTextParser(new TestSoneProvider(), null); - Iterable parts; /* check empty http links. */ - parts = soneTextParser.parse("Some text. Empty link: http:// – nice!", null); + Iterable parts = soneTextParser.parse("Some text. Empty link: http:// – nice!", null); assertThat("Parts", parts, notNullValue()); assertThat("Part Text", "Some text. Empty link: http:// – nice!", is(convertText(parts, PlainTextPart.class))); } - // - // PRIVATE METHODS - // + @Test + public void httpLinkWithoutParensEndsAtNextClosingParen() { + Iterable parts = soneTextParser.parse("Some text (and a link: http://example.sone/abc) – nice!", null); + assertThat("Parts", parts, notNullValue()); + assertThat("Part Text", "Some text (and a link: [http://example.sone/abc|example.sone/abc|example.sone/abc]) – nice!", is(convertText(parts, PlainTextPart.class, LinkPart.class))); + } + + @Test + public void httpLinkWithOpenedAndClosedParensEndsAtNextClosingParen() { + Iterable parts = soneTextParser.parse("Some text (and a link: http://example.sone/abc_(def)) – nice!", null); + assertThat("Parts", parts, notNullValue()); + assertThat("Part Text", "Some text (and a link: [http://example.sone/abc_(def)|example.sone/abc_(def)|example.sone/abc_(def)]) – nice!", is(convertText(parts, PlainTextPart.class, LinkPart.class))); + } + + @Test + public void punctuationIsIgnoredAtEndOfLinkBeforeWhitespace() { + SoneTextParser soneTextParser = new SoneTextParser(null, null); + Iterable parts = soneTextParser.parse("Some text and a link: http://example.sone/abc. Nice!", null); + assertThat("Parts", parts, notNullValue()); + assertThat("Part Text", "Some text and a link: [http://example.sone/abc|example.sone/abc|example.sone/abc]. Nice!", is(convertText(parts, PlainTextPart.class, LinkPart.class))); + } + + @Test + public void multiplePunctuationCharactersAreIgnoredAtEndOfLinkBeforeWhitespace() { + Iterable parts = soneTextParser.parse("Some text and a link: http://example.sone/abc... Nice!", null); + assertThat("Parts", parts, notNullValue()); + assertThat("Part Text", "Some text and a link: [http://example.sone/abc|example.sone/abc|example.sone/abc]... Nice!", is(convertText(parts, PlainTextPart.class, LinkPart.class))); + } + + @Test + public void commasAreIgnoredAtEndOfLinkBeforeWhitespace() { + SoneTextParser soneTextParser = new SoneTextParser(null, null); + Iterable parts = soneTextParser.parse("Some text and a link: http://example.sone/abc, nice!", null); + assertThat("Parts", parts, notNullValue()); + assertThat("Part Text", "Some text and a link: [http://example.sone/abc|example.sone/abc|example.sone/abc], nice!", is(convertText(parts, PlainTextPart.class, LinkPart.class))); + } /** * Converts all given {@link Part}s into a string, validating that the