🚸 Format USK links with filenames better
[Sone.git] / src / test / java / net / pterodactylus / sone / text / SoneTextParserTest.java
index ff2a175..69cc658 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Sone - SoneTextParserTest.java - Copyright Â© 2011–2016 David Roden
+ * Sone - SoneTextParserTest.java - Copyright Â© 2011–2019 David Roden
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -17,7 +17,9 @@
 
 package net.pterodactylus.sone.text;
 
+import static com.google.inject.Guice.createInjector;
 import static java.lang.String.format;
+import static net.pterodactylus.sone.test.GuiceKt.supply;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
 import static org.hamcrest.Matchers.isIn;
@@ -36,6 +38,7 @@ import net.pterodactylus.sone.database.PostProvider;
 import net.pterodactylus.sone.database.SoneProvider;
 
 import com.google.common.base.Optional;
+import com.google.inject.Injector;
 import kotlin.jvm.functions.Function1;
 import org.junit.Test;
 
@@ -211,6 +214,17 @@ public class SoneTextParserTest {
        }
 
        @Test
+       public void sskWithoutDocumentNameIsParsedCorrectly() {
+               Iterable<Part> parts = soneTextParser.parse(
+                               "SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8",
+                               null);
+               assertThat("Part Text", convertText(parts),
+                               is("[SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8|"
+                                               + "SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8|"
+                                               + "SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU]"));
+       }
+
+       @Test
        public void sskLinkWithoutContextIsNotTrusted() {
                Iterable<Part> parts = soneTextParser.parse("SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test", null);
                assertThat("Part Text", convertText(parts), is("[SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test|SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test|test]"));
@@ -293,6 +307,12 @@ public class SoneTextParserTest {
        }
 
        @Test
+       public void uskLinkWithFilenameShowsTheFilename() {
+               Iterable<Part> parts = soneTextParser.parse("Some link (USK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test/0/images/image.jpg). Nice", null);
+               assertThat("Part Text", convertText(parts), is("Some link ([USK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test/0/images/image.jpg|USK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test/0/images/image.jpg|image.jpg]). Nice"));
+       }
+
+       @Test
        public void httpLinkWithOpenedAndClosedParensEndsAtNextClosingParen() {
                Iterable<Part> 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)|http://example.sone/abc_(def)|example.sone/abc_(def)]) â€“ nice!"));
@@ -404,6 +424,15 @@ public class SoneTextParserTest {
                return text.toString();
        }
 
+       @Test
+       public void parserCanBeCreatedByGuice() {
+               Injector injector = createInjector(
+                               supply(SoneProvider.class).byMock(),
+                               supply(PostProvider.class).byMock()
+               );
+               assertThat(injector.getInstance(SoneTextParser.class), notNullValue());
+       }
+
        /**
         * Mock Sone provider.
         */