1package soy.iko.opencode.ui.components
3import org.junit.Assert.assertEquals
6class ExtractCodeTextTest {
9 fun fencedCodeStripsOpeningAndClosingFence() {
10 val raw = "```kotlin\nfun main() {}\n```"
11 assertEquals("fun main() {}", extractCodeText(raw, isFenced = true))
15 fun fencedCodeWithTildeFenceStripped() {
16 val raw = "~~~python\nprint('hi')\n~~~"
17 assertEquals("print('hi')", extractCodeText(raw, isFenced = true))
21 fun fencedCodePreservesBlankLines() {
22 val raw = "```text\nline1\n\nline3\n```"
23 assertEquals("line1\n\nline3", extractCodeText(raw, isFenced = true))
27 fun fencedCodeWithoutClosingFence() {
28 // A streaming code block may not have a closing fence yet.
29 val raw = "```kotlin\nfun main() {}"
30 assertEquals("fun main() {}", extractCodeText(raw, isFenced = true))
34 fun fencedEmptyBody() {
35 val raw = "```kotlin\n```"
36 assertEquals("", extractCodeText(raw, isFenced = true))
40 fun fencedMultilineCode() {
41 val raw = "```js\nconst a = 1;\nconst b = 2;\n```"
42 assertEquals("const a = 1;\nconst b = 2;", extractCodeText(raw, isFenced = true))
46 fun indentedCodeTrimIndent() {
47 val raw = " fun main() {\n println()\n }"
48 assertEquals("fun main() {\n println()\n}", extractCodeText(raw, isFenced = false))
52 fun indentedCodeNoIndent() {
53 val raw = "code without indent"
54 assertEquals("code without indent", extractCodeText(raw, isFenced = false))
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list