X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftext%2FSoneTextParserTest.java;h=59987c384577488f03156d8d3e3ebd0c5c6321bb;hb=a4a6ac17f4d3a8f353c01dd74f28dc975ea5c748;hp=bfe218e39ad6a6df7898f50b545c5402b9ca1095;hpb=e9dd4ebd28b5a429573f54565ea8215de5266a87;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 bfe218e..59987c3 100644 --- a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java +++ b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java @@ -49,17 +49,14 @@ public class SoneTextParserTest { public void testPlainText() throws IOException { /* check basic operation. */ Iterable parts = soneTextParser.parse("Test.", null); - assertThat("Parts", parts, notNullValue()); assertThat("Part Text", convertText(parts, PlainTextPart.class), is("Test.")); /* check empty lines at start and end. */ parts = soneTextParser.parse("\nTest.\n\n", null); - assertThat("Parts", parts, notNullValue()); assertThat("Part Text", convertText(parts, PlainTextPart.class), is("Test.")); /* check duplicate empty lines in the text. */ parts = soneTextParser.parse("\nTest.\n\n\nTest.", null); - assertThat("Parts", parts, notNullValue()); assertThat("Part Text", convertText(parts, PlainTextPart.class), is("Test.\n\nTest.")); } @@ -116,7 +113,7 @@ public class SoneTextParserTest { @Test public void nameOfFreenetLinkDoesNotContainUrlParameters() { - Iterable parts = soneTextParser.parse("KSK@gpl.txt?max-size=12345", null); + Iterable parts = soneTextParser.parse("KSK@gpl.txt?max-size=12345", null); assertThat("Part Text", convertText(parts), is("[KSK@gpl.txt?max-size=12345|gpl.txt|gpl.txt]")); } @@ -152,7 +149,7 @@ public class SoneTextParserTest { @Test public void httpLinksHaveTheirLastSlashRemoved() { - Iterable parts = soneTextParser.parse("http://test.test/test/", null); + Iterable parts = soneTextParser.parse("http://test.test/test/", null); assertThat("Part Text", convertText(parts), is("[http://test.test/test/|test.test/…|test.test/…]")); } @@ -237,17 +234,14 @@ public class SoneTextParserTest { public void testKSKLinks() throws IOException { /* check basic links. */ Iterable parts = soneTextParser.parse("KSK@gpl.txt", null); - assertThat("Parts", parts, notNullValue()); assertThat("Part Text", convertText(parts, FreenetLinkPart.class), is("[KSK@gpl.txt|gpl.txt|gpl.txt]")); /* check embedded links. */ parts = soneTextParser.parse("Link is KSK@gpl.txt\u200b.", null); - assertThat("Parts", parts, notNullValue()); assertThat("Part Text", convertText(parts, PlainTextPart.class, FreenetLinkPart.class), is("Link is [KSK@gpl.txt|gpl.txt|gpl.txt]\u200b.")); /* check embedded links and line breaks. */ parts = soneTextParser.parse("Link is KSK@gpl.txt\nKSK@test.dat\n", null); - assertThat("Parts", parts, notNullValue()); assertThat("Part Text", convertText(parts, PlainTextPart.class, FreenetLinkPart.class), is("Link is [KSK@gpl.txt|gpl.txt|gpl.txt]\n[KSK@test.dat|test.dat|test.dat]")); } @@ -258,7 +252,6 @@ public class SoneTextParserTest { /* check basic links. */ Iterable parts = soneTextParser.parse("Some text.\n\nLink to sone://DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU and stuff.", null); - assertThat("Parts", parts, notNullValue()); assertThat("Part Text", convertText(parts, PlainTextPart.class, SonePart.class), is("Some text.\n\nLink to [Sone|DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU] and stuff.")); } @@ -269,47 +262,57 @@ public class SoneTextParserTest { /* check empty http links. */ Iterable parts = soneTextParser.parse("Some text. Empty link: http:// – nice!", null); - assertThat("Parts", parts, notNullValue()); assertThat("Part Text", convertText(parts, PlainTextPart.class), is("Some text. Empty link: http:// – nice!")); } @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", convertText(parts, PlainTextPart.class, LinkPart.class), is("Some text (and a link: [http://example.sone/abc|example.sone/abc|example.sone/abc]) – nice!")); } @Test + public void uskLinkEndsAtFirstNonNumericNonSlashCharacterAfterVersionNumber() { + Iterable parts = soneTextParser.parse("Some link (USK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test/0). Nice", null); + assertThat("Part Text", convertText(parts), is("Some link ([USK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test/0|test|test]). Nice")); + } + + @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", convertText(parts, PlainTextPart.class, LinkPart.class), is("Some text (and a link: [http://example.sone/abc_(def)|example.sone/abc_(def)|example.sone/abc_(def)]) – nice!")); } @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", convertText(parts, PlainTextPart.class, LinkPart.class), is("Some text and a link: [http://example.sone/abc|example.sone/abc|example.sone/abc]. Nice!")); } @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", convertText(parts, PlainTextPart.class, LinkPart.class), is("Some text and a link: [http://example.sone/abc|example.sone/abc|example.sone/abc]... Nice!")); } @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", convertText(parts, PlainTextPart.class, LinkPart.class), is("Some text and a link: [http://example.sone/abc|example.sone/abc|example.sone/abc], nice!")); } + @Test + public void exclamationMarksAreIgnoredAtEndOfLinkBeforeWhitespace() { + Iterable parts = soneTextParser.parse("A link: http://example.sone/abc!", null); + assertThat("Part Text", convertText(parts, PlainTextPart.class, LinkPart.class), is("A link: [http://example.sone/abc|example.sone/abc|example.sone/abc]!")); + } + + @Test + public void questionMarksAreIgnoredAtEndOfLinkBeforeWhitespace() { + Iterable parts = soneTextParser.parse("A link: http://example.sone/abc?", null); + assertThat("Part Text", convertText(parts, PlainTextPart.class, LinkPart.class), is("A link: [http://example.sone/abc|example.sone/abc|example.sone/abc]?")); + } + /** * Converts all given {@link Part}s into a string, validating that the * part’s classes match only the expected classes.