Fix text parser only parsing the last element in a line
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 20 May 2017 10:40:09 +0000 (12:40 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 20 May 2017 10:40:09 +0000 (12:40 +0200)
src/main/java/net/pterodactylus/sone/text/SoneTextParser.java
src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java

index c3c4068..39d26db 100644 (file)
@@ -334,6 +334,7 @@ public class SoneTextParser implements Parser<SoneTextParserContext> {
                        if (nextLink.isPresent()) {
                                if (nextLink.get().getPosition() < earliestLinkPosition) {
                                        earliestNextLink = nextLink.get();
+                                       earliestLinkPosition = earliestNextLink.getPosition();
                                }
                        }
                }
index e640c7d..0daf944 100644 (file)
@@ -93,6 +93,13 @@ public class SoneTextParserTest {
        }
 
        @Test
+       public void soneAndPostCanBeParsedFromTheSameText() {
+               SoneTextParser parser = new SoneTextParser(new TestSoneProvider(), new TestPostProvider());
+               Iterable<Part> 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<Part> parts = soneTextParser.parse("post://too-short", null);
                assertThat("Part Text", convertText(parts), is("post://too-short"));