+ @Test
+ public void httpLinksHaveTheirLastSlashRemoved() {
+ Iterable<Part> parts = soneTextParser.parse("http://test.test/test/", null);
+ assertThat("Part Text", convertText(parts), is("[http://test.test/test/|test.test/…|test.test/…]"));
+ }
+
+ @Test
+ public void wwwPrefixIsRemovedForHostnameWithTwoDotsAndNoPath() {
+ Iterable<Part> parts = soneTextParser.parse("http://www.test.test", null);
+ assertThat("Part Text", convertText(parts), is("[http://www.test.test|test.test|test.test]"));
+ }
+
+ @Test
+ public void wwwPrefixIsRemovedForHostnameWithTwoDotsAndAPath() {
+ Iterable<Part> 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]"));
+ }
+
+ @Test
+ public void hostnameIsKeptIntactIfNotBeginningWithWww() {
+ Iterable<Part> 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]"));
+ }
+
+ @Test
+ public void hostnameWithOneDotButNoSlashIsKeptIntact() {
+ Iterable<Part> parts = soneTextParser.parse("http://test.test", null);
+ assertThat("Part Text", convertText(parts), is("[http://test.test|test.test|test.test]"));
+ }
+
+ @Test
+ public void urlParametersAreRemovedForHttpLinks() {
+ Iterable<Part> parts = soneTextParser.parse("http://test.test?foo=bar", null);
+ assertThat("Part Text", convertText(parts), is("[http://test.test?foo=bar|test.test|test.test]"));
+ }
+
+ @Test
+ public void emptyStringIsParsedCorrectly() {
+ Iterable<Part> parts = soneTextParser.parse("", null);
+ assertThat("Part Text", convertText(parts), is(""));
+ }
+
+ @Test
+ public void linksAreParsedInCorrectOrder() {
+ Iterable<Part> parts = soneTextParser.parse("KSK@ CHK@", null);
+ assertThat("Part Text", convertText(parts), is("KSK@ CHK@"));
+ }
+
+ @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|test|test]"));
+ }
+
+ @Test
+ public void sskLinkWithContextWithoutSoneIsNotTrusted() {
+ SoneTextParserContext context = new SoneTextParserContext(null);
+ Iterable<Part> parts = soneTextParser.parse("SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test", context);
+ assertThat("Part Text", convertText(parts), is("[SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test|test|test]"));
+ }
+
+ @Test
+ public void sskLinkWithContextWithDifferentSoneIsNotTrusted() {
+ SoneTextParserContext context = new SoneTextParserContext(new IdOnlySone("DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU"));
+ Iterable<Part> parts = soneTextParser.parse("SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test", context);
+ assertThat("Part Text", convertText(parts), is("[SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test|test|test]"));
+ }
+
+ @Test
+ public void sskLinkWithContextWithCorrectSoneIsTrusted() {
+ SoneTextParserContext context = new SoneTextParserContext(new IdOnlySone("qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU"));
+ Iterable<Part> parts = soneTextParser.parse("SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test", context);
+ assertThat("Part Text", convertText(parts), is("[SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test|trusted|test|test]"));
+ }
+
+ @Test
+ public void uskLinkWithContextWithCorrectSoneIsTrusted() {
+ SoneTextParserContext context = new SoneTextParserContext(new IdOnlySone("qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU"));
+ Iterable<Part> parts = soneTextParser.parse("USK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test/0", context);
+ assertThat("Part Text", convertText(parts), is("[USK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test/0|trusted|test|test]"));
+ }
+
+ @SuppressWarnings("static-method")
+ @Test
+ public void testKSKLinks() throws IOException {