X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftext%2FSoneTextParserTest.java;h=b0fe86f62e0f26ac3e1269360c036880c8589046;hb=0d1361df1885f83bcaccd73368033b2829cf9aef;hp=74099f587846453ca9088dba4b9fe815c9456514;hpb=88c18e062171323f0c986e3e86261cadd9fe3b08;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 74099f5..b0fe86f 100644 --- a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java +++ b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java @@ -116,7 +116,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 +152,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/…]")); } @@ -206,28 +206,28 @@ public class SoneTextParserTest { @Test public void sskLinkWithContextWithoutSoneIsNotTrusted() { - SoneTextParserContext context = new SoneTextParserContext(null, null); + SoneTextParserContext context = new SoneTextParserContext(null); Iterable parts = soneTextParser.parse("SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test", context); assertThat("Part Text", convertText(parts), is("[SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test|test|test]")); } @Test public void sskLinkWithContextWithDifferentSoneIsNotTrusted() { - SoneTextParserContext context = new SoneTextParserContext(null, new IdOnlySone("DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU")); + SoneTextParserContext context = new SoneTextParserContext(new IdOnlySone("DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU")); Iterable parts = soneTextParser.parse("SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test", context); assertThat("Part Text", convertText(parts), is("[SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test|test|test]")); } @Test public void sskLinkWithContextWithCorrectSoneIsTrusted() { - SoneTextParserContext context = new SoneTextParserContext(null, new IdOnlySone("qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU")); + SoneTextParserContext context = new SoneTextParserContext(new IdOnlySone("qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU")); Iterable parts = soneTextParser.parse("SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test", context); assertThat("Part Text", convertText(parts), is("[SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test|trusted|test|test]")); } @Test public void uskLinkWithContextWithCorrectSoneIsTrusted() { - SoneTextParserContext context = new SoneTextParserContext(null, new IdOnlySone("qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU")); + SoneTextParserContext context = new SoneTextParserContext(new IdOnlySone("qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU")); Iterable parts = soneTextParser.parse("USK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test/0", context); assertThat("Part Text", convertText(parts), is("[USK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test/0|trusted|test|test]")); } @@ -281,6 +281,13 @@ public class SoneTextParserTest { } @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("Parts", parts, notNullValue()); + 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()); @@ -289,7 +296,6 @@ public class SoneTextParserTest { @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!")); @@ -304,12 +310,25 @@ public class SoneTextParserTest { @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("Parts", parts, notNullValue()); + 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("Parts", parts, notNullValue()); + 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.