package main import ( "os" "path/filepath" "testing" ) func TestCheckTemplColorsFlagsHardcodedColorsAndInlineStyles(t *testing.T) { root := t.TempDir() file := filepath.Join(root, "sample.templ") content := `package sample templ Example() {
} ` if err := os.WriteFile(file, []byte(content), 0644); err != nil { t.Fatalf("write sample templ: %v", err) } violations := checkTemplColors(root) if len(violations) < 5 { t.Fatalf("checkTemplColors() returned %d violations, want at least 5: %#v", len(violations), violations) } rules := map[string]bool{} for _, violation := range violations { rules[violation.rule] = true } for _, rule := range []string{ "no-hardcoded-tw-color", "no-hex-in-class", "no-tw-arbitrary-hex", "no-inline-hex-style", "no-inline-rgb-style", } { if !rules[rule] { t.Fatalf("missing rule %q in violations: %#v", rule, violations) } } } func TestCheckTemplColorsAllowsSemanticTokensAndCSSVariables(t *testing.T) { root := t.TempDir() file := filepath.Join(root, "sample.templ") content := `package sample templ Example() { } ` if err := os.WriteFile(file, []byte(content), 0644); err != nil { t.Fatalf("write sample templ: %v", err) } violations := checkTemplColors(root) if len(violations) != 0 { t.Fatalf("checkTemplColors() returned %d violations, want 0: %#v", len(violations), violations) } } func TestCheckNinjaTplColorsFlagsHardcodedColors(t *testing.T) { root := t.TempDir() tplDir := filepath.Join(root, "templates", "blocks") if err := os.MkdirAll(tplDir, 0755); err != nil { t.Fatalf("mkdir: %v", err) } file := filepath.Join(tplDir, "hero.ninjatpl") content := `{{ subtext }}
{{ primary_cta }}{{ subtext }}
{{ cta }}