-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
cocoa-core/src/test/kotlin/cc/unitmesh/cf/core/parser/MarkdownCodeTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package cc.unitmesh.cf.core.parser; | ||
|
||
import org.junit.jupiter.api.Test | ||
import kotlin.test.assertEquals | ||
|
||
class MarkdownCodeTest { | ||
|
||
@Test | ||
fun should_parseMarkdownCode_when_validContentProvided() { | ||
// given | ||
val content = """ | ||
```kotlin | ||
val message = "Hello, World!" | ||
println(message) | ||
``` | ||
""".trimIndent() | ||
|
||
// when | ||
val markdownCode = MarkdownCode.parse(content) | ||
|
||
// then | ||
assertEquals("kotlin", markdownCode.language) | ||
assertEquals("val message = \"Hello, World!\"\nprintln(message)", markdownCode.text) | ||
} | ||
|
||
@Test | ||
fun should_parseMarkdownCode_withEmptyLanguage_when_noLanguageSpecified() { | ||
// given | ||
val content = """ | ||
``` | ||
val message = "Hello, World!" | ||
println(message) | ||
``` | ||
""".trimIndent() | ||
|
||
// when | ||
val markdownCode = MarkdownCode.parse(content) | ||
|
||
// then | ||
assertEquals("", markdownCode.language) | ||
assertEquals("val message = \"Hello, World!\"\nprintln(message)", markdownCode.text) | ||
} | ||
|
||
@Test | ||
fun should_parseMarkdownCode_withIncompleteCode_when_codeNotClosed() { | ||
// given | ||
val content = """ | ||
```kotlin | ||
val message = "Hello, World!" | ||
println(message) | ||
""".trimIndent() | ||
|
||
// when | ||
val markdownCode = MarkdownCode.parse(content) | ||
|
||
// then | ||
assertEquals("kotlin", markdownCode.language) | ||
assertEquals("val message = \"Hello, World!\"\nprintln(message)\n", markdownCode.text) | ||
assertEquals(false, markdownCode.isComplete) | ||
} | ||
|
||
@Test | ||
fun should_parseMarkdownCode_withTrimmedCode_when_codeHasLeadingAndTrailingWhitespace() { | ||
// given | ||
val content = """ | ||
```kotlin | ||
val message = "Hello, World!" | ||
println(message) | ||
``` | ||
""".trimIndent() | ||
|
||
// when | ||
val markdownCode = MarkdownCode.parse(content) | ||
|
||
// then | ||
assertEquals("kotlin", markdownCode.language) | ||
assertEquals("val message = \"Hello, World!\"\nprintln(message)", markdownCode.text) | ||
} | ||
|
||
@Test | ||
fun should_parseMarkdownCode_withTrimmedCode_when_codeHasLeadingAndTrailingWhitespaceAndNewLine() { | ||
// given | ||
val content = """ | ||
val message = "Hello, World!" | ||
println(message) | ||
""".trimIndent() | ||
|
||
// when | ||
val markdownCode = MarkdownCode.parse(content) | ||
|
||
// then | ||
assertEquals("", markdownCode.language) | ||
assertEquals("val message = \"Hello, World!\"\nprintln(message)", markdownCode.text) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters