Skip to content
quarry Artifact [e386504fa3]
Login

Artifact [e386504fa3]

Artifact e386504fa3752e88ac60c6f5fa11adfda39eb5d69cb468c2a506c356d9488433:


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