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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
package preview
import (
"strings"
"testing"
)
var testColors = Colors{
Background: "#100F0F", Text: "#CECDC3", Heading: "#D14D41", Code: "#879A39", Link: "#4385BE",
}
func renderPreview(t *testing.T, md string) string {
t.Helper()
m := New("dark")
m.SetColors(testColors)
m.SetSize(40, 20)
if err := m.Render(md); err != nil {
t.Fatal(err)
}
return m.View()
}
// H1 text must sit on the heading background, not the paper background.
func TestH1BackgroundBehindText(t *testing.T) {
out := renderPreview(t, "# glint\n")
if !strings.Contains(out, "48;2;209;77;65") {
t.Fatalf("H1 missing heading background (209;77;65):\n%q", out)
}
// the word "glint" itself must carry the heading bg, not paper (16;15;15)
if !strings.Contains(out, "48;2;209;77;65;1mglint") {
t.Fatalf("H1 text not painted on heading background:\n%q", out)
}
}
// Every ANSI reset must be followed by a re-assert of the paper background so
// unstyled regions (table borders, cell padding) never fall back to the
// terminal default โ the table-background-between-themes bug.
func TestPaperBackgroundReassertedAfterResets(t *testing.T) {
out := renderPreview(t, "| Key | Action |\n| --- | --- |\n| `Tab` | indent |\n")
paper := "\x1b[48;2;16;15;15m"
resets := strings.Count(out, "\x1b[0m")
reasserted := strings.Count(out, "\x1b[0m"+paper)
if resets == 0 {
t.Fatal("expected some resets in table output")
}
if resets != reasserted {
t.Fatalf("bare resets remain: %d resets, %d re-asserted paper bg", resets, reasserted)
}
}
|