package base import ( "regexp" "testing" "amadan.net/oficina/estilo.git/internal/tokencheck" ) func TestBaseUsesDefinedTokens(t *testing.T) { missing, n := tokencheck.Undefined(CSS()) if n == 0 { t.Fatal("base.css reads no rastrillo token; the check would pass vacuously") } if len(missing) > 0 { t.Fatal("base.css reads undefined tokens:", missing) } } // Every selector in base.css must be wrapped in :where(), so that it has // zero specificity and cannot outrank a component's own link colour. // A bare "a { color }" here would repaint every menu item, row title and // button in the suite. func TestBaseRulesHaveZeroSpecificity(t *testing.T) { src := regexp.MustCompile(`(?s)/\*.*?\*/`).ReplaceAll(CSS(), nil) selectors := regexp.MustCompile(`(?m)^([^{}]+)\{`).FindAllSubmatch(src, -1) if len(selectors) == 0 { t.Fatal("no rules found in base.css") } for _, m := range selectors { sel := string(m[1]) if !regexp.MustCompile(`^\s*:where\([^)]*\)\s*$`).MatchString(sel) { t.Errorf("selector %q is not a bare :where(...) and has specificity", sel) } } }