Skip to content

Commit

Permalink
add tests for markdown markup in comments
Browse files Browse the repository at this point in the history
  • Loading branch information
i582 committed Oct 17, 2024
1 parent 896757f commit 1848c59
Showing 1 changed file with 55 additions and 4 deletions.
59 changes: 55 additions & 4 deletions src/test/kotlin/org/move/ide/docs/MoveDocumentationProviderTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class MvDocumentationProviderTest : MvDocumentationProviderTestCase() {
""", expected = """
<div class='definition'><pre>0x0::builtins
native fun <b>move_from</b>&lt;T: key&gt;(addr: address): T</pre></div>
<div class='content'><p>Removes `T` from address and returns it. </p>
<p>Aborts if address does not hold a `T`.</p></div>
<div class='content'><p>Removes <code>T</code> from address and returns it.
Aborts if address does not hold a <code>T</code>.</p></div>
""")

fun `test show doc comment for module`() = doTest("""
Expand Down Expand Up @@ -52,8 +52,7 @@ class MvDocumentationProviderTest : MvDocumentationProviderTestCase() {
""", expected = """
<div class='definition'><pre>0x1::M
fun <b>add</b>(a: u8, b: u8): u8</pre></div>
<div class='content'><p>Adds two numbers.</p>
<p>Returns their sum.</p></div>
<div class='content'><p>Adds two numbers.</p><p>Returns their sum.</p></div>
""")

fun `test show signature for function parameter`() = doTest("""
Expand Down Expand Up @@ -164,6 +163,58 @@ module 0x1::m {
value parameter <b>result</b>: &mut T
""")

fun `test markdown text styles`() = doTest("""
/// This string contains some *bold* and **italic** words.
module 0x1::M {}
//^
""", """
<div class='definition'><pre>module 0x1::M</pre></div>
<div class='content'><p>This string contains some <em>bold</em> and <strong>italic</strong> words.</p></div>
""")

fun `test markdown inline code`() = doTest("""
/// Maybe some `inline` keyword
module 0x1::M {}
//^
""", """
<div class='definition'><pre>module 0x1::M</pre></div>
<div class='content'><p>Maybe some <code>inline</code> keyword</p></div>
""")

fun `test markdown multiline code`() = doTest("""
/// Move code:
/// ```
/// module 0x1::M {}
/// ```
module 0x1::M {}
//^
""", """
<div class='definition'><pre>module 0x1::M</pre></div>
<div class='content'><p>Move code:</p><pre style="text-indent: 10px; margin-bottom: -20px;"><span style="color: #000080; font-weight: bold;">module </span><span style="color: #000000;">0x1::M {}</span>
</pre>
</div>
""")

fun `test markdown list`() = doTest("""
/// - The number of "items" in global storage.
/// - The number of bytes in global storage.
module 0x1::M {}
//^
""", """
<div class='definition'><pre>module 0x1::M</pre></div>
<div class='content'><ul><li>The number of &quot;items&quot; in global storage.</li><li>The number of bytes in global storage.</li></ul></div>
""")

fun `test markdown numbered list`() = doTest("""
/// 1. The number of "items" in global storage.
/// 2. The number of bytes in global storage.
module 0x1::M {}
//^
""", """
<div class='definition'><pre>module 0x1::M</pre></div>
<div class='content'><ol><li>The number of &quot;items&quot; in global storage.</li><li>The number of bytes in global storage.</li></ol></div>
""")

private fun doTest(@Language("Move") code: String, @Language("Html") expected: String?) =
doTest(code, expected, block = MvDocumentationProvider::generateDoc)
}

0 comments on commit 1848c59

Please sign in to comment.