diff options
author | Andrzej Ratajczak <andrzej.ratajczak98@gmail.com> | 2020-07-02 11:33:52 +0200 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-07-08 11:48:29 +0200 |
commit | f80d5938ccafcf5bd41d73f98bebe2d9699faa95 (patch) | |
tree | 8d0df46b4f806bdcc092c2f38af5face44e026bb /plugins/gfm/src/test | |
parent | 5647b4221604a9084194949d9c582a57da920220 (diff) | |
download | dokka-f80d5938ccafcf5bd41d73f98bebe2d9699faa95.tar.gz dokka-f80d5938ccafcf5bd41d73f98bebe2d9699faa95.tar.bz2 dokka-f80d5938ccafcf5bd41d73f98bebe2d9699faa95.zip |
Add GFM renderer tests
Diffstat (limited to 'plugins/gfm/src/test')
4 files changed, 621 insertions, 0 deletions
diff --git a/plugins/gfm/src/test/kotlin/renderers/gfm/DivergentTest.kt b/plugins/gfm/src/test/kotlin/renderers/gfm/DivergentTest.kt new file mode 100644 index 00000000..13231c43 --- /dev/null +++ b/plugins/gfm/src/test/kotlin/renderers/gfm/DivergentTest.kt @@ -0,0 +1,375 @@ +package renderers.gfm + +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.SourceRootImpl +import org.jetbrains.dokka.gfm.CommonmarkRenderer +import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.pages.ContentDivergentGroup +import org.junit.jupiter.api.Test +import renderers.gfm.GfmRenderingOnlyTestBase +import renderers.defaultSourceSet +import renderers.TestPage + +class DivergentTest : GfmRenderingOnlyTestBase() { + private val js = defaultSourceSet.copy( + "root", + "JS", + "js", + analysisPlatform = Platform.js, + sourceRoots = listOf(SourceRootImpl("pl1")) + ) + private val jvm = defaultSourceSet.copy( + "root", + "JVM", + "jvm", + + analysisPlatform = Platform.jvm, + sourceRoots = listOf(SourceRootImpl("pl1")) + ) + private val native = defaultSourceSet.copy( + "root", + "NATIVE", + "native", + analysisPlatform = Platform.native, + sourceRoots = listOf(SourceRootImpl("pl1")) + ) + + @Test + fun simpleWrappingCase() { + val page = TestPage { + divergentGroup(ContentDivergentGroup.GroupID("test")) { + instance(setOf(DRI("test", "Test")), setOf(js)) { + divergent { + text("a") + } + } + } + } + val expect = "//[testPage](test-page.md)\n\n#### [root/js] \n##### Content \na \n" + CommonmarkRenderer(context).render(page) + assert(renderedContent == expect) + } + + @Test + fun noPlatformHintCase() { + val page = TestPage { + divergentGroup(ContentDivergentGroup.GroupID("test"), implicitlySourceSetHinted = false) { + instance(setOf(DRI("test", "Test")), setOf(js)) { + divergent { + text("a") + } + } + } + } + val expect = "//[testPage](test-page.md)\n\n#### [root/js] \n##### Content \na \n" + CommonmarkRenderer(context).render(page) + assert(renderedContent == expect) + } + + @Test + fun divergentBetweenSourceSets() { + val page = TestPage { + divergentGroup(ContentDivergentGroup.GroupID("test")) { + instance(setOf(DRI("test", "Test")), setOf(js)) { + divergent { + text("a") + } + } + instance(setOf(DRI("test", "Test")), setOf(jvm)) { + divergent { + text("b") + } + } + instance(setOf(DRI("test", "Test")), setOf(native)) { + divergent { + text("c") + } + } + } + } + val expect = "//[testPage](test-page.md)\n\n#### [root/js, root/jvm, root/native] \n##### Content \n###### [root/js] \na \n###### [root/jvm] \nb \n###### [root/native] \nc \n" + CommonmarkRenderer(context).render(page) + assert(renderedContent == expect) + } + + @Test + fun divergentInOneSourceSet() { + val page = TestPage { + divergentGroup(ContentDivergentGroup.GroupID("test")) { + instance(setOf(DRI("test", "Test")), setOf(js)) { + divergent { + text("a") + } + } + instance(setOf(DRI("test", "Test2")), setOf(js)) { + divergent { + text("b") + } + } + instance(setOf(DRI("test", "Test3")), setOf(js)) { + divergent { + text("c") + } + } + } + } + val expect = "//[testPage](test-page.md)\n\n#### [root/js] \n##### Content \na \nb \nc \n" + CommonmarkRenderer(context).render(page) + assert(renderedContent == expect) + } + + @Test + fun divergentInAndBetweenSourceSets() { + val page = TestPage { + divergentGroup(ContentDivergentGroup.GroupID("test")) { + instance(setOf(DRI("test", "Test")), setOf(native)) { + divergent { + text("a") + } + } + instance(setOf(DRI("test", "Test")), setOf(js)) { + divergent { + text("b") + } + } + instance(setOf(DRI("test", "Test")), setOf(jvm)) { + divergent { + text("c") + } + } + instance(setOf(DRI("test", "Test2")), setOf(js)) { + divergent { + text("d") + } + } + instance(setOf(DRI("test", "Test3")), setOf(native)) { + divergent { + text("e") + } + } + } + } + val expect = "//[testPage](test-page.md)\n\n#### [root/native, root/js, root/jvm] \n##### Content \n###### [root/native] \na \n###### [root/js] \nb \n###### [root/jvm] \nc \n###### [root/js] \nd \n###### [root/native] \ne \n" + CommonmarkRenderer(context).render(page) + assert(renderedContent == expect) + } + + @Test + fun divergentInAndBetweenSourceSetsWithGrouping() { + val page = TestPage { + divergentGroup(ContentDivergentGroup.GroupID("test")) { + instance(setOf(DRI("test", "Test")), setOf(native)) { + divergent { + text("a") + } + after { + text("a+") + } + } + instance(setOf(DRI("test", "Test")), setOf(js)) { + divergent { + text("b") + } + after { + text("bd+") + } + } + instance(setOf(DRI("test", "Test")), setOf(jvm)) { + divergent { + text("c") + } + } + instance(setOf(DRI("test", "Test2")), setOf(js)) { + divergent { + text("d") + } + after { + text("bd+") + } + } + instance(setOf(DRI("test", "Test3")), setOf(native)) { + divergent { + text("e") + } + after { + text("e+") + } + } + } + } + val expect = "//[testPage](test-page.md)\n\n#### [root/native] \n##### Content \na \n##### More info \na+ \n#### [root/js] \n##### Content \nb \nd \n##### More info \nbd+ \n#### [root/jvm] \n##### Content \nc \n#### [root/native] \n##### Content \ne \n##### More info \ne+ \n" + CommonmarkRenderer(context).render(page) + assert(renderedContent == expect) + } + + @Test + fun divergentSameBefore() { + val page = TestPage { + divergentGroup(ContentDivergentGroup.GroupID("test")) { + instance(setOf(DRI("test", "Test")), setOf(native)) { + before { + text("ab-") + } + divergent { + text("a") + } + } + instance(setOf(DRI("test", "Test2")), setOf(native)) { + before { + text("ab-") + } + divergent { + text("b") + } + } + } + } + val expect = "//[testPage](test-page.md)\n\n#### [root/native] \n##### Brief description \nab- \n##### Content \na \nb \n" + CommonmarkRenderer(context).render(page) + assert(renderedContent == expect) + } + + @Test + fun divergentSameAfter() { + val page = TestPage { + divergentGroup(ContentDivergentGroup.GroupID("test")) { + instance(setOf(DRI("test", "Test")), setOf(native)) { + divergent { + text("a") + } + after { + text("ab+") + } + } + instance(setOf(DRI("test", "Test2")), setOf(native)) { + divergent { + text("b") + } + after { + text("ab+") + } + } + } + } + val expect = "//[testPage](test-page.md)\n\n#### [root/native] \n##### Content \na \nb \n##### More info \nab+ \n" + CommonmarkRenderer(context).render(page) + assert(renderedContent == expect) + } + + @Test + fun divergentGroupedByBeforeAndAfter() { + val page = TestPage { + divergentGroup(ContentDivergentGroup.GroupID("test")) { + instance(setOf(DRI("test", "Test")), setOf(native)) { + before { + text("ab-") + } + divergent { + text("a") + } + after { + text("ab+") + } + } + instance(setOf(DRI("test", "Test2")), setOf(native)) { + before { + text("ab-") + } + divergent { + text("b") + } + after { + text("ab+") + } + } + } + } + val expect = "//[testPage](test-page.md)\n\n#### [root/native] \n##### Brief description \nab- \n##### Content \na \nb \n##### More info \nab+ \n" + CommonmarkRenderer(context).render(page) + assert(renderedContent == expect) + } + + @Test + fun divergentDifferentBeforeAndAfter() { + val page = TestPage { + divergentGroup(ContentDivergentGroup.GroupID("test")) { + instance(setOf(DRI("test", "Test")), setOf(native)) { + before { + text("a-") + } + divergent { + text("a") + } + after { + text("ab+") + } + } + instance(setOf(DRI("test", "Test2")), setOf(native)) { + before { + text("b-") + } + divergent { + text("b") + } + after { + text("ab+") + } + } + } + } + val expect = "//[testPage](test-page.md)\n\n#### [root/native] \n##### Brief description \na- \n##### Content \na \n##### More info \nab+ \n#### [root/native] \n##### Brief description \nb- \n##### Content \nb \n##### More info \nab+ \n" + CommonmarkRenderer(context).render(page) + assert(renderedContent == expect) + } + + @Test + fun divergentInAndBetweenSourceSetsWithGroupingAncCommonParts() { + val page = TestPage { + divergentGroup(ContentDivergentGroup.GroupID("test")) { + instance(setOf(DRI("test", "Test")), setOf(native)) { + divergent { + text("a") + } + after { + text("a+") + } + } + instance(setOf(DRI("test", "Test")), setOf(js)) { + divergent { + text("b") + } + after { + text("bd+") + } + } + instance(setOf(DRI("test", "Test")), setOf(jvm)) { + divergent { + text("c") + } + after { + text("bd+") + } + } + instance(setOf(DRI("test", "Test2")), setOf(js)) { + divergent { + text("d") + } + after { + text("bd+") + } + } + instance(setOf(DRI("test", "Test3")), setOf(native)) { + divergent { + text("e") + } + after { + text("e+") + } + } + } + } + val expect = "//[testPage](test-page.md)\n\n#### [root/native] \n##### Content \na \n##### More info \na+ \n#### [root/js, root/jvm] \n##### Content \n###### [root/js] \nb \n###### [root/jvm] \nc \n###### [root/js] \nd \n##### More info \nbd+ \n#### [root/native] \n##### Content \ne \n##### More info \ne+ \n" + CommonmarkRenderer(context).render(page) + assert(renderedContent == expect) + } +}
\ No newline at end of file diff --git a/plugins/gfm/src/test/kotlin/renderers/gfm/GfmRenderingOnlyTestBase.kt b/plugins/gfm/src/test/kotlin/renderers/gfm/GfmRenderingOnlyTestBase.kt new file mode 100644 index 00000000..3636bf26 --- /dev/null +++ b/plugins/gfm/src/test/kotlin/renderers/gfm/GfmRenderingOnlyTestBase.kt @@ -0,0 +1,32 @@ +package renderers.gfm + +import org.jetbrains.dokka.DokkaConfigurationImpl +import org.jetbrains.dokka.gfm.GfmPlugin +import org.jetbrains.dokka.gfm.MarkdownLocationProviderFactory +import org.jetbrains.dokka.testApi.context.MockContext +import org.jetbrains.dokka.base.DokkaBase +import org.jetbrains.dokka.base.renderers.RootCreator +import org.jetbrains.dokka.base.resolvers.external.DokkaExternalLocationProviderFactory +import org.jetbrains.dokka.base.resolvers.external.JavadocExternalLocationProviderFactory +import renderers.RenderingOnlyTestBase +import utils.TestOutputWriter + +abstract class GfmRenderingOnlyTestBase : RenderingOnlyTestBase() { + + val files = TestOutputWriter() + override val context = MockContext( + DokkaBase().outputWriter to { _ -> files }, + DokkaBase().locationProviderFactory to ::MarkdownLocationProviderFactory, + DokkaBase().externalLocationProviderFactory to { ::JavadocExternalLocationProviderFactory }, + DokkaBase().externalLocationProviderFactory to { ::DokkaExternalLocationProviderFactory }, + GfmPlugin().gfmPreprocessors to { _ -> RootCreator }, + + testConfiguration = DokkaConfigurationImpl( + "", "", null, false, emptyList(), emptyList(), emptyMap(), emptyList(), false + ) + ) + + protected val renderedContent: String by lazy { + files.contents.getValue("test-page.md") + } +}
\ No newline at end of file diff --git a/plugins/gfm/src/test/kotlin/renderers/gfm/GroupWrappingTest.kt b/plugins/gfm/src/test/kotlin/renderers/gfm/GroupWrappingTest.kt new file mode 100644 index 00000000..2e1dc83a --- /dev/null +++ b/plugins/gfm/src/test/kotlin/renderers/gfm/GroupWrappingTest.kt @@ -0,0 +1,77 @@ +package renderers.gfm + +import org.jetbrains.dokka.gfm.CommonmarkRenderer +import renderers.gfm.GfmRenderingOnlyTestBase +import org.jetbrains.dokka.pages.TextStyle +import org.junit.jupiter.api.Test +import renderers.* + +class GroupWrappingTest : GfmRenderingOnlyTestBase() { + + @Test + fun notWrapped() { + val page = TestPage { + group { + text("a") + text("b") + } + text("c") + } + + CommonmarkRenderer(context).render(page) + + assert(renderedContent == "//[testPage](test-page.md)\n\nabc") + } + + @Test + fun paragraphWrapped() { + val page = TestPage { + group(styles = setOf(TextStyle.Paragraph)) { + text("a") + text("b") + } + text("c") + } + + CommonmarkRenderer(context).render(page) + + assert(renderedContent == "//[testPage](test-page.md)\n\n\n\nab\n\nc") + } + + @Test + fun blockWrapped() { + val page = TestPage { + group(styles = setOf(TextStyle.Block)) { + text("a") + text("b") + } + text("c") + } + + CommonmarkRenderer(context).render(page) + + assert(renderedContent == "//[testPage](test-page.md)\n\nab \nc") + } + + @Test + fun nested() { + val page = TestPage { + group(styles = setOf(TextStyle.Block)) { + text("a") + group(styles = setOf(TextStyle.Block)) { + group(styles = setOf(TextStyle.Block)) { + text("b") + text("c") + } + } + text("d") + } + } + + CommonmarkRenderer(context).render(page) + +// renderedContent.match(Div("a", Div(Div("bc")), "d")) + assert(renderedContent == "//[testPage](test-page.md)\n\nabc \n \nd \n") + } + +} diff --git a/plugins/gfm/src/test/kotlin/renderers/gfm/SourceSetDependentHintTest.kt b/plugins/gfm/src/test/kotlin/renderers/gfm/SourceSetDependentHintTest.kt new file mode 100644 index 00000000..64664d4a --- /dev/null +++ b/plugins/gfm/src/test/kotlin/renderers/gfm/SourceSetDependentHintTest.kt @@ -0,0 +1,137 @@ +package renderers.gfm + +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.SourceRootImpl +import org.jetbrains.dokka.gfm.CommonmarkRenderer +import renderers.gfm.GfmRenderingOnlyTestBase +import org.jetbrains.dokka.pages.TextStyle +import org.junit.jupiter.api.Test +import renderers.TestPage +import renderers.defaultSourceSet + +class SourceSetDependentHintTest : GfmRenderingOnlyTestBase() { + + private val pl1 = defaultSourceSet.copy( + "root", + "pl1", + "pl1", + analysisPlatform = Platform.js, + sourceRoots = listOf(SourceRootImpl("pl1")) + ) + private val pl2 = defaultSourceSet.copy( + "root", + "pl2", + "pl2", + analysisPlatform = Platform.jvm, + sourceRoots = listOf(SourceRootImpl("pl1")) + ) + private val pl3 = defaultSourceSet.copy( + "root", + "pl3", + "pl3", + analysisPlatform = Platform.native, + sourceRoots = listOf(SourceRootImpl("pl1")) + ) + + @Test + fun platformIndependentCase() { + val page = TestPage { + sourceSetDependentHint(sourceSets = setOf(pl1, pl2, pl3), styles = setOf(TextStyle.Block)) { + text("a") + text("b") + text("c") + } + } + + CommonmarkRenderer(context).render(page) + assert(renderedContent == "//[testPage](test-page.md)\n\n [root/pl1, root/pl2, root/pl3] abc \n ") + } + + @Test + fun completelyDivergentCase() { + val page = TestPage { + sourceSetDependentHint(sourceSets = setOf(pl1, pl2, pl3), styles = setOf(TextStyle.Block)) { + text("a", sourceSets = setOf(pl1)) + text("b", sourceSets = setOf(pl2)) + text("c", sourceSets = setOf(pl3)) + } + } + + CommonmarkRenderer(context).render(page) + assert(renderedContent == "//[testPage](test-page.md)\n\n [root/pl1] a \n [root/pl2] b \n [root/pl3] c \n ") + } + + @Test + fun overlappingCase() { + val page = TestPage { + sourceSetDependentHint(sourceSets = setOf(pl1, pl2), styles = setOf(TextStyle.Block)) { + text("a", sourceSets = setOf(pl1)) + text("b", sourceSets = setOf(pl1, pl2)) + text("c", sourceSets = setOf(pl2)) + } + } + + CommonmarkRenderer(context).render(page) + assert(renderedContent == "//[testPage](test-page.md)\n\n [root/pl1] ab \n [root/pl2] bc \n ") + } + + @Test + fun caseThatCanBeSimplified() { + val page = TestPage { + sourceSetDependentHint(sourceSets = setOf(pl1, pl2), styles = setOf(TextStyle.Block)) { + text("a", sourceSets = setOf(pl1, pl2)) + text("b", sourceSets = setOf(pl1)) + text("b", sourceSets = setOf(pl2)) + } + } + + CommonmarkRenderer(context).render(page) + assert(renderedContent == "//[testPage](test-page.md)\n\n [root/pl1, root/pl2] ab \n ") + } + + @Test + fun caseWithGroupBreakingSimplification() { + val page = TestPage { + sourceSetDependentHint(sourceSets = setOf(pl1, pl2), styles = setOf(TextStyle.Block)) { + group(styles = setOf(TextStyle.Block)) { + text("a", sourceSets = setOf(pl1, pl2)) + text("b", sourceSets = setOf(pl1)) + } + text("b", sourceSets = setOf(pl2)) + } + } + + CommonmarkRenderer(context).render(page) + assert(renderedContent == "//[testPage](test-page.md)\n\n [root/pl1] ab \n \n [root/pl2] a \nb \n ") + } + + @Test + fun caseWithGroupNotBreakingSimplification() { + val page = TestPage { + sourceSetDependentHint(sourceSets = setOf(pl1, pl2)) { + group { + text("a", sourceSets = setOf(pl1, pl2)) + text("b", sourceSets = setOf(pl1)) + } + text("b", sourceSets = setOf(pl2)) + } + } + + CommonmarkRenderer(context).render(page) + assert(renderedContent == "//[testPage](test-page.md)\n\n [root/pl1, root/pl2] ab ") + } + + @Test + fun partiallyUnifiedCase() { + val page = TestPage { + sourceSetDependentHint(sourceSets = setOf(pl1, pl2, pl3), styles = setOf(TextStyle.Block)) { + text("a", sourceSets = setOf(pl1)) + text("a", sourceSets = setOf(pl2)) + text("b", sourceSets = setOf(pl3)) + } + } + + CommonmarkRenderer(context).render(page) + assert(renderedContent == "//[testPage](test-page.md)\n\n [root/pl1, root/pl2] a \n [root/pl3] b \n ") + } +}
\ No newline at end of file |