From 7d52ecea5a10feaae9fcd86415a3c6f41edc72fa Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 20 May 2017 12:40:09 +0200 Subject: [PATCH] Fix text parser only parsing the last element in a line --- src/main/java/net/pterodactylus/sone/text/SoneTextParser.java | 1 + src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java b/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java index c3c4068..39d26db 100644 --- a/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java +++ b/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java @@ -334,6 +334,7 @@ public class SoneTextParser implements Parser { if (nextLink.isPresent()) { if (nextLink.get().getPosition() < earliestLinkPosition) { earliestNextLink = nextLink.get(); + earliestLinkPosition = earliestNextLink.getPosition(); } } } diff --git a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java index e640c7d..0daf944 100644 --- a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java +++ b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java @@ -93,6 +93,13 @@ public class SoneTextParserTest { } @Test + public void soneAndPostCanBeParsedFromTheSameText() { + SoneTextParser parser = new SoneTextParser(new TestSoneProvider(), new TestPostProvider()); + Iterable parts = parser.parse("Text sone://DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU more text post://f3757817-b45a-497a-803f-9c5aafc10dc6 even more text", null); + assertThat("Part Text", convertText(parts), is("Text [Sone|DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU] more text [Post|f3757817-b45a-497a-803f-9c5aafc10dc6|text] even more text")); + } + + @Test public void postLinkIsRenderedAsPlainTextIfPostIdIsTooShort() { Iterable parts = soneTextParser.parse("post://too-short", null); assertThat("Part Text", convertText(parts), is("post://too-short")); -- 2.7.4