1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
package tui
import (
"testing"
"github.com/grindlemire/go-tui/internal/markdown"
)
type fakeHighlighter struct{ lines [][]TextSpan }
func (f fakeHighlighter) Highlight(lang, code string) [][]TextSpan { return f.lines }
func TestRenderCodeFenceMismatchedLineCount(t *testing.T) {
th := DefaultMarkdownTheme()
th.CodeHighlighter = fakeHighlighter{lines: [][]TextSpan{
{{Text: "one"}},
}}
m := NewMarkdown(WithMarkdownSource(""), WithMarkdownTheme(th))
block := markdown.Block{Kind: markdown.KindCodeFence, Lang: "go", Lines: []string{"one", "two", "three"}}
box := m.renderCodeFence(block)
inner := box.children[0]
if len(inner.children) != 3 {
t.Fatalf("want 3 line elements, got %d", len(inner.children))
}
if len(inner.children[0].RichText()) == 0 {
t.Error("line 0 should have rich-text spans")
}
if len(inner.children[2].RichText()) != 0 {
t.Error("line 2 should fall back to plain text")
}
}
|