diff options
author | Ignat Beresnev <ignat.beresnev@jetbrains.com> | 2022-04-19 13:11:38 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-19 13:11:38 +0300 |
commit | 3d573827230e7a750c002cf416cf9231161dd9b3 (patch) | |
tree | 9da32e97873536db521974a004929cbb0c8a29df /plugins/base | |
parent | 2a0ed52ff33c2ea38cf2bbd439a8b5af9f692d04 (diff) | |
download | dokka-3d573827230e7a750c002cf416cf9231161dd9b3.tar.gz dokka-3d573827230e7a750c002cf416cf9231161dd9b3.tar.bz2 dokka-3d573827230e7a750c002cf416cf9231161dd9b3.zip |
Update Jsoup to 1.14.3 (#2448)
* Update Jsoup to 1.14.3
* Fix Jsoup API breaking changes after the update
* Fix new Qodana inspections
* Replace IllegalStateException with more appropriate NoSuchElementException
Diffstat (limited to 'plugins/base')
7 files changed, 42 insertions, 19 deletions
diff --git a/plugins/base/base-test-utils/api/base-test-utils.api b/plugins/base/base-test-utils/api/base-test-utils.api index a0b535f2..6a31e468 100644 --- a/plugins/base/base-test-utils/api/base-test-utils.api +++ b/plugins/base/base-test-utils/api/base-test-utils.api @@ -95,6 +95,7 @@ public final class signatures/Parameters : utils/Tag { public final class signatures/SignatureUtilsKt { public static final fun firstSignature (Lorg/jsoup/nodes/Element;)Lorg/jsoup/nodes/Element; + public static final fun lastSignature (Lorg/jsoup/nodes/Element;)Lorg/jsoup/nodes/Element; public static final fun renderedContent (Lutils/TestOutputWriter;Ljava/lang/String;)Lorg/jsoup/nodes/Element; public static synthetic fun renderedContent$default (Lutils/TestOutputWriter;Ljava/lang/String;ILjava/lang/Object;)Lorg/jsoup/nodes/Element; public static final fun signature (Lorg/jsoup/nodes/Element;)Lorg/jsoup/select/Elements; diff --git a/plugins/base/base-test-utils/src/main/kotlin/renderers/SignatureUtils.kt b/plugins/base/base-test-utils/src/main/kotlin/renderers/SignatureUtils.kt index 1d725398..3397b2b4 100644 --- a/plugins/base/base-test-utils/src/main/kotlin/renderers/SignatureUtils.kt +++ b/plugins/base/base-test-utils/src/main/kotlin/renderers/SignatureUtils.kt @@ -11,7 +11,8 @@ fun TestOutputWriter.renderedContent(path: String = "root/example.html"): Elemen .single() fun Element.signature(): Elements = select("div.symbol.monospace") -fun Element.firstSignature(): Element = signature().first() +fun Element.firstSignature(): Element = signature().first() ?: throw NoSuchElementException("No signature found") +fun Element.lastSignature(): Element = signature().last() ?: throw NoSuchElementException("No signature found") class Parameters(vararg matchers: Any) : Tag("span", *matchers, expectedClasses = listOf("parameters")) class Parameter(vararg matchers: Any) : Tag("span", *matchers, expectedClasses = listOf("parameter"))
\ No newline at end of file diff --git a/plugins/base/src/test/kotlin/linking/EnumValuesLinkingTest.kt b/plugins/base/src/test/kotlin/linking/EnumValuesLinkingTest.kt index 29e705fd..f95d9860 100644 --- a/plugins/base/src/test/kotlin/linking/EnumValuesLinkingTest.kt +++ b/plugins/base/src/test/kotlin/linking/EnumValuesLinkingTest.kt @@ -13,7 +13,7 @@ import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test import java.nio.file.Paths import utils.TestOutputWriterPlugin -import java.lang.AssertionError +import kotlin.AssertionError class EnumValuesLinkingTest : BaseAbstractTest() { @@ -106,12 +106,32 @@ class EnumValuesLinkingTest : BaseAbstractTest() { assertNotNull(content.dfs { it is ContentDRILink && it.address.classNames == "JavaEnum.ON_DECEIT" }) } - // single method will throw an exception if there is no single element (0 or 2+) - Jsoup.parse(writerPlugin.writer.contents["root/linking.source/-java-linker/index.html"]).select("a[href=\"../-kotlin-enum/-o-n_-c-r-e-a-t-e/index.html\"]").single() - Jsoup.parse(writerPlugin.writer.contents["root/linking.source/-java-linker/index.html"]).select("a[href=\"../-java-enum/-o-n_-d-e-c-e-i-t/index.html\"]").single() - Jsoup.parse(writerPlugin.writer.contents["root/linking.source/-kotlin-linker/index.html"]).select("a[href=\"../-kotlin-enum/-o-n_-c-r-e-a-t-e/index.html\"]").single() - Jsoup.parse(writerPlugin.writer.contents["root/linking.source/-kotlin-linker/index.html"]).select("a[href=\"../-java-enum/-o-n_-d-e-c-e-i-t/index.html\"]").single() + Jsoup + .parse(writerPlugin.writer.contents.getValue("root/linking.source/-java-linker/index.html")) + .select("a[href=\"../-kotlin-enum/-o-n_-c-r-e-a-t-e/index.html\"]") + .assertOnlyOneElement() + + Jsoup + .parse(writerPlugin.writer.contents.getValue("root/linking.source/-java-linker/index.html")) + .select("a[href=\"../-java-enum/-o-n_-d-e-c-e-i-t/index.html\"]") + .assertOnlyOneElement() + + Jsoup + .parse(writerPlugin.writer.contents.getValue("root/linking.source/-kotlin-linker/index.html")) + .select("a[href=\"../-kotlin-enum/-o-n_-c-r-e-a-t-e/index.html\"]") + .assertOnlyOneElement() + + Jsoup + .parse(writerPlugin.writer.contents.getValue("root/linking.source/-kotlin-linker/index.html")) + .select("a[href=\"../-java-enum/-o-n_-d-e-c-e-i-t/index.html\"]") + .assertOnlyOneElement() } } } + + private fun <T> List<T>.assertOnlyOneElement() { + if (isEmpty() || size > 1) { + throw AssertionError("Single element expected in list: $this") + } + } } diff --git a/plugins/base/src/test/kotlin/renderers/html/TextStylesTest.kt b/plugins/base/src/test/kotlin/renderers/html/TextStylesTest.kt index d65a4f6e..fd2f7860 100644 --- a/plugins/base/src/test/kotlin/renderers/html/TextStylesTest.kt +++ b/plugins/base/src/test/kotlin/renderers/html/TextStylesTest.kt @@ -45,7 +45,8 @@ class TextStylesTest : HtmlRenderingOnlyTestBase() { } HtmlRenderer(context).render(page) renderedContent.match(Span("keyword")) - assertEquals(renderedContent.children().last().attr("class"), "token keyword") + val lastChild = renderedContent.children().last() ?: throw IllegalStateException("No element found") + assertEquals(lastChild.attr("class"), "token keyword") } @Test diff --git a/plugins/base/src/test/kotlin/resourceLinks/ResourceLinksTest.kt b/plugins/base/src/test/kotlin/resourceLinks/ResourceLinksTest.kt index fb9ec10e..8a8586ee 100644 --- a/plugins/base/src/test/kotlin/resourceLinks/ResourceLinksTest.kt +++ b/plugins/base/src/test/kotlin/resourceLinks/ResourceLinksTest.kt @@ -65,7 +65,7 @@ class ResourceLinksTest : BaseAbstractTest() { ) { renderingStage = { root, context -> Jsoup - .parse(writerPlugin.writer.contents["root/example.html"]) + .parse(writerPlugin.writer.contents.getValue("root/example.html")) .head() .select("link, script") .let { @@ -125,7 +125,7 @@ class ResourceLinksTest : BaseAbstractTest() { } if (isMultiModule) { Jsoup - .parse(writerPlugin.writer.contents["example.html"]) + .parse(writerPlugin.writer.contents.getValue("example.html")) .head() .select("link, script") .let { @@ -135,7 +135,7 @@ class ResourceLinksTest : BaseAbstractTest() { } } else { Jsoup - .parse(writerPlugin.writer.contents["root/example.html"]) + .parse(writerPlugin.writer.contents.getValue("root/example.html")) .head() .select("link, script") .let { @@ -184,7 +184,7 @@ class ResourceLinksTest : BaseAbstractTest() { assertNull(writerPlugin.writer.contents["scripts/relativePath.js"]) assertNull(writerPlugin.writer.contents["styles/relativePath.js"]) Jsoup - .parse(writerPlugin.writer.contents["root/example.html"]) + .parse(writerPlugin.writer.contents.getValue("root/example.html")) .head() .select("link, script") .let { diff --git a/plugins/base/src/test/kotlin/signatures/FunctionalTypeConstructorsSignatureTest.kt b/plugins/base/src/test/kotlin/signatures/FunctionalTypeConstructorsSignatureTest.kt index e631117f..cd55a001 100644 --- a/plugins/base/src/test/kotlin/signatures/FunctionalTypeConstructorsSignatureTest.kt +++ b/plugins/base/src/test/kotlin/signatures/FunctionalTypeConstructorsSignatureTest.kt @@ -235,7 +235,7 @@ class FunctionalTypeConstructorsSignatureTest : BaseAbstractTest() { pluginOverrides = listOf(writerPlugin) ) { renderingStage = { _, _ -> - writerPlugin.writer.renderedContent("root/example/-java-class/index.html").signature().last().match( + writerPlugin.writer.renderedContent("root/example/-java-class/index.html").lastSignature().match( "open val ", A("javaFunction"), ": (", A("Integer"), ") -> ", A("String"), Span(), ignoreSpanWithTokenStyle = true ) @@ -261,7 +261,7 @@ class FunctionalTypeConstructorsSignatureTest : BaseAbstractTest() { pluginOverrides = listOf(writerPlugin) ) { renderingStage = { _, _ -> - writerPlugin.writer.renderedContent("root/example/-java-class/index.html").signature().last().match( + writerPlugin.writer.renderedContent("root/example/-java-class/index.html").lastSignature().match( "open val ", A("kotlinFunction"), ": (", A("Integer"), ") -> ", A("String"), Span(), ignoreSpanWithTokenStyle = true ) diff --git a/plugins/base/src/test/kotlin/signatures/SignatureTest.kt b/plugins/base/src/test/kotlin/signatures/SignatureTest.kt index ddf1c892..6f4de32b 100644 --- a/plugins/base/src/test/kotlin/signatures/SignatureTest.kt +++ b/plugins/base/src/test/kotlin/signatures/SignatureTest.kt @@ -547,7 +547,7 @@ class SignatureTest : BaseAbstractTest() { pluginOverrides = listOf(writerPlugin) ) { renderingStage = { _, _ -> - writerPlugin.writer.renderedContent("root/example.html").signature().first().match( + writerPlugin.writer.renderedContent("root/example.html").firstSignature().match( "typealias ", A("PlainTypealias"), " = ", A("Int"), Span(), ignoreSpanWithTokenStyle = true ) @@ -577,7 +577,7 @@ class SignatureTest : BaseAbstractTest() { pluginOverrides = listOf(writerPlugin) ) { renderingStage = { _, _ -> - writerPlugin.writer.renderedContent("root/example/index.html").signature().first().match( + writerPlugin.writer.renderedContent("root/example/index.html").firstSignature().match( Div( Div( "@", A("SomeAnnotation") @@ -607,7 +607,7 @@ class SignatureTest : BaseAbstractTest() { pluginOverrides = listOf(writerPlugin) ) { renderingStage = { _, _ -> - writerPlugin.writer.renderedContent("root/example.html").signature().first().match( + writerPlugin.writer.renderedContent("root/example.html").firstSignature().match( "typealias ", A("PlainTypealias"), " = ", A("Comparable"), "<", A("Int"), ">", Span(), ignoreSpanWithTokenStyle = true @@ -634,7 +634,7 @@ class SignatureTest : BaseAbstractTest() { pluginOverrides = listOf(writerPlugin) ) { renderingStage = { _, _ -> - writerPlugin.writer.renderedContent("root/example.html").signature().first().match( + writerPlugin.writer.renderedContent("root/example.html").firstSignature().match( "typealias ", A("GenericTypealias"), "<", A("T"), "> = ", A("Comparable"), "<", A("T"), ">", Span(), ignoreSpanWithTokenStyle = true @@ -663,7 +663,7 @@ class SignatureTest : BaseAbstractTest() { pluginOverrides = listOf(writerPlugin) ) { renderingStage = { _, _ -> - writerPlugin.writer.renderedContent("root/kotlinAsJavaPlugin/-a-b-c/some-fun.html").signature().first() + writerPlugin.writer.renderedContent("root/kotlinAsJavaPlugin/-a-b-c/some-fun.html").firstSignature() .match( "fun ", A("someFun"), "(", Parameters( Parameter("xd: ", A("XD"), "<", A("Int"), ", ", A("String"), ">"), |