|
| 1 | +package com.quarkdown.test |
| 2 | + |
| 3 | +import com.quarkdown.core.ast.attributes.presence.hasCode |
| 4 | +import com.quarkdown.test.util.execute |
| 5 | +import kotlin.test.Test |
| 6 | +import kotlin.test.assertEquals |
| 7 | +import kotlin.test.assertFalse |
| 8 | +import kotlin.test.assertTrue |
| 9 | + |
| 10 | +/** |
| 11 | + * Tests for code blocks and inline code. |
| 12 | + */ |
| 13 | +class CodeTest { |
| 14 | + @Test |
| 15 | + fun inline() { |
| 16 | + execute("`println(\"Hello, world!\")`") { |
| 17 | + assertEquals( |
| 18 | + "<p><span class=\"codespan-content\"><code>println("Hello, world!")</code></span></p>", |
| 19 | + it, |
| 20 | + ) |
| 21 | + assertFalse(attributes.hasCode) |
| 22 | + } |
| 23 | + } |
| 24 | + |
| 25 | + @Test |
| 26 | + fun `hex color preview`() { |
| 27 | + execute("`#FF0000`") { |
| 28 | + assertEquals( |
| 29 | + "<p>" + |
| 30 | + "<span class=\"codespan-content\">" + |
| 31 | + "<code>#FF0000</code>" + |
| 32 | + "<span style=\"background-color: rgba(255, 0, 0, 1.0);\" class=\"color-preview\"></span>" + |
| 33 | + "</span>" + |
| 34 | + "</p>", |
| 35 | + it, |
| 36 | + ) |
| 37 | + assertFalse(attributes.hasCode) |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + fun `rgb color preview`() { |
| 43 | + execute("`rgba(200, 100, 50, 0.5)`") { |
| 44 | + assertEquals( |
| 45 | + "<p>" + |
| 46 | + "<span class=\"codespan-content\">" + |
| 47 | + "<code>rgba(200, 100, 50, 0.5)</code>" + |
| 48 | + "<span style=\"background-color: rgba(200, 100, 50, 0.5);\" class=\"color-preview\"></span>" + |
| 49 | + "</span>" + |
| 50 | + "</p>", |
| 51 | + it, |
| 52 | + ) |
| 53 | + assertFalse(attributes.hasCode) |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + @Test |
| 58 | + fun block() { |
| 59 | + execute("```\nprintln(\"Hello, world!\")\n```") { |
| 60 | + assertEquals("<pre><code>println("Hello, world!")</code></pre>", it) |
| 61 | + assertTrue(attributes.hasCode) |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + @Test |
| 66 | + fun `block with language`() { |
| 67 | + execute("```kotlin\nprintln(\"Hello, world!\")\n```") { |
| 68 | + assertEquals("<pre><code class=\"language-kotlin\">println("Hello, world!")</code></pre>", it) |
| 69 | + assertTrue(attributes.hasCode) |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + @Test |
| 74 | + fun `block with language and indentation`() { |
| 75 | + execute("```kotlin\nfun hello() {\n println(\"Hello, world!\")\n}\n```") { |
| 76 | + assertEquals( |
| 77 | + "<pre><code class=\"language-kotlin\">fun hello() {\n println("Hello, world!")\n}</code></pre>", |
| 78 | + it, |
| 79 | + ) |
| 80 | + assertTrue(attributes.hasCode) |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + // #32 |
| 85 | + @Test |
| 86 | + fun `long block`() { |
| 87 | + execute( |
| 88 | + """ |
| 89 | + ```nohighlight |
| 90 | + 1/1 file.ext - this_is_a_very_long_function_name_indeed() |
| 91 | + 59/59 file.ext - this_is_a_very_long_function_name_indeed() |
| 92 | + 11/11 file.ext - this_is_a_very_long_function_name_indeed() |
| 93 | + 11/11 file.ext - this_is_a_very_long_function_name_indeed() |
| 94 | + 11/11 file.ext - this_is_a_very_long_function_name_indeed() |
| 95 | + 15/15 file.ext - this_is_a_very_long_function_name_indeed() |
| 96 | + 4/4 file.ext - this_is_a_very_long_function_name_indeed() |
| 97 | + 13/13 file.ext - this_is_a_very_long_function_name_indeed() |
| 98 | + 14/14 file.ext - this_is_a_very_long_function_name_indeed() |
| 99 | + 4/4 file.ext - this_is_a_very_long_function_name_indeed() |
| 100 | + 15/15 file.ext - this_is_a_very_long_function_name_indeed() |
| 101 | + 19/19 file.ext - this_is_a_very_long_function_name_indeed() |
| 102 | + 12/12 file.ext - this_is_a_very_long_function_name_indeed() |
| 103 | + 4/4 file.ext - this_is_a_very_long_function_name_indeed() |
| 104 | + 14/14 file.ext - this_is_a_very_long_function_name_indeed() |
| 105 | + 2/2 file.ext - this_is_a_very_long_function_name_indeed() |
| 106 | + 8/8 file.ext - this_is_a_very_long_function_name_indeed() |
| 107 | + 13/13 file.ext - this_is_a_very_long_function_name_indeed() |
| 108 | + 4/4 file.ext - this_is_a_very_long_function_name_indeed() |
| 109 | + 16/16 file.ext - this_is_a_very_long_function_name_indeed() |
| 110 | + *** 19/21 file.ext - this_is_a_very_long_function_name_indeed() |
| 111 | + 2/2 file.ext - this_is_a_very_long_function_name_indeed() |
| 112 | + 2/2 file.ext - this_is_a_very_long_function_name_indeed() |
| 113 | + 2/2 file.ext - this_is_a_very_long_function_name_indeed() |
| 114 | + 2/2 file.ext - this_is_a_very_long_function_name_indeed() |
| 115 | + 2/2 file.ext - this_is_a_very_long_function_name_indeed() |
| 116 | + 2/2 file.ext - this_is_a_very_long_function_name_indeed() |
| 117 | + 16/16 file.ext - this_is_a_very_long_function_name_indeed() |
| 118 | + *** 23/25 file.ext - this_is_a_very_long_function_name_indeed() |
| 119 | + 1/1 file.ext - this_is_a_very_long_function_name_indeed() |
| 120 | + 1/1 file.ext - this_is_a_very_long_function_name_indeed() |
| 121 | + 7/7 file.ext - this_is_a_very_long_function_name_indeed() |
| 122 | + 3/3 file.ext - this_is_a_very_long_function_name_indeed() |
| 123 | + *** 81/82 file_1.ext - this_is_a_very_long_function_name_indeed() |
| 124 | + *** 0/87 file_1.ext - this_is_a_very_long_function_name_indeed() |
| 125 | + ``` |
| 126 | + """.trimIndent(), |
| 127 | + ) { |
| 128 | + assertTrue(it.startsWith("<pre><code class=\"language-nohighlight\">")) |
| 129 | + assertTrue(it.endsWith("</code></pre>")) |
| 130 | + assertEquals(35, it.lines().size) |
| 131 | + } |
| 132 | + } |
| 133 | +} |
0 commit comments