Artifact e386504fa3752e88ac60c6f5fa11adfda39eb5d69cb468c2a506c356d9488433:
- File
internal/highlight/highlight_test.go
— part of check-in
[689d0692d7]
at
2026-08-15 12:16:01
on branch trunk
— highlight: chroma wrapper, fenced-code + file-view highlighting
Cleanroom (their wrapper is settings-coupled); classes only, both themes in one stylesheet; sanitizer learns chroma token classes. (user: dmestas, size: 1091) [annotate] [blame] [check-ins using]
package highlight import ( "strings" "testing" ) func TestCodeByFilename(t *testing.T) { out, ok := Code([]byte("package main\n"), "", "src/main.go") if !ok { t.Fatal("go file not highlighted") } if !strings.Contains(out, "<span class=") || !strings.Contains(out, "package") { t.Fatalf("no classed spans:\n%s", out) } if strings.Contains(out, "style=") { t.Fatalf("inline styles leak into output (classes only):\n%s", out) } } func TestCodeByLanguage(t *testing.T) { if _, ok := Code([]byte("SELECT 1;\n"), "sql", ""); !ok { t.Fatal("language hint not used") } } func TestCodeNoLexer(t *testing.T) { // Pure binary-ish content with no filename or language: callers get // ok=false and fall back to escaped <pre>. if out, ok := Code([]byte{0x00, 0x01, 0x02}, "", "data.zzzunknown"); ok { t.Fatalf("unexpected lexer match:\n%s", out) } } func TestCSSHasBothThemes(t *testing.T) { css := CSS() if !strings.Contains(css, ".chroma") { t.Fatal("no chroma rules") } if !strings.Contains(css, "prefers-color-scheme: dark") { t.Fatal("no dark theme block") } }