X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Ftext%2FSoneTextParserTest.kt;h=bd1485834a444b4db80722a533cf2db413850ce8;hb=ccd77b5da1130109a8676ac691e486774fff30cd;hp=9ea97d9edc73a603ea8756cb9fb6820e70450f8c;hpb=62c784c521d116ee569023f2fdd1b2bea8a86b7b;p=Sone.git diff --git a/src/test/kotlin/net/pterodactylus/sone/text/SoneTextParserTest.kt b/src/test/kotlin/net/pterodactylus/sone/text/SoneTextParserTest.kt index 9ea97d9..bd14858 100644 --- a/src/test/kotlin/net/pterodactylus/sone/text/SoneTextParserTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/text/SoneTextParserTest.kt @@ -1,5 +1,5 @@ /* - * Sone - SoneTextParserTest.java - Copyright © 2011–2019 David Roden + * Sone - SoneTextParserTest.kt - Copyright © 2011–2020 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 @@ -18,13 +18,14 @@ package net.pterodactylus.sone.text import com.google.inject.Guice.* +import freenet.keys.FreenetURI import net.pterodactylus.sone.data.* import net.pterodactylus.sone.data.impl.* import net.pterodactylus.sone.database.* import net.pterodactylus.sone.test.* import org.hamcrest.MatcherAssert.* import org.hamcrest.Matchers.* -import org.junit.* +import kotlin.test.* /** * JUnit test case for [SoneTextParser]. @@ -244,6 +245,21 @@ class SoneTextParserTest { } @Test + fun `usk links with backlinks is parsed correctly`() { + val context = SoneTextParserContext(IdOnlySone("qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU")) + val parts = soneTextParser.parse("USK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test/0/../../../USK@nwa8lHa271k2QvJ8aa0Ov7IHAV-DFOCFgmDt3X6BpCI,DuQSUZiI~agF8c-6tjsFFGuZ8eICrzWCILB60nT8KKo,AQACAAE/sone/78/", context) + assertThat("Part Text", convertText(parts), equalTo("[USK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test/0|trusted|USK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test/0|test]")) + } + + @Test + fun `broken usk links is parsed as plain text`() { + val context = SoneTextParserContext(IdOnlySone("qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU")) + val parts = soneTextParser.parse("USK@/someCrazyName.R1/0", context) + FreenetURI("USK@/someCrazyName.R1/0") + assertThat("Part Text", convertText(parts), equalTo("USK@/someCrazyName.R1/0")) + } + + @Test fun `test basic ksk links`() { val parts: Iterable = soneTextParser.parse("KSK@gpl.txt", null) assertThat("Part Text", convertText(parts, FreenetLinkPart::class.java), equalTo("[KSK@gpl.txt|KSK@gpl.txt|gpl.txt]")) @@ -262,6 +278,12 @@ class SoneTextParserTest { } @Test + fun `ksk links with backlinks are parsed correctly`() { + val parts = soneTextParser.parse("KSK@gallery/../Sone/imageBrowser.html?album=30c930ee-97cd-11e9-bd44-f3e595768b77", null) + assertThat("Part Text", convertText(parts, FreenetLinkPart::class.java), equalTo("[KSK@gallery|KSK@gallery|gallery]")) + } + + @Test fun `test empty lines and sone links`() { val soneTextParser = SoneTextParser(TestSoneProvider(), null)