From 4087be42ee49af7f216b40060a429a52409ae34a Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 8 Nov 2016 18:07:32 +0100 Subject: [PATCH] Use link as tooltip on internet links --- .../java/net/pterodactylus/sone/text/LinkPart.java | 2 +- .../net/pterodactylus/sone/text/LinkPartTest.java | 4 ++-- .../sone/text/SoneTextParserTest.java | 28 +++++++++++----------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/text/LinkPart.java b/src/main/java/net/pterodactylus/sone/text/LinkPart.java index 9f889ef..bbcaf8b 100644 --- a/src/main/java/net/pterodactylus/sone/text/LinkPart.java +++ b/src/main/java/net/pterodactylus/sone/text/LinkPart.java @@ -35,7 +35,7 @@ public class LinkPart implements Part { private final String title; public LinkPart(@Nonnull String link, @Nonnull String text) { - this(link, text, text); + this(link, text, link); } public LinkPart(@Nonnull String link, @Nonnull String text, @Nonnull String title) { diff --git a/src/test/java/net/pterodactylus/sone/text/LinkPartTest.java b/src/test/java/net/pterodactylus/sone/text/LinkPartTest.java index 431dfa6..62648a1 100644 --- a/src/test/java/net/pterodactylus/sone/text/LinkPartTest.java +++ b/src/test/java/net/pterodactylus/sone/text/LinkPartTest.java @@ -30,8 +30,8 @@ public class LinkPartTest { } @Test - public void textIsUsedAsTitleIfNoTitleIsGiven() { - assertThat(new LinkPart("link", "text").getTitle(), is("text")); + public void linkIsUsedAsTitleIfNoTitleIsGiven() { + assertThat(new LinkPart("link", "text").getTitle(), is("link")); } @Test(expected = NullPointerException.class) diff --git a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java index 8956ba4..40e8124 100644 --- a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java +++ b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java @@ -145,43 +145,43 @@ public class SoneTextParserTest { @Test public void httpsLinkHasItsPathsShortened() { Iterable parts = soneTextParser.parse("https://test.test/some-long-path/file.txt", null); - assertThat("Part Text", convertText(parts), is("[https://test.test/some-long-path/file.txt|test.test/…/file.txt|test.test/…/file.txt]")); + assertThat("Part Text", convertText(parts), is("[https://test.test/some-long-path/file.txt|https://test.test/some-long-path/file.txt|test.test/…/file.txt]")); } @Test public void httpLinksHaveTheirLastSlashRemoved() { Iterable parts = soneTextParser.parse("http://test.test/test/", null); - assertThat("Part Text", convertText(parts), is("[http://test.test/test/|test.test/…|test.test/…]")); + assertThat("Part Text", convertText(parts), is("[http://test.test/test/|http://test.test/test/|test.test/…]")); } @Test public void wwwPrefixIsRemovedForHostnameWithTwoDotsAndNoPath() { Iterable parts = soneTextParser.parse("http://www.test.test", null); - assertThat("Part Text", convertText(parts), is("[http://www.test.test|test.test|test.test]")); + assertThat("Part Text", convertText(parts), is("[http://www.test.test|http://www.test.test|test.test]")); } @Test public void wwwPrefixIsRemovedForHostnameWithTwoDotsAndAPath() { Iterable parts = soneTextParser.parse("http://www.test.test/test.html", null); - assertThat("Part Text", convertText(parts), is("[http://www.test.test/test.html|test.test/test.html|test.test/test.html]")); + assertThat("Part Text", convertText(parts), is("[http://www.test.test/test.html|http://www.test.test/test.html|test.test/test.html]")); } @Test public void hostnameIsKeptIntactIfNotBeginningWithWww() { Iterable parts = soneTextParser.parse("http://test.test.test/test.html", null); - assertThat("Part Text", convertText(parts), is("[http://test.test.test/test.html|test.test.test/test.html|test.test.test/test.html]")); + assertThat("Part Text", convertText(parts), is("[http://test.test.test/test.html|http://test.test.test/test.html|test.test.test/test.html]")); } @Test public void hostnameWithOneDotButNoSlashIsKeptIntact() { Iterable parts = soneTextParser.parse("http://test.test", null); - assertThat("Part Text", convertText(parts), is("[http://test.test|test.test|test.test]")); + assertThat("Part Text", convertText(parts), is("[http://test.test|http://test.test|test.test]")); } @Test public void urlParametersAreRemovedForHttpLinks() { Iterable parts = soneTextParser.parse("http://test.test?foo=bar", null); - assertThat("Part Text", convertText(parts), is("[http://test.test?foo=bar|test.test|test.test]")); + assertThat("Part Text", convertText(parts), is("[http://test.test?foo=bar|http://test.test?foo=bar|test.test]")); } @Test @@ -269,7 +269,7 @@ public class SoneTextParserTest { @Test public void httpLinkWithoutParensEndsAtNextClosingParen() { Iterable parts = soneTextParser.parse("Some text (and a link: http://example.sone/abc) – nice!", null); - 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!")); + assertThat("Part Text", convertText(parts, PlainTextPart.class, LinkPart.class), is("Some text (and a link: [http://example.sone/abc|http://example.sone/abc|example.sone/abc]) – nice!")); } @Test @@ -281,37 +281,37 @@ public class SoneTextParserTest { @Test public void httpLinkWithOpenedAndClosedParensEndsAtNextClosingParen() { Iterable parts = soneTextParser.parse("Some text (and a link: http://example.sone/abc_(def)) – nice!", null); - 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!")); + assertThat("Part Text", convertText(parts, PlainTextPart.class, LinkPart.class), is("Some text (and a link: [http://example.sone/abc_(def)|http://example.sone/abc_(def)|example.sone/abc_(def)]) – nice!")); } @Test public void punctuationIsIgnoredAtEndOfLinkBeforeWhitespace() { Iterable parts = soneTextParser.parse("Some text and a link: http://example.sone/abc. Nice!", null); - 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!")); + assertThat("Part Text", convertText(parts, PlainTextPart.class, LinkPart.class), is("Some text and a link: [http://example.sone/abc|http://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("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!")); + assertThat("Part Text", convertText(parts, PlainTextPart.class, LinkPart.class), is("Some text and a link: [http://example.sone/abc|http://example.sone/abc|example.sone/abc]... Nice!")); } @Test public void commasAreIgnoredAtEndOfLinkBeforeWhitespace() { Iterable parts = soneTextParser.parse("Some text and a link: http://example.sone/abc, nice!", null); - 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!")); + assertThat("Part Text", convertText(parts, PlainTextPart.class, LinkPart.class), is("Some text and a link: [http://example.sone/abc|http://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]!")); + assertThat("Part Text", convertText(parts, PlainTextPart.class, LinkPart.class), is("A link: [http://example.sone/abc|http://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]?")); + assertThat("Part Text", convertText(parts, PlainTextPart.class, LinkPart.class), is("A link: [http://example.sone/abc|http://example.sone/abc|example.sone/abc]?")); } @Test -- 2.7.4