diff --git a/utils/utils.go b/utils/utils.go index 9f33a1e..205467d 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -101,7 +101,7 @@ func GlamourStyle(style string, isCode bool) glamour.TermRendererOption { case styles.DraculaStyle: styleConfig = styles.DraculaStyleConfig case styles.TokyoNightStyle: - styleConfig = styles.DraculaStyleConfig + styleConfig = styles.TokyoNightStyleConfig default: return glamour.WithStylesFromJSONFile(style) } diff --git a/utils/utils_test.go b/utils/utils_test.go new file mode 100644 index 0000000..6e688f6 --- /dev/null +++ b/utils/utils_test.go @@ -0,0 +1,36 @@ +package utils + +import ( + "testing" + + "github.com/charmbracelet/glamour" + "github.com/charmbracelet/glamour/styles" +) + +// renderCode renders a fenced code block with the given style in code mode. +func renderCode(t *testing.T, style string) string { + t.Helper() + r, err := glamour.NewTermRenderer(GlamourStyle(style, true)) + if err != nil { + t.Fatalf("new renderer for %q: %v", style, err) + } + out, err := r.Render("```go\nfmt.Println(\"hello\")\n```\n") + if err != nil { + t.Fatalf("render with %q: %v", style, err) + } + return out +} + +// TestGlamourStyleTokyoNightCodeDistinctFromDracula guards against the +// tokyo-night code style being mapped to the dracula StyleConfig. The two +// themes use different colors, so their rendered code output must differ. +func TestGlamourStyleTokyoNightCodeDistinctFromDracula(t *testing.T) { + t.Setenv("CLICOLOR_FORCE", "1") // force ANSI color so styles are distinguishable + + tokyo := renderCode(t, styles.TokyoNightStyle) + dracula := renderCode(t, styles.DraculaStyle) + + if tokyo == dracula { + t.Errorf("tokyo-night code rendering is identical to dracula; GlamourStyle must use TokyoNightStyleConfig") + } +}