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) } }