diff options
author | Mike Sinkovsky <msink@users.noreply.github.com> | 2021-06-26 01:29:17 +0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-25 22:29:17 +0200 |
commit | 46b33710df5418fd3b668ea0753a8bd72f63c406 (patch) | |
tree | 4100d599be82488d78f6f27720bccec37e4ac397 /plugins/gfm/src/test | |
parent | c2182b766a65619c859c0fc871a8a6334d66f199 (diff) | |
download | dokka-46b33710df5418fd3b668ea0753a8bd72f63c406.tar.gz dokka-46b33710df5418fd3b668ea0753a8bd72f63c406.tar.bz2 dokka-46b33710df5418fd3b668ea0753a8bd72f63c406.zip |
Cleanup paragraphs and tables in GFM renderer (#1946)
* GFM renderer: cleanup paragraphs
* GFM renderer: cleanup tables
* GFM renderer: add tests for wrong header in table
Table with extra cell in row is really generated by `all-modules-page` plugin
* Remove commented-out lines
* Add BriefCommentPreprocessor which inserts a line break between a signature and a brief comment
Fixed a bug with `mapTransform` function which replaces table headers with their contents
Co-authored-by: Kamil Doległo <kamil.doleglo@interia.pl>
Diffstat (limited to 'plugins/gfm/src/test')
4 files changed, 274 insertions, 40 deletions
diff --git a/plugins/gfm/src/test/kotlin/renderers/gfm/DivergentTest.kt b/plugins/gfm/src/test/kotlin/renderers/gfm/DivergentTest.kt index d9ae5e99..ae1b4d7f 100644 --- a/plugins/gfm/src/test/kotlin/renderers/gfm/DivergentTest.kt +++ b/plugins/gfm/src/test/kotlin/renderers/gfm/DivergentTest.kt @@ -41,7 +41,11 @@ class DivergentTest : GfmRenderingOnlyTestBase() { } } } - val expect = "//[testPage](test-page.md)\n\n[js]\\\nContent\\\na" + val expect = """|//[testPage](test-page.md) + | + |[js]\ + |a""".trimMargin() + CommonmarkRenderer(context).render(page) assert(renderedContent == expect) } @@ -57,7 +61,11 @@ class DivergentTest : GfmRenderingOnlyTestBase() { } } } - val expect = "//[testPage](test-page.md)\n\n[js]\\\nContent\\\na" + val expect = """|//[testPage](test-page.md) + | + |[js]\ + |a""".trimMargin() + CommonmarkRenderer(context).render(page) assert(renderedContent == expect) } @@ -83,7 +91,18 @@ class DivergentTest : GfmRenderingOnlyTestBase() { } } } - val expect = "//[testPage](test-page.md)\n\n[js, jvm, native]\\\nContent\\\n[js]\\\na\\\n[jvm]\\\nb\\\n[native]\\\nc" + val expect = """|//[testPage](test-page.md) + | + |[js, jvm, native]\ + |[js]\ + |a + | + |[jvm]\ + |b + | + |[native]\ + |c""".trimMargin() + CommonmarkRenderer(context).render(page) assert(renderedContent == expect) } @@ -109,7 +128,15 @@ class DivergentTest : GfmRenderingOnlyTestBase() { } } } - val expect = "//[testPage](test-page.md)\n\n[js]\\\nContent\\\na\\\nb\\\nc" + val expect = """|//[testPage](test-page.md) + | + |[js]\ + |a + | + |b + | + |c""".trimMargin() + CommonmarkRenderer(context).render(page) assert(renderedContent == expect) } @@ -145,7 +172,24 @@ class DivergentTest : GfmRenderingOnlyTestBase() { } } } - val expect = "//[testPage](test-page.md)\n\n[native, js, jvm]\\\nContent\\\n[native]\\\na\\\n[js]\\\nb\\\n[jvm]\\\nc\\\n[js]\\\nd\\\n[native]\\\ne" + val expect = """|//[testPage](test-page.md) + | + |[native, js, jvm]\ + |[native]\ + |a + | + |[js]\ + |b + | + |[jvm]\ + |c + | + |[js]\ + |d + | + |[native]\ + |e""".trimMargin() + CommonmarkRenderer(context).render(page) assert(renderedContent == expect) } @@ -193,7 +237,28 @@ class DivergentTest : GfmRenderingOnlyTestBase() { } } } - val expect = "//[testPage](test-page.md)\n\n[native]\\\nContent\\\na\\\nMore info\\\na+\n\n[js]\\\nContent\\\nb\\\nd\\\nMore info\\\nbd+\n\n[jvm]\\\nContent\\\nc\n\n[native]\\\nContent\\\ne\\\nMore info\\\ne+" + val expect = """|//[testPage](test-page.md) + | + |[native]\ + |a + | + |a+ + | + |[js]\ + |b + | + |d + | + |bd+ + | + |[jvm]\ + |c + | + |[native]\ + |e + | + |e+""".trimMargin() + CommonmarkRenderer(context).render(page) assert(renderedContent == expect) } @@ -220,7 +285,15 @@ class DivergentTest : GfmRenderingOnlyTestBase() { } } } - val expect = "//[testPage](test-page.md)\n\n[native]\\\nBrief description\\\nab-\\\nContent\\\na\\\nb" + val expect = """|//[testPage](test-page.md) + | + |[native]\ + |ab- + | + |a + | + |b""".trimMargin() + CommonmarkRenderer(context).render(page) assert(renderedContent == expect) } @@ -247,7 +320,15 @@ class DivergentTest : GfmRenderingOnlyTestBase() { } } } - val expect = "//[testPage](test-page.md)\n\n[native]\\\nContent\\\na\\\nb\\\nMore info\\\nab+" + val expect = """|//[testPage](test-page.md) + | + |[native]\ + |a + | + |b + | + |ab+""".trimMargin() + CommonmarkRenderer(context).render(page) assert(renderedContent == expect) } @@ -280,7 +361,17 @@ class DivergentTest : GfmRenderingOnlyTestBase() { } } } - val expect = "//[testPage](test-page.md)\n\n[native]\\\nBrief description\\\nab-\\\nContent\\\na\\\nb\\\nMore info\\\nab+" + val expect = """|//[testPage](test-page.md) + | + |[native]\ + |ab- + | + |a + | + |b + | + |ab+""".trimMargin() + CommonmarkRenderer(context).render(page) assert(renderedContent == expect) } @@ -313,7 +404,22 @@ class DivergentTest : GfmRenderingOnlyTestBase() { } } } - val expect = "//[testPage](test-page.md)\n\n[native]\\\nBrief description\\\na-\\\nContent\\\na\\\nMore info\\\nab+\n\n[native]\\\nBrief description\\\nb-\\\nContent\\\nb\\\nMore info\\\nab+" + val expect = """|//[testPage](test-page.md) + | + |[native]\ + |a- + | + |a + | + |ab+ + | + |[native]\ + |b- + | + |b + | + |ab+""".trimMargin() + CommonmarkRenderer(context).render(page) assert(renderedContent == expect) } @@ -364,7 +470,30 @@ class DivergentTest : GfmRenderingOnlyTestBase() { } } } - val expect = "//[testPage](test-page.md)\n\n[native]\\\nContent\\\na\\\nMore info\\\na+\n\n[js, jvm]\\\nContent\\\n[js]\\\nb\\\n[jvm]\\\nc\\\n[js]\\\nd\\\nMore info\\\nbd+\n\n[native]\\\nContent\\\ne\\\nMore info\\\ne+" + val expect = """|//[testPage](test-page.md) + | + |[native]\ + |a + | + |a+ + | + |[js, jvm]\ + |[js]\ + |b + | + |[jvm]\ + |c + | + |[js]\ + |d + | + |bd+ + | + |[native]\ + |e + | + |e+""".trimMargin() + CommonmarkRenderer(context).render(page) assert(renderedContent == expect) } diff --git a/plugins/gfm/src/test/kotlin/renderers/gfm/GroupWrappingTest.kt b/plugins/gfm/src/test/kotlin/renderers/gfm/GroupWrappingTest.kt index 11105ebd..eafe3e13 100644 --- a/plugins/gfm/src/test/kotlin/renderers/gfm/GroupWrappingTest.kt +++ b/plugins/gfm/src/test/kotlin/renderers/gfm/GroupWrappingTest.kt @@ -16,10 +16,12 @@ class GroupWrappingTest : GfmRenderingOnlyTestBase() { } text("c") } + val expect = """|//[testPage](test-page.md) + | + |abc""".trimMargin() CommonmarkRenderer(context).render(page) - - assert(renderedContent == "//[testPage](test-page.md)\n\nabc") + assert(renderedContent == expect) } @Test @@ -31,10 +33,14 @@ class GroupWrappingTest : GfmRenderingOnlyTestBase() { } text("c") } + val expect = """|//[testPage](test-page.md) + | + |ab + | + |c""".trimMargin() CommonmarkRenderer(context).render(page) - - assert(renderedContent == "//[testPage](test-page.md)\n\nab\n\nc") + assert(renderedContent == expect) } @Test @@ -46,9 +52,14 @@ class GroupWrappingTest : GfmRenderingOnlyTestBase() { } text("c") } + val expect = """|//[testPage](test-page.md) + | + |ab + | + |c""".trimMargin() CommonmarkRenderer(context).render(page) - assert(renderedContent == "//[testPage](test-page.md)\n\nab\n\nc") + assert(renderedContent == expect) } @Test @@ -65,11 +76,15 @@ class GroupWrappingTest : GfmRenderingOnlyTestBase() { text("d") } } + val expect = """|//[testPage](test-page.md) + | + |a + | + |bc + | + |d""".trimMargin() CommonmarkRenderer(context).render(page) - -// renderedContent.match(Div("a", Div(Div("bc")), "d")) - assert(renderedContent == "//[testPage](test-page.md)\n\nabc\n\nd") + assert(renderedContent == expect) } - } diff --git a/plugins/gfm/src/test/kotlin/renderers/gfm/SimpleElementsTest.kt b/plugins/gfm/src/test/kotlin/renderers/gfm/SimpleElementsTest.kt index 1a28a9a8..ee156c7f 100644 --- a/plugins/gfm/src/test/kotlin/renderers/gfm/SimpleElementsTest.kt +++ b/plugins/gfm/src/test/kotlin/renderers/gfm/SimpleElementsTest.kt @@ -120,13 +120,12 @@ class SimpleElementsTest : GfmRenderingOnlyTestBase() { } } } - - val expect = """\//[testPage](test-page.md) - \ - \| Col1 | Col2 | Col3 | - \|---|---|---| - \| <a name="////PointingToDeclaration/"></a>Text1| <a name="////PointingToDeclaration/"></a>Text2| <a name="////PointingToDeclaration/"></a>Text3| - \| <a name="////PointingToDeclaration/"></a>Text4| <a name="////PointingToDeclaration/"></a>Text5| <a name="////PointingToDeclaration/"></a>Text6|""".trimMargin("\\") + val expect = """|//[testPage](test-page.md) + | + || Col1 | Col2 | Col3 | + ||---|---|---| + || Text1 | Text2 | Text3 | + || Text4 | Text5 | Text6 |""".trimMargin() CommonmarkRenderer(context).render(page) assertEquals(expect, renderedContent) @@ -148,15 +147,61 @@ class SimpleElementsTest : GfmRenderingOnlyTestBase() { } } } + val expect = """|//[testPage](test-page.md) + | + || | | | + ||---|---|---| + || Text1 | Text2 | Text3 | + || Text4 | Text5 | Text6 |""".trimMargin() + + CommonmarkRenderer(context).render(page) + assertEquals(expect, renderedContent) + } - val expect = """\//[testPage](test-page.md) - \ - \| | | | - \|---|---|---| - \| <a name="////PointingToDeclaration/"></a>Text1| <a name="////PointingToDeclaration/"></a>Text2| <a name="////PointingToDeclaration/"></a>Text3| - \| <a name="////PointingToDeclaration/"></a>Text4| <a name="////PointingToDeclaration/"></a>Text5| <a name="////PointingToDeclaration/"></a>Text6|""".trimMargin("\\") + @Test + fun `table with extra cell in row`() { + val page = testPage { + table { + header { + text("Col1") + } + row { + text("Text1") + text("Text2") + } + } + } + val expect = """|//[testPage](test-page.md) + | + || Col1 | + ||---| + || Text1 | Text2 |""".trimMargin() CommonmarkRenderer(context).render(page) assertEquals(expect, renderedContent) } + + @Test + fun `table with extra cell in header`() { + val page = testPage { + table { + header { + text("Col1") + text("Col2") + } + row { + text("Text1") + } + } + } + val expect = """|//[testPage](test-page.md) + | + || Col1 | Col2 | + ||---|---| + || Text1 |""".trimMargin() + + CommonmarkRenderer(context).render(page) + assertEquals(expect, renderedContent) + } + } diff --git a/plugins/gfm/src/test/kotlin/renderers/gfm/SourceSetDependentHintTest.kt b/plugins/gfm/src/test/kotlin/renderers/gfm/SourceSetDependentHintTest.kt index 254832de..dae9983a 100644 --- a/plugins/gfm/src/test/kotlin/renderers/gfm/SourceSetDependentHintTest.kt +++ b/plugins/gfm/src/test/kotlin/renderers/gfm/SourceSetDependentHintTest.kt @@ -39,9 +39,13 @@ class SourceSetDependentHintTest : GfmRenderingOnlyTestBase() { text("c") } } + val expect = """|//[testPage](test-page.md) + | + |[pl1, pl2, pl3]\ + |abc""".trimMargin() CommonmarkRenderer(context).render(page) - assert(renderedContent == "//[testPage](test-page.md)\n\n [pl1, pl2, pl3] abc") + assert(renderedContent == expect) } @Test @@ -53,9 +57,19 @@ class SourceSetDependentHintTest : GfmRenderingOnlyTestBase() { text("c", sourceSets = setOf(pl3)) } } + val expect = """|//[testPage](test-page.md) + | + |[pl1]\ + |a + | + |[pl2]\ + |b + | + |[pl3]\ + |c""".trimMargin() CommonmarkRenderer(context).render(page) - assert(renderedContent == "//[testPage](test-page.md)\n\n [pl1] a\n\n [pl2] b\n\n [pl3] c") + assert(renderedContent == expect) } @Test @@ -67,9 +81,16 @@ class SourceSetDependentHintTest : GfmRenderingOnlyTestBase() { text("c", sourceSets = setOf(pl2)) } } + val expect = """|//[testPage](test-page.md) + | + |[pl1]\ + |ab + | + |[pl2]\ + |bc""".trimMargin() CommonmarkRenderer(context).render(page) - assert(renderedContent == "//[testPage](test-page.md)\n\n [pl1] ab\n\n [pl2] bc") + assert(renderedContent == expect) } @Test @@ -81,9 +102,13 @@ class SourceSetDependentHintTest : GfmRenderingOnlyTestBase() { text("b", sourceSets = setOf(pl2)) } } + val expect = """|//[testPage](test-page.md) + | + |[pl1, pl2]\ + |ab""".trimMargin() CommonmarkRenderer(context).render(page) - assert(renderedContent == "//[testPage](test-page.md)\n\n [pl1, pl2] ab") + assert(renderedContent == expect) } @Test @@ -97,9 +122,18 @@ class SourceSetDependentHintTest : GfmRenderingOnlyTestBase() { text("b", sourceSets = setOf(pl2)) } } + val expect = """|//[testPage](test-page.md) + | + |[pl1]\ + |ab + | + |[pl2]\ + |a + | + |b""".trimMargin() CommonmarkRenderer(context).render(page) - assert(renderedContent == "//[testPage](test-page.md)\n\n [pl1] ab\n\n [pl2] a\n\nb") + assert(renderedContent == expect) } @Test @@ -113,9 +147,13 @@ class SourceSetDependentHintTest : GfmRenderingOnlyTestBase() { text("b", sourceSets = setOf(pl2)) } } + val expect = """|//[testPage](test-page.md) + | + |[pl1, pl2]\ + |ab""".trimMargin() CommonmarkRenderer(context).render(page) - assert(renderedContent == "//[testPage](test-page.md)\n\n [pl1, pl2] ab") + assert(renderedContent == expect) } @Test @@ -127,8 +165,15 @@ class SourceSetDependentHintTest : GfmRenderingOnlyTestBase() { text("b", sourceSets = setOf(pl3)) } } + val expect = """|//[testPage](test-page.md) + | + |[pl1, pl2]\ + |a + | + |[pl3]\ + |b""".trimMargin() CommonmarkRenderer(context).render(page) - assert(renderedContent == "//[testPage](test-page.md)\n\n [pl1, pl2] a\n\n [pl3] b") + assert(renderedContent == expect) } } |