X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftext%2FSoneTextParserTest.java;h=62f8b481cacebc88aad998d61a8c6be73fbee3cc;hb=2d37242d19f2e726cd402b99f935a0eba282f630;hp=b67fea838397c3352905071b6f038dae1279a188;hpb=9c0408ace4264416f7182a128e80ef1b386297be;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 b67fea8..62f8b48 100644 --- a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java +++ b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java @@ -169,7 +169,7 @@ public class SoneTextParserTest { } @Test - public void parseTrustedSoneLinks() throws IOException { + public void parseTrustedSoneSSKLinks() throws IOException { Sone trustedSone = mocks.mockSone("DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU").create(); assertThat(parse(new SoneTextParserContext(trustedSone), "Get SSK@DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU/file.txt\u200b!"), matches( is(new PlainTextPart("Get ")), @@ -179,6 +179,16 @@ public class SoneTextParserTest { } @Test + public void parseTrustedSoneUSKLinks() throws IOException { + Sone trustedSone = mocks.mockSone("DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU").create(); + assertThat(parse(new SoneTextParserContext(trustedSone), "Get USK@DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU,DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU/site/0/file.txt\u200b!"), matches( + is(new PlainTextPart("Get ")), + is(new FreenetLinkPart("USK@DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU,DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU/site/0/file.txt", "file.txt", true)), + is(new PlainTextPart("\u200b!")) + )); + } + + @Test public void parseHttpLink() throws IOException { assertThat(parse("http://w3.org/foo.html"), matches( is(new LinkPart("http://w3.org/foo.html", "w3.org/foo.html", "w3.org/foo.html")) @@ -245,9 +255,17 @@ public class SoneTextParserTest { } @Test - public void linkToNonExistingSoneCreatesLinkToEmptyShell() throws IOException { + public void freenetPrefixBeforeKeysInMiddleOfTextIsCutOff() throws IOException { + assertThat(parse("Link is freenet:KSK@gpl.txt"), matches( + is(new PlainTextPart("Link is ")), + is(new FreenetLinkPart("KSK@gpl.txt", "gpl.txt", false)) + )); + } + + @Test + public void linkToNonExistingSoneCreatesPlainTextLink() throws IOException { assertThat(parse("sone://1234567890123456789012345678901234567890123"), matches( - is(new SonePart(new DefaultSone(mocks.database, "1234567890123456789012345678901234567890123", false, null))) + is(new PlainTextPart("sone://1234567890123456789012345678901234567890123")) )); } @@ -300,4 +318,13 @@ public class SoneTextParserTest { )); } + @Test + public void multipleLinksInOneLine() throws IOException { + assertThat(parse("KSK@gpl.txt and http://server.com/"), matches( + is(new FreenetLinkPart("KSK@gpl.txt", "gpl.txt", false)), + is(new PlainTextPart(" and ")), + is(new FreenetLinkPart("http://server.com/", "server.com", false)) + )); + } + }