From e9fd8b7bc00491b50e4822acc82e5615ab0bde3b Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Fri, 5 Jun 2020 09:07:20 +0200 Subject: Implement `reportUndocumented` option to report undocumented code --- .../ReportUndocumentedTransformerTest.kt | 832 +++++++++++++++++++++ 1 file changed, 832 insertions(+) create mode 100644 plugins/base/src/test/kotlin/transformers/ReportUndocumentedTransformerTest.kt (limited to 'plugins/base/src/test/kotlin/transformers') diff --git a/plugins/base/src/test/kotlin/transformers/ReportUndocumentedTransformerTest.kt b/plugins/base/src/test/kotlin/transformers/ReportUndocumentedTransformerTest.kt new file mode 100644 index 00000000..9b6c50da --- /dev/null +++ b/plugins/base/src/test/kotlin/transformers/ReportUndocumentedTransformerTest.kt @@ -0,0 +1,832 @@ +package transformers + +import org.jetbrains.dokka.PackageOptionsImpl +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest +import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test + + +class ReportUndocumentedTransformerTest : AbstractCoreTest() { + @Test + fun `undocumented class gets reported`() { + val configuration = dokkaConfiguration { + passes { + pass { + reportUndocumented = true + sourceRoots = listOf("src/main/kotlin/Test.kt") + } + } + } + + testInline( + """ + |/src/main/kotlin/Test.kt + |package sample + | + |class X + """.trimIndent(), + configuration + ) { + pagesTransformationStage = { + assertNoUndocumentedReport(Regex("init")) + assertSingleUndocumentedReport(Regex("""sample/X/""")) + } + } + } + + @Test + fun `undocumented non-public class does not get reported`() { + val configuration = dokkaConfiguration { + passes { + pass { + reportUndocumented = true + sourceRoots = listOf("src/main/kotlin/Test.kt") + } + } + } + + testInline( + """ + |/src/main/kotlin/Test.kt + |package sample + | + |internal class X + """.trimIndent(), + configuration + ) { + pagesTransformationStage = { + assertNoUndocumentedReport() + } + } + } + + @Test + fun `undocumented function gets reported`() { + val configuration = dokkaConfiguration { + passes { + pass { + reportUndocumented = true + sourceRoots = listOf("src/main/kotlin/Test.kt") + } + } + } + + testInline( + """ + |/src/main/kotlin/Test.kt + |package sample + | + |/** Documented */ + |class X { + | fun x() + |} + """.trimIndent(), + configuration + ) { + pagesTransformationStage = { + assertSingleUndocumentedReport(Regex("X")) + assertSingleUndocumentedReport(Regex("X/x")) + } + } + } + + @Test + fun `undocumented property gets reported`() { + val configuration = dokkaConfiguration { + passes { + pass { + reportUndocumented = true + sourceRoots = listOf("src/main/kotlin/Test.kt") + } + } + } + + testInline( + """ + |/src/main/kotlin/Test.kt + |package sample + | + |/** Documented */ + |class X { + | val x: Int = 0 + |} + """.trimIndent(), + configuration + ) { + pagesTransformationStage = { + assertSingleUndocumentedReport(Regex("X")) + assertSingleUndocumentedReport(Regex("X/x")) + } + } + } + + @Test + fun `undocumented primary constructor does not get reported`() { + val configuration = dokkaConfiguration { + passes { + pass { + reportUndocumented = true + sourceRoots = listOf("src/main/kotlin/Test.kt") + } + } + } + + testInline( + """ + |/src/main/kotlin/Test.kt + |package sample + | + |/** Documented */ + |class X(private val x: Int) { + |} + """.trimIndent(), + configuration + ) { + pagesTransformationStage = { + assertNoUndocumentedReport() + } + } + } + + @Disabled + @Test + fun `undocumented secondary constructor gets reported`() { + val configuration = dokkaConfiguration { + passes { + pass { + reportUndocumented = true + sourceRoots = listOf("src/main/kotlin/Test.kt") + } + } + } + + testInline( + """ + |/src/main/kotlin/Test.kt + |package sample + | + |/** Documented */ + |class X { + | constructor(unit: Unit) : this() + |} + """.trimIndent(), + configuration + ) { + pagesTransformationStage = { + assertSingleUndocumentedReport(Regex("X")) + assertSingleUndocumentedReport(Regex("X.*init.*Unit")) + } + } + } + + @Test + fun `undocumented inherited function does not get reported`() { + val configuration = dokkaConfiguration { + passes { + pass { + reportUndocumented = true + sourceRoots = listOf("src/main/kotlin/Test.kt") + } + } + } + + testInline( + """ + |/src/main/kotlin/Test.kt + |package sample + | + |/** Documented */ + |open class A { + | fun a() = Unit + |} + | + |/** Documented */ + |class B : A() + """.trimIndent(), + configuration + ) { + pagesTransformationStage = { + assertNoUndocumentedReport(Regex("B")) + assertSingleUndocumentedReport(Regex("A.*a")) + } + } + } + + @Test + fun `undocumented inherited property does not get reported`() { + val configuration = dokkaConfiguration { + passes { + pass { + reportUndocumented = true + sourceRoots = listOf("src/main/kotlin/Test.kt") + } + } + } + + testInline( + """ + |/src/main/kotlin/Test.kt + |package sample + | + |/** Documented */ + |open class A { + | val a = Unit + |} + | + |/** Documented */ + |class B : A() + """.trimIndent(), + configuration + ) { + pagesTransformationStage = { + assertNoUndocumentedReport(Regex("B")) + assertSingleUndocumentedReport(Regex("A.*a")) + } + } + } + + @Test + fun `overridden function does not get reported when super is documented`() { + val configuration = dokkaConfiguration { + passes { + pass { + reportUndocumented = true + sourceRoots = listOf("src/main/kotlin/Test.kt") + } + } + } + + testInline( + """ + |/src/main/kotlin/Test.kt + |package sample + |import kotlin.Exception + | + |/** Documented */ + |open class A { + | /** Documented */ + | fun a() = Unit + |} + | + |/** Documented */ + |class B : A() { + | override fun a() = throw Exception() + |} + """.trimIndent(), + configuration + ) { + pagesTransformationStage = { + assertNoUndocumentedReport() + } + } + } + + @Test + fun `overridden property does not get reported when super is documented`() { + val configuration = dokkaConfiguration { + passes { + pass { + reportUndocumented = true + sourceRoots = listOf("src/main/kotlin/Test.kt") + } + } + } + + testInline( + """ + |/src/main/kotlin/Test.kt + |package sample + |import kotlin.Exception + | + |/** Documented */ + |open class A { + | /** Documented */ + | open val a = 0 + |} + | + |/** Documented */ + |class B : A() { + | override val a = 1 + |} + """.trimIndent(), + configuration + ) { + pagesTransformationStage = { + assertNoUndocumentedReport() + } + } + } + + @Test + fun `report disabled by pass configuration`() { + val configuration = dokkaConfiguration { + passes { + pass { + reportUndocumented = false + sourceRoots = listOf("src/main/kotlin/Test.kt") + } + } + } + + testInline( + """ + |/src/main/kotlin/Test.kt + |package sample + | + |class X + """.trimIndent(), + configuration + ) { + pagesTransformationStage = { + assertNoUndocumentedReport() + } + } + } + + @Test + fun `report enabled by package configuration`() { + val configuration = dokkaConfiguration { + passes { + pass { + perPackageOptions += packageOptions( + prefix = "sample", + reportUndocumented = true, + ) + reportUndocumented = false + sourceRoots = listOf("src/main/kotlin/Test.kt") + } + } + } + + testInline( + """ + |/src/main/kotlin/Test.kt + |package sample + | + |class X + """.trimIndent(), + configuration + ) { + pagesTransformationStage = { + assertSingleUndocumentedReport(Regex("X")) + } + } + } + + @Test + fun `report enabled by more specific package configuration`() { + val configuration = dokkaConfiguration { + passes { + pass { + perPackageOptions += packageOptions( + prefix = "sample", + reportUndocumented = false, + ) + perPackageOptions += packageOptions( + prefix = "sample.enabled", + reportUndocumented = true, + ) + reportUndocumented = false + sourceRoots = listOf("src/main/kotlin/") + } + } + } + + testInline( + """ + |/src/main/kotlin/sample/disabled/Disabled.kt + |package sample.disabled + |class Disabled + | + |/src/main/kotlin/sample/enabled/Enabled.kt + |package sample.enabled + |class Enabled + """.trimIndent(), + configuration + ) { + pagesTransformationStage = { + assertSingleUndocumentedReport(Regex("Enabled")) + assertNumberOfUndocumentedReports(1) + } + } + } + + @Test + fun `report disabled by more specific package configuration`() { + val configuration = dokkaConfiguration { + passes { + pass { + perPackageOptions += packageOptions( + prefix = "sample", + reportUndocumented = true, + ) + perPackageOptions += packageOptions( + prefix = "sample.disabled", + reportUndocumented = false, + ) + reportUndocumented = true + sourceRoots = listOf("src/main/kotlin/") + } + } + } + + testInline( + """ + |/src/main/kotlin/sample/disabled/Disabled.kt + |package sample.disabled + |class Disabled + | + |/src/main/kotlin/sample/enabled/Enabled.kt + |package sample.enabled + |class Enabled + """.trimIndent(), + configuration + ) { + pagesTransformationStage = { + assertSingleUndocumentedReport(Regex("Enabled")) + assertNumberOfUndocumentedReports(1) + } + } + } + + @Test + fun `multiplatform undocumented class gets reported`() { + val configuration = dokkaConfiguration { + passes { + pass { + reportUndocumented = true + analysisPlatform = Platform.common.toString() + sourceSetName = "commonMain" + sourceRoots = listOf("src/commonMain/kotlin") + } + + pass { + reportUndocumented = true + analysisPlatform = Platform.jvm.toString() + sourceSetName = "jvmMain" + sourceRoots = listOf("src/jvmMain/kotlin") + dependentSourceRoots = listOf("src/commonMain/kotlin") + dependentSourceSets = listOf("commonMain") + } + } + } + + testInline( + """ + |/src/commonMain/kotlin/sample/Common.kt + |package sample + |expect class X + | + |/src/jvmMain/kotlin/sample/JvmMain.kt + |package sample + |actual class X + """.trimIndent(), + configuration + ) { + pagesTransformationStage = { + assertNumberOfUndocumentedReports(2, Regex("X")) + assertSingleUndocumentedReport(Regex("X.*jvmMain")) + assertSingleUndocumentedReport(Regex("X.*commonMain")) + } + } + } + + @Test + fun `multiplatform undocumented class does not get reported if expect is documented`() { + val configuration = dokkaConfiguration { + passes { + pass { + reportUndocumented = true + analysisPlatform = Platform.common.toString() + sourceSetName = "commonMain" + sourceRoots = listOf("src/commonMain/kotlin") + } + + pass { + reportUndocumented = true + analysisPlatform = Platform.jvm.toString() + sourceSetName = "jvmMain" + sourceRoots = listOf("src/jvmMain/kotlin") + dependentSourceRoots = listOf("src/commonMain/kotlin") + dependentSourceSets = listOf("commonMain") + } + } + } + + testInline( + """ + |/src/commonMain/kotlin/sample/Common.kt + |package sample + |/** Documented */ + |expect class X + | + |/src/jvmMain/kotlin/sample/JvmMain.kt + |package sample + |actual class X + """.trimIndent(), + configuration + ) { + pagesTransformationStage = { + assertNumberOfUndocumentedReports(0) + } + } + } + + @Test + fun `java undocumented class gets reported`() { + val configuration = dokkaConfiguration { + passes { + pass { + reportUndocumented = true + sourceRoots = listOf("src/main/java") + } + } + } + + testInline( + """ + |/src/main/java/sample/Test.java + |package sample + |public class Test { } + """.trimIndent(), + configuration + ) { + pagesTransformationStage = { + assertNoUndocumentedReport(Regex("init")) + assertSingleUndocumentedReport(Regex("""Test""")) + assertNumberOfUndocumentedReports(1) + } + } + } + + @Test + fun `java undocumented non-public class does not get reported`() { + val configuration = dokkaConfiguration { + passes { + pass { + reportUndocumented = true + sourceRoots = listOf("src/main/java") + } + } + } + + testInline( + """ + |/src/main/java/sample/Test.java + |package sample + |class Test { } + """.trimIndent(), + configuration + ) { + pagesTransformationStage = { + assertNoUndocumentedReport() + } + } + } + + @Test + fun `java undocumented constructor does not get reported`() { + val configuration = dokkaConfiguration { + passes { + pass { + reportUndocumented = true + sourceRoots = listOf("src/main/java") + } + } + } + + testInline( + """ + |/src/main/java/sample/Test.java + |package sample + |/** Documented */ + |public class Test { + | public Test() { + | } + |} + """.trimIndent(), + configuration + ) { + pagesTransformationStage = { + assertNoUndocumentedReport() + } + } + } + + @Test + fun `java undocumented method gets reported`() { + val configuration = dokkaConfiguration { + passes { + pass { + reportUndocumented = true + sourceRoots = listOf("src/main/java") + } + } + } + + testInline( + """ + |/src/main/java/sample/X.java + |package sample + |/** Documented */ + |public class X { + | public void x { } + |} + """.trimIndent(), + configuration + ) { + pagesTransformationStage = { + assertSingleUndocumentedReport(Regex("X")) + assertSingleUndocumentedReport(Regex("X.*x")) + assertNumberOfUndocumentedReports(1) + } + } + } + + @Test + fun `java undocumented property gets reported`() { + val configuration = dokkaConfiguration { + passes { + pass { + reportUndocumented = true + sourceRoots = listOf("src/main/java") + } + } + } + + testInline( + """ + |/src/main/java/sample/X.java + |package sample + |/** Documented */ + |public class X { + | public int x = 0; + |} + """.trimIndent(), + configuration + ) { + pagesTransformationStage = { + assertSingleUndocumentedReport(Regex("X")) + assertSingleUndocumentedReport(Regex("X.*x")) + assertNumberOfUndocumentedReports(1) + } + } + } + + @Test + fun `java undocumented inherited method gets reported`() { + val configuration = dokkaConfiguration { + passes { + pass { + reportUndocumented = true + sourceRoots = listOf("src/main/java") + } + } + } + + testInline( + """ + |/src/main/java/sample/Super.java + |package sample + |/** Documented */ + |public class Super { + | public void x() {} + |} + | + |/src/main/java/sample/X.java + |package sample + |/** Documented */ + |public class X extends Super { + | public void x() {} + |} + | + """.trimIndent(), + configuration + ) { + pagesTransformationStage = { + assertSingleUndocumentedReport(Regex("X")) + assertSingleUndocumentedReport(Regex("X.*x")) + assertSingleUndocumentedReport(Regex("Super.*x")) + assertNumberOfUndocumentedReports(2) + } + } + } + + @Test + fun `java documented inherited method does not get reported`() { + val configuration = dokkaConfiguration { + passes { + pass { + reportUndocumented = true + sourceRoots = listOf("src/main/java") + } + } + } + + testInline( + """ + |/src/main/java/sample/Super.java + |package sample + |/** Documented */ + |public class Super { + | /** Documented */ + | public void x() {} + |} + | + |/src/main/java/sample/X.java + |package sample + |/** Documented */ + |public class X extends Super { + | + |} + | + """.trimIndent(), + configuration + ) { + pagesTransformationStage = { + assertNoUndocumentedReport() + } + } + } + + @Test + fun `java overridden function does not get reported when super is documented`() { + val configuration = dokkaConfiguration { + passes { + pass { + reportUndocumented = true + sourceRoots = listOf("src/main/java") + } + } + } + + testInline( + """ + |/src/main/java/sample/Super.java + |package sample + |/** Documented */ + |public class Super { + | /** Documented */ + | public void x() {} + |} + | + |/src/main/java/sample/X.java + |package sample + |/** Documented */ + |public class X extends Super { + | @Override + | public void x() {} + |} + | + """.trimIndent(), + configuration + ) { + pagesTransformationStage = { + assertNoUndocumentedReport() + } + } + } + + private fun assertNumberOfUndocumentedReports(expectedReports: Int, regex: Regex = Regex(".")) { + val reports = logger.warnMessages + .filter { it.startsWith("Undocumented:") } + val matchingReports = reports + .filter { it.contains(regex) } + + assertEquals( + expectedReports, matchingReports.size, + "Expected $expectedReports report of documented code ($regex).\n" + + "Found matching reports: $matchingReports\n" + + "Found reports: $reports" + ) + } + + private fun assertSingleUndocumentedReport(regex: Regex) { + assertNumberOfUndocumentedReports(1, regex) + } + + private fun assertNoUndocumentedReport(regex: Regex) { + assertNumberOfUndocumentedReports(0, regex) + } + + private fun assertNoUndocumentedReport() { + assertNoUndocumentedReport(Regex(".")) + } + + private fun packageOptions( + prefix: String, + reportUndocumented: Boolean?, + includeNonPublic: Boolean = true, + skipDeprecated: Boolean = false, + suppress: Boolean = false + ) = PackageOptionsImpl( + prefix = prefix, + reportUndocumented = reportUndocumented, + includeNonPublic = includeNonPublic, + skipDeprecated = skipDeprecated, + suppress = suppress + ) + +} \ No newline at end of file -- cgit From 4c9952dbfa2d9b304b10d6d3e43e2424e69fdfe8 Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Fri, 12 Jun 2020 12:44:48 +0200 Subject: Fix tests --- .../transformers/ReportUndocumentedTransformerTest.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'plugins/base/src/test/kotlin/transformers') diff --git a/plugins/base/src/test/kotlin/transformers/ReportUndocumentedTransformerTest.kt b/plugins/base/src/test/kotlin/transformers/ReportUndocumentedTransformerTest.kt index 9b6c50da..f05abb1a 100644 --- a/plugins/base/src/test/kotlin/transformers/ReportUndocumentedTransformerTest.kt +++ b/plugins/base/src/test/kotlin/transformers/ReportUndocumentedTransformerTest.kt @@ -458,16 +458,17 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { pass { reportUndocumented = true analysisPlatform = Platform.common.toString() - sourceSetName = "commonMain" + sourceSetID = "commonMain" + displayName = "commonMain" sourceRoots = listOf("src/commonMain/kotlin") } pass { reportUndocumented = true analysisPlatform = Platform.jvm.toString() - sourceSetName = "jvmMain" + sourceSetID = "jvmMain" + displayName = "jvmMain" sourceRoots = listOf("src/jvmMain/kotlin") - dependentSourceRoots = listOf("src/commonMain/kotlin") dependentSourceSets = listOf("commonMain") } } @@ -500,16 +501,17 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { pass { reportUndocumented = true analysisPlatform = Platform.common.toString() - sourceSetName = "commonMain" + sourceSetID = "commonMain" + displayName = "commonMain" sourceRoots = listOf("src/commonMain/kotlin") } pass { reportUndocumented = true analysisPlatform = Platform.jvm.toString() - sourceSetName = "jvmMain" + sourceSetID = "jvmMain" + displayName = "jvmMain" sourceRoots = listOf("src/jvmMain/kotlin") - dependentSourceRoots = listOf("src/commonMain/kotlin") dependentSourceSets = listOf("commonMain") } } -- cgit From bae2c8de63baf0c0b627a17ae179400fbc3c5be9 Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Fri, 12 Jun 2020 14:54:54 +0200 Subject: Fix sourceSet matching inside ReportUndocumentedTransformer --- .../ReportUndocumentedTransformerTest.kt | 60 +++++++++++++++++++++- 1 file changed, 58 insertions(+), 2 deletions(-) (limited to 'plugins/base/src/test/kotlin/transformers') diff --git a/plugins/base/src/test/kotlin/transformers/ReportUndocumentedTransformerTest.kt b/plugins/base/src/test/kotlin/transformers/ReportUndocumentedTransformerTest.kt index f05abb1a..5be60109 100644 --- a/plugins/base/src/test/kotlin/transformers/ReportUndocumentedTransformerTest.kt +++ b/plugins/base/src/test/kotlin/transformers/ReportUndocumentedTransformerTest.kt @@ -536,6 +536,63 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { } } + @Test + fun `multiplatform undocumented function gets reported`() { + val configuration = dokkaConfiguration { + passes { + pass { + reportUndocumented = true + analysisPlatform = Platform.common.toString() + sourceSetID = "commonMain" + displayName = "commonMain" + sourceRoots = listOf("src/commonMain/kotlin") + } + + pass { + reportUndocumented = true + analysisPlatform = Platform.jvm.toString() + sourceSetID = "jvmMain" + displayName = "jvmMain" + sourceRoots = listOf("src/jvmMain/kotlin") + dependentSourceSets = listOf("commonMain") + } + + pass { + reportUndocumented = true + analysisPlatform = Platform.native.toString() + sourceSetID = "macosMain" + displayName = "macosMain" + sourceRoots = listOf("src/macosMain/kotlin") + dependentSourceSets = listOf("commonMain") + } + } + } + + testInline( + """ + |/src/commonMain/kotlin/sample/Common.kt + |package sample + |expect fun x() + | + |/src/macosMain/kotlin/sample/MacosMain.kt + |package sample + |/** Documented */ + |actual fun x() = Unit + | + |/src/jvmMain/kotlin/sample/JvmMain.kt + |package sample + |actual fun x() = Unit + """.trimIndent(), + configuration + ) { + pagesTransformationStage = { + assertNumberOfUndocumentedReports(2) + assertSingleUndocumentedReport(Regex("x.*commonMain")) + assertSingleUndocumentedReport(Regex("x.*jvmMain")) + } + } + } + @Test fun `java undocumented class gets reported`() { val configuration = dokkaConfiguration { @@ -830,5 +887,4 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { skipDeprecated = skipDeprecated, suppress = suppress ) - -} \ No newline at end of file +} -- cgit From f6530934d36fbb977c2b7c4eb3669a8f581dd9f5 Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Mon, 22 Jun 2020 12:15:50 +0200 Subject: Prevent ReportUndocumentedTransformer.kt from reporting "componentN" functions fromd data classes --- .../ReportUndocumentedTransformerTest.kt | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'plugins/base/src/test/kotlin/transformers') diff --git a/plugins/base/src/test/kotlin/transformers/ReportUndocumentedTransformerTest.kt b/plugins/base/src/test/kotlin/transformers/ReportUndocumentedTransformerTest.kt index 5be60109..fac1e060 100644 --- a/plugins/base/src/test/kotlin/transformers/ReportUndocumentedTransformerTest.kt +++ b/plugins/base/src/test/kotlin/transformers/ReportUndocumentedTransformerTest.kt @@ -150,6 +150,35 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { } } + @Test + fun `data class component functions do not get reported`() { + val configuration = dokkaConfiguration { + passes { + pass { + reportUndocumented = true + sourceRoots = listOf("src/main/kotlin") + } + } + } + + testInline( + """ + |/src/main/kotlin/Test.kt + |package sample + | + |/** Documented */ + |data class X(val x: Int) { + |} + """.trimIndent(), + configuration + ) { + pagesTransformationStage = { + assertNoUndocumentedReport(Regex("component")) + assertNumberOfUndocumentedReports(1) + } + } + } + @Disabled @Test fun `undocumented secondary constructor gets reported`() { -- cgit From cae0ab0b5c9358f4b7d42209d59fad337c01d9be Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Mon, 29 Jun 2020 11:12:35 +0200 Subject: Test Api, "testInline": Add support for idiomatic trimIndent and trimMargin --- .../ReportUndocumentedTransformerTest.kt | 52 +++++++++++----------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'plugins/base/src/test/kotlin/transformers') diff --git a/plugins/base/src/test/kotlin/transformers/ReportUndocumentedTransformerTest.kt b/plugins/base/src/test/kotlin/transformers/ReportUndocumentedTransformerTest.kt index fac1e060..523813fc 100644 --- a/plugins/base/src/test/kotlin/transformers/ReportUndocumentedTransformerTest.kt +++ b/plugins/base/src/test/kotlin/transformers/ReportUndocumentedTransformerTest.kt @@ -26,7 +26,7 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { |package sample | |class X - """.trimIndent(), + """.trimMargin(), configuration ) { pagesTransformationStage = { @@ -53,7 +53,7 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { |package sample | |internal class X - """.trimIndent(), + """.trimMargin(), configuration ) { pagesTransformationStage = { @@ -82,7 +82,7 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { |class X { | fun x() |} - """.trimIndent(), + """.trimMargin(), configuration ) { pagesTransformationStage = { @@ -112,7 +112,7 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { |class X { | val x: Int = 0 |} - """.trimIndent(), + """.trimMargin(), configuration ) { pagesTransformationStage = { @@ -141,7 +141,7 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { |/** Documented */ |class X(private val x: Int) { |} - """.trimIndent(), + """.trimMargin(), configuration ) { pagesTransformationStage = { @@ -169,7 +169,7 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { |/** Documented */ |data class X(val x: Int) { |} - """.trimIndent(), + """.trimMargin(), configuration ) { pagesTransformationStage = { @@ -200,7 +200,7 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { |class X { | constructor(unit: Unit) : this() |} - """.trimIndent(), + """.trimMargin(), configuration ) { pagesTransformationStage = { @@ -233,7 +233,7 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { | |/** Documented */ |class B : A() - """.trimIndent(), + """.trimMargin(), configuration ) { pagesTransformationStage = { @@ -266,7 +266,7 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { | |/** Documented */ |class B : A() - """.trimIndent(), + """.trimMargin(), configuration ) { pagesTransformationStage = { @@ -303,7 +303,7 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { |class B : A() { | override fun a() = throw Exception() |} - """.trimIndent(), + """.trimMargin(), configuration ) { pagesTransformationStage = { @@ -339,7 +339,7 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { |class B : A() { | override val a = 1 |} - """.trimIndent(), + """.trimMargin(), configuration ) { pagesTransformationStage = { @@ -365,7 +365,7 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { |package sample | |class X - """.trimIndent(), + """.trimMargin(), configuration ) { pagesTransformationStage = { @@ -395,7 +395,7 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { |package sample | |class X - """.trimIndent(), + """.trimMargin(), configuration ) { pagesTransformationStage = { @@ -432,7 +432,7 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { |/src/main/kotlin/sample/enabled/Enabled.kt |package sample.enabled |class Enabled - """.trimIndent(), + """.trimMargin(), configuration ) { pagesTransformationStage = { @@ -470,7 +470,7 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { |/src/main/kotlin/sample/enabled/Enabled.kt |package sample.enabled |class Enabled - """.trimIndent(), + """.trimMargin(), configuration ) { pagesTransformationStage = { @@ -512,7 +512,7 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { |/src/jvmMain/kotlin/sample/JvmMain.kt |package sample |actual class X - """.trimIndent(), + """.trimMargin(), configuration ) { pagesTransformationStage = { @@ -556,7 +556,7 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { |/src/jvmMain/kotlin/sample/JvmMain.kt |package sample |actual class X - """.trimIndent(), + """.trimMargin(), configuration ) { pagesTransformationStage = { @@ -611,7 +611,7 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { |/src/jvmMain/kotlin/sample/JvmMain.kt |package sample |actual fun x() = Unit - """.trimIndent(), + """.trimMargin(), configuration ) { pagesTransformationStage = { @@ -638,7 +638,7 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { |/src/main/java/sample/Test.java |package sample |public class Test { } - """.trimIndent(), + """.trimMargin(), configuration ) { pagesTransformationStage = { @@ -665,7 +665,7 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { |/src/main/java/sample/Test.java |package sample |class Test { } - """.trimIndent(), + """.trimMargin(), configuration ) { pagesTransformationStage = { @@ -694,7 +694,7 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { | public Test() { | } |} - """.trimIndent(), + """.trimMargin(), configuration ) { pagesTransformationStage = { @@ -722,7 +722,7 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { |public class X { | public void x { } |} - """.trimIndent(), + """.trimMargin(), configuration ) { pagesTransformationStage = { @@ -752,7 +752,7 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { |public class X { | public int x = 0; |} - """.trimIndent(), + """.trimMargin(), configuration ) { pagesTransformationStage = { @@ -790,7 +790,7 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { | public void x() {} |} | - """.trimIndent(), + """.trimMargin(), configuration ) { pagesTransformationStage = { @@ -830,7 +830,7 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { | |} | - """.trimIndent(), + """.trimMargin(), configuration ) { pagesTransformationStage = { @@ -868,7 +868,7 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { | public void x() {} |} | - """.trimIndent(), + """.trimMargin(), configuration ) { pagesTransformationStage = { -- cgit From a89fef501de1ab2149417dc23a3ad94744a59e08 Mon Sep 17 00:00:00 2001 From: Filip Zybała Date: Mon, 29 Jun 2020 18:38:55 +0200 Subject: Handling multi-line list items. Added tests for comment to content converter. --- .../transformers/CommentsToContentConverterTest.kt | 407 +++++++++++++++++++++ 1 file changed, 407 insertions(+) create mode 100644 plugins/base/src/test/kotlin/transformers/CommentsToContentConverterTest.kt (limited to 'plugins/base/src/test/kotlin/transformers') diff --git a/plugins/base/src/test/kotlin/transformers/CommentsToContentConverterTest.kt b/plugins/base/src/test/kotlin/transformers/CommentsToContentConverterTest.kt new file mode 100644 index 00000000..2fe2d2ae --- /dev/null +++ b/plugins/base/src/test/kotlin/transformers/CommentsToContentConverterTest.kt @@ -0,0 +1,407 @@ +package transformers + +import org.jetbrains.dokka.DokkaConfiguration +import org.jetbrains.dokka.base.DokkaBase +import org.jetbrains.dokka.base.transformers.pages.comments.DocTagToContentConverter +import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.model.doc.* +import org.jetbrains.dokka.plugability.querySingle +import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Test +import matchers.content.* +import org.jetbrains.dokka.pages.* +import org.jetbrains.kotlin.utils.addToStdlib.assertedCast +import utils.assertIsInstance + +class CommentsToContentConverterTest { + private val converter = DocTagToContentConverter + + private fun executeTest( + docTag:DocTag, + match: ContentMatcherBuilder.() -> Unit + ) { + val dci = DCI( + setOf( + DRI("kotlin", "Any") + ), + ContentKind.Comment + ) + converter.buildContent( + Li( + listOf( + docTag + ) + ), + dci, + emptySet() + ).single().assertNode(match) + } + + @Test + fun `simple text`() { + val docTag = P(listOf(Text("This is simple test of string Next line"))) + executeTest(docTag) { + +"This is simple test of string Next line" + } + } + + @Test + fun `simple text with new line`() { + val docTag = P( + listOf( + Text("This is simple test of string"), + Br, + Text("Next line") + ) + ) + executeTest(docTag) { + +"This is simple test of string" + node() + +"Next line" + } + } + + @Test + fun `paragraphs`() { + val docTag = P( + listOf( + P(listOf(Text("Paragraph number one"))), + P(listOf(Text("Paragraph"), Br, Text("number two"))) + ) + ) + executeTest(docTag) { + +"Paragraph number one" + +"Paragraph" + node() + +"number two" + } + } + + @Test + fun `unordered list with empty lines`() { + val docTag = Ul( + listOf( + Li(listOf(P(listOf(Text("list item 1 continue 1"))))), + Li(listOf(P(listOf(Text("list item 2"), Br, Text("continue 2"))))) + ) + ) + executeTest(docTag) { + node { + group { + +"list item 1 continue 1" + } + group { + +"list item 2" + node() + +"continue 2" + } + } + } + } + + @Test + fun `nested list`() { + val docTag = P( + listOf( + Ul( + listOf( + Li(listOf(P(listOf(Text("Outer first Outer next line"))))), + Li(listOf(P(listOf(Text("Outer second"))))), + Ul( + listOf( + Li(listOf(P(listOf(Text("Middle first Middle next line"))))), + Li(listOf(P(listOf(Text("Middle second"))))), + Ul( + listOf( + Li(listOf(P(listOf(Text("Inner first Inner next line"))))) + ) + ), + Li(listOf(P(listOf(Text("Middle third"))))) + ) + ), + Li(listOf(P(listOf(Text("Outer third"))))) + ) + ), + P(listOf(Text("New paragraph"))) + ) + ) + executeTest(docTag) { + node { + group { +"Outer first Outer next line" } + group { +"Outer second" } + node { + group { +"Middle first Middle next line" } + group { +"Middle second" } + node { + group { +"Inner first Inner next line" } + } + group { +"Middle third" } + } + group { +"Outer third" } + } + +"New paragraph" + } + } + + @Test + fun `header and paragraphs`() { + val docTag = P( + listOf( + H1(listOf(Text("Header 1"))), + P(listOf(Text("Following text"))), + P(listOf(Text("New paragraph"))) + ) + ) + executeTest(docTag) { + header(1) { +"Header 1" } + +"Following text" + +"New paragraph" + } + } + + @Test + fun `header levels`() { + val docTag = P( + listOf( + H1(listOf(Text("Header 1"))), + P(listOf(Text("Text 1"))), + H2(listOf(Text("Header 2"))), + P(listOf(Text("Text 2"))), + H3(listOf(Text("Header 3"))), + P(listOf(Text("Text 3"))), + H4(listOf(Text("Header 4"))), + P(listOf(Text("Text 4"))), + H5(listOf(Text("Header 5"))), + P(listOf(Text("Text 5"))), + H6(listOf(Text("Header 6"))), + P(listOf(Text("Text 6"))) + ) + ) + executeTest(docTag) { + header(1) {+"Header 1"} + +"Text 1" + header(2) {+"Header 2"} + +"Text 2" + header(3) {+"Header 3"} + +"Text 3" + header(4) {+"Header 4"} + +"Text 4" + header(5) {+"Header 5"} + +"Text 5" + header(6) {+"Header 6"} + +"Text 6" + } + } + + @Test + fun `block quotes`() { + val docTag = P( + listOf( + BlockQuote( + listOf( + P( + listOf( + Text("Blockquotes are very handy in email to emulate reply text. This line is part of the same quote.") + ) + ) + ) + ), + P(listOf(Text("Quote break."))), + BlockQuote( + listOf( + P(listOf(Text("Quote"))) + ) + ) + ) + ) + executeTest(docTag) { + node { + +"Blockquotes are very handy in email to emulate reply text. This line is part of the same quote." + } + +"Quote break." + node { + +"Quote" + } + } + } + + @Test + fun `nested block quotes`() { + val docTag = P( + listOf( + BlockQuote( + listOf( + P(listOf(Text("text 1 text 2"))), + BlockQuote( + listOf( + P(listOf(Text("text 3 text 4"))) + ) + ), + P(listOf(Text("text 5"))) + ) + ), + P(listOf(Text("Quote break."))), + BlockQuote( + listOf( + P(listOf(Text("Quote"))) + ) + ) + ) + ) + executeTest(docTag) { + node { + +"text 1 text 2" + node { + +"text 3 text 4" + } + +"text 5" + } + +"Quote break." + node { + +"Quote" + } + } + } + + @Test + fun `multiline code`() { + val docTag = P( + listOf( + Code( + listOf( + Text("val x: Int = 0"), Br, + Text("val y: String = \"Text\""), Br, Br, + Text(" val z: Boolean = true"), Br, + Text("for(i in 0..10) {"), Br, + Text(" println(i)"), Br, + Text("}") + ), + mapOf("lang" to "kotlin") + ), + P(listOf(Text("Sample text"))) + ) + ) + executeTest(docTag) { + node { + +"val x: Int = 0" + node() + +"val y: String = \"Text\"" + node() + node() + +" val z: Boolean = true" + node() + +"for(i in 0..10) {" + node() + +" println(i)" + node() + +"}" + } + +"Sample text" + } + } + + @Test + fun `inline link`() { + val docTag = P( + listOf( + A( + listOf(Text("I'm an inline-style link")), + mapOf("href" to "https://www.google.com") + ) + ) + ) + executeTest(docTag) { + link { + +"I'm an inline-style link" + check { + assertEquals( + assertedCast { "Link should be resolved" }.address, + "https://www.google.com" + ) + } + } + } + } + + + + @Test + fun `ordered list`() { + val docTag = + Ol( + listOf( + Li( + listOf( + P(listOf(Text("test1"))), + P(listOf(Text("test2"))), + ) + ), + Li( + listOf( + P(listOf(Text("test3"))), + P(listOf(Text("test4"))), + ) + ) + ) + ) + executeTest(docTag) { + node { + group { + +"test1" + +"test2" + } + group { + +"test3" + +"test4" + } + } + } + } + + @Test + fun `nested ordered list`() { + val docTag = P( + listOf( + Ol( + listOf( + Li(listOf(P(listOf(Text("Outer first Outer next line"))))), + Li(listOf(P(listOf(Text("Outer second"))))), + Ol( + listOf( + Li(listOf(P(listOf(Text("Middle first Middle next line"))))), + Li(listOf(P(listOf(Text("Middle second"))))), + Ol( + listOf( + Li(listOf(P(listOf(Text("Inner first Inner next line"))))) + ), + mapOf("start" to "1") + ), + Li(listOf(P(listOf(Text("Middle third"))))) + ), + mapOf("start" to "1") + ), + Li(listOf(P(listOf(Text("Outer third"))))) + ), + mapOf("start" to "1") + ), + P(listOf(Text("New paragraph"))) + ) + ) + executeTest(docTag) { + node { + group { +"Outer first Outer next line" } + group { +"Outer second" } + node { + group { +"Middle first Middle next line" } + group { +"Middle second" } + node { + +"Inner first Inner next line" + } + group { +"Middle third" } + } + group { +"Outer third" } + } + +"New paragraph" + } + } +} \ No newline at end of file -- cgit From b0e8622f374f6499058b0f083367b4a54512b702 Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Tue, 30 Jun 2020 23:06:03 +0200 Subject: Enforce workspace unique SourceSetID --- .../ReportUndocumentedTransformerTest.kt | 136 ++++++++++----------- 1 file changed, 68 insertions(+), 68 deletions(-) (limited to 'plugins/base/src/test/kotlin/transformers') diff --git a/plugins/base/src/test/kotlin/transformers/ReportUndocumentedTransformerTest.kt b/plugins/base/src/test/kotlin/transformers/ReportUndocumentedTransformerTest.kt index 523813fc..72948372 100644 --- a/plugins/base/src/test/kotlin/transformers/ReportUndocumentedTransformerTest.kt +++ b/plugins/base/src/test/kotlin/transformers/ReportUndocumentedTransformerTest.kt @@ -12,8 +12,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `undocumented class gets reported`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { reportUndocumented = true sourceRoots = listOf("src/main/kotlin/Test.kt") } @@ -39,8 +39,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `undocumented non-public class does not get reported`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { reportUndocumented = true sourceRoots = listOf("src/main/kotlin/Test.kt") } @@ -65,8 +65,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `undocumented function gets reported`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { reportUndocumented = true sourceRoots = listOf("src/main/kotlin/Test.kt") } @@ -95,8 +95,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `undocumented property gets reported`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { reportUndocumented = true sourceRoots = listOf("src/main/kotlin/Test.kt") } @@ -125,8 +125,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `undocumented primary constructor does not get reported`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { reportUndocumented = true sourceRoots = listOf("src/main/kotlin/Test.kt") } @@ -153,8 +153,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `data class component functions do not get reported`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { reportUndocumented = true sourceRoots = listOf("src/main/kotlin") } @@ -183,8 +183,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `undocumented secondary constructor gets reported`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { reportUndocumented = true sourceRoots = listOf("src/main/kotlin/Test.kt") } @@ -213,8 +213,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `undocumented inherited function does not get reported`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { reportUndocumented = true sourceRoots = listOf("src/main/kotlin/Test.kt") } @@ -246,8 +246,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `undocumented inherited property does not get reported`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { reportUndocumented = true sourceRoots = listOf("src/main/kotlin/Test.kt") } @@ -279,8 +279,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `overridden function does not get reported when super is documented`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { reportUndocumented = true sourceRoots = listOf("src/main/kotlin/Test.kt") } @@ -315,8 +315,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `overridden property does not get reported when super is documented`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { reportUndocumented = true sourceRoots = listOf("src/main/kotlin/Test.kt") } @@ -349,10 +349,10 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { } @Test - fun `report disabled by pass configuration`() { + fun `report disabled by source set`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { reportUndocumented = false sourceRoots = listOf("src/main/kotlin/Test.kt") } @@ -377,8 +377,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `report enabled by package configuration`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { perPackageOptions += packageOptions( prefix = "sample", reportUndocumented = true, @@ -407,8 +407,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `report enabled by more specific package configuration`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { perPackageOptions += packageOptions( prefix = "sample", reportUndocumented = false, @@ -445,8 +445,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `report disabled by more specific package configuration`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { perPackageOptions += packageOptions( prefix = "sample", reportUndocumented = true, @@ -483,22 +483,22 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `multiplatform undocumented class gets reported`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + val commonMain = sourceSet { reportUndocumented = true analysisPlatform = Platform.common.toString() - sourceSetID = "commonMain" + name = "commonMain" displayName = "commonMain" sourceRoots = listOf("src/commonMain/kotlin") } - pass { + sourceSet { reportUndocumented = true analysisPlatform = Platform.jvm.toString() - sourceSetID = "jvmMain" + name = "jvmMain" displayName = "jvmMain" sourceRoots = listOf("src/jvmMain/kotlin") - dependentSourceSets = listOf("commonMain") + dependentSourceSets = setOf(commonMain.sourceSetID) } } } @@ -526,22 +526,22 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `multiplatform undocumented class does not get reported if expect is documented`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + val commonMain = sourceSet { reportUndocumented = true analysisPlatform = Platform.common.toString() - sourceSetID = "commonMain" + name = "commonMain" displayName = "commonMain" sourceRoots = listOf("