From 29cc17ba80018e3e45a5fabcf2e370c735fd5674 Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Tue, 25 Aug 2020 14:28:44 +0200 Subject: Implement ModuleAndPackageDocumentationReader --- .../ParseModuleAndPackageDocFragmentsTest.kt | 199 -------------------- ...seModuleAndPackageDocumentationFragmentsTest.kt | 201 +++++++++++++++++++++ 2 files changed, 201 insertions(+), 199 deletions(-) delete mode 100644 plugins/base/src/test/kotlin/parsers/ParseModuleAndPackageDocFragmentsTest.kt create mode 100644 plugins/base/src/test/kotlin/parsers/ParseModuleAndPackageDocumentationFragmentsTest.kt (limited to 'plugins/base/src/test/kotlin') diff --git a/plugins/base/src/test/kotlin/parsers/ParseModuleAndPackageDocFragmentsTest.kt b/plugins/base/src/test/kotlin/parsers/ParseModuleAndPackageDocFragmentsTest.kt deleted file mode 100644 index 49eddaea..00000000 --- a/plugins/base/src/test/kotlin/parsers/ParseModuleAndPackageDocFragmentsTest.kt +++ /dev/null @@ -1,199 +0,0 @@ -package parsers - -import org.jetbrains.dokka.base.parsers.IllegalModuleAndPackageDocumentation -import org.jetbrains.dokka.base.parsers.ModuleAndPackageDocFragment -import org.jetbrains.dokka.base.parsers.ModuleAndPackageDocFragment.Classifier.Module -import org.jetbrains.dokka.base.parsers.ModuleAndPackageDocFragment.Classifier.Package -import org.jetbrains.dokka.base.parsers.ModuleAndPackageDocumentationSource -import org.jetbrains.dokka.base.parsers.parseModuleAndPackageDocFragments -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertTrue -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertThrows -import org.junit.jupiter.api.io.TempDir -import java.nio.file.Path - -class ParseModuleAndPackageDocFragmentsTest { - - @Test - fun `basic example`() { - - val fragments = parseModuleAndPackageDocFragments( - source( - """ - # Module kotlin-demo - Module description - - # Package org.jetbrains.kotlin.demo - Package demo description - ## Level 2 heading - Heading 2 - - # Package org.jetbrains.kotlin.demo2 - Package demo2 description - """.trimIndent() - ) - ) - - assertEquals( - listOf( - ModuleAndPackageDocFragment( - classifier = Module, - name = "kotlin-demo", - documentation = "Module description" - ), - ModuleAndPackageDocFragment( - classifier = Package, - name = "org.jetbrains.kotlin.demo", - documentation = "Package demo description\n## Level 2 heading\nHeading 2" - ), - ModuleAndPackageDocFragment( - classifier = Package, - name = "org.jetbrains.kotlin.demo2", - documentation = "Package demo2 description" - ) - ), - fragments - ) - } - - @Test - fun `no module name specified fails`() { - val exception = assertThrows { - parseModuleAndPackageDocFragments( - source( - """ - # Module - No module name given - """.trimIndent() - ) - ) - } - - assertTrue( - "Missing Module name" in exception.message.orEmpty(), - "Expected 'Missing Module name' in error message" - ) - } - - @Test - fun `no package name specified fails`() { - val exception = assertThrows { - parseModuleAndPackageDocFragments( - source( - """ - # Package - No package name given - """.trimIndent() - ) - ) - } - - assertTrue( - "Missing Package name" in exception.message.orEmpty(), - "Expected 'Missing Package name' in error message" - ) - } - - @Test - fun `white space in module name fails`() { - val exception = assertThrows { - parseModuleAndPackageDocFragments( - source( - """ - # Module My Module - """.trimIndent() - ) - ) - } - - assertTrue( - "Module My Module" in exception.message.orEmpty(), - "Expected problematic statement in error message" - ) - } - - @Test - fun `white space in package name fails`() { - val exception = assertThrows { - parseModuleAndPackageDocFragments( - source( - """ - # Package my package - """.trimIndent() - ) - ) - } - - assertTrue( - "Package my package" in exception.message.orEmpty(), - "Expected problematic statement in error message" - ) - } - - @Test - fun `multiple whitespaces are supported in first line`() { - val fragments = parseModuleAndPackageDocFragments( - source( - """ - # Module my-module - My Module - # Package com.my.package - My Package - """.trimIndent() - ) - ) - - assertEquals( - listOf( - ModuleAndPackageDocFragment( - classifier = Module, - name = "my-module", - documentation = "My Module" - ), - ModuleAndPackageDocFragment( - classifier = Package, - name = "com.my.package", - documentation = "My Package" - ) - ), - fragments - ) - } - - @Test - fun `parse from file`(@TempDir temporaryFolder: Path) { - val file = temporaryFolder.resolve("other.md").toFile() - file.writeText( - """ - # Module MyModule - D1 - # Package com.sample - D2 - """.trimIndent() - ) - - assertEquals( - listOf( - ModuleAndPackageDocFragment( - classifier = Module, - name = "MyModule", - documentation = "D1" - ), - ModuleAndPackageDocFragment( - classifier = Package, - name = "com.sample", - documentation = "D2" - ) - ), - parseModuleAndPackageDocFragments(file) - ) - } - - - private fun source(documentation: String): ModuleAndPackageDocumentationSource = - object : ModuleAndPackageDocumentationSource() { - override val sourceDescription: String = "inline test" - override val documentation: String = documentation - } -} diff --git a/plugins/base/src/test/kotlin/parsers/ParseModuleAndPackageDocumentationFragmentsTest.kt b/plugins/base/src/test/kotlin/parsers/ParseModuleAndPackageDocumentationFragmentsTest.kt new file mode 100644 index 00000000..5c0a0646 --- /dev/null +++ b/plugins/base/src/test/kotlin/parsers/ParseModuleAndPackageDocumentationFragmentsTest.kt @@ -0,0 +1,201 @@ +package parsers + +import org.jetbrains.dokka.base.parsers.moduleAndPackage.* +import org.jetbrains.dokka.base.parsers.moduleAndPackage.ModuleAndPackageDocumentation.Classifier.Module +import org.jetbrains.dokka.base.parsers.moduleAndPackage.ModuleAndPackageDocumentation.Classifier.Package +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import org.junit.jupiter.api.io.TempDir +import java.nio.file.Path + +class ParseModuleAndPackageDocumentationFragmentsTest { + + @Test + fun `basic example`() { + + val source = source( + """ + # Module kotlin-demo + Module description + + # Package org.jetbrains.kotlin.demo + Package demo description + ## Level 2 heading + Heading 2 + + # Package org.jetbrains.kotlin.demo2 + Package demo2 description + """.trimIndent() + ) + val fragments = parseModuleAndPackageDocumentationFragments(source) + + assertEquals( + listOf( + ModuleAndPackageDocumentationFragment( + classifier = Module, + name = "kotlin-demo", + documentation = "Module description", + source = source + ), + ModuleAndPackageDocumentationFragment( + classifier = Package, + name = "org.jetbrains.kotlin.demo", + documentation = "Package demo description\n## Level 2 heading\nHeading 2", + source = source + ), + ModuleAndPackageDocumentationFragment( + classifier = Package, + name = "org.jetbrains.kotlin.demo2", + documentation = "Package demo2 description", + source = source + ) + ), + fragments + ) + } + + @Test + fun `no module name specified fails`() { + val exception = assertThrows { + parseModuleAndPackageDocumentationFragments( + source( + """ + # Module + No module name given + """.trimIndent() + ) + ) + } + + assertTrue( + "Missing Module name" in exception.message.orEmpty(), + "Expected 'Missing Module name' in error message" + ) + } + + @Test + fun `no package name specified fails`() { + val exception = assertThrows { + parseModuleAndPackageDocumentationFragments( + source( + """ + # Package + No package name given + """.trimIndent() + ) + ) + } + + assertTrue( + "Missing Package name" in exception.message.orEmpty(), + "Expected 'Missing Package name' in error message" + ) + } + + @Test + fun `white space in module name fails`() { + val exception = assertThrows { + parseModuleAndPackageDocumentationFragments( + source( + """ + # Module My Module + """.trimIndent() + ) + ) + } + + assertTrue( + "Module My Module" in exception.message.orEmpty(), + "Expected problematic statement in error message" + ) + } + + @Test + fun `white space in package name fails`() { + val exception = assertThrows { + parseModuleAndPackageDocumentationFragments( + source( + """ + # Package my package + """.trimIndent() + ) + ) + } + + assertTrue( + "Package my package" in exception.message.orEmpty(), + "Expected problematic statement in error message" + ) + } + + @Test + fun `multiple whitespaces are supported in first line`() { + val source = source( + """ + # Module my-module + My Module + # Package com.my.package + My Package + """.trimIndent() + ) + val fragments = parseModuleAndPackageDocumentationFragments(source) + + assertEquals( + listOf( + ModuleAndPackageDocumentationFragment( + classifier = Module, + name = "my-module", + documentation = "My Module", + source = source + ), + ModuleAndPackageDocumentationFragment( + classifier = Package, + name = "com.my.package", + documentation = "My Package", + source = source + ) + ), + fragments + ) + } + + @Test + fun `parse from file`(@TempDir temporaryFolder: Path) { + val file = temporaryFolder.resolve("other.md").toFile() + file.writeText( + """ + # Module MyModule + D1 + # Package com.sample + D2 + """.trimIndent() + ) + + assertEquals( + listOf( + ModuleAndPackageDocumentationFragment( + classifier = Module, + name = "MyModule", + documentation = "D1", + source = ModuleAndPackageDocumentationFile(file) + ), + ModuleAndPackageDocumentationFragment( + classifier = Package, + name = "com.sample", + documentation = "D2", + source = ModuleAndPackageDocumentationFile(file) + ) + ), + parseModuleAndPackageDocumentationFragments(file) + ) + } + + + private fun source(documentation: String): ModuleAndPackageDocumentationSource = + object : ModuleAndPackageDocumentationSource() { + override val sourceDescription: String = "inline test" + override val documentation: String = documentation + } +} -- cgit