oficina / estilo Public

Clone
git clone https://amadan.net/oficina/estilo

Plain git — no account needed to clone.

Download

Download this file

1package base
2
3import (
4 "regexp"
5 "testing"
6
7 "amadan.net/oficina/estilo.git/internal/tokencheck"
8)
9
10func TestBaseUsesDefinedTokens(t *testing.T) {
11 missing, n := tokencheck.Undefined(CSS())
12 if n == 0 {
13 t.Fatal("base.css reads no rastrillo token; the check would pass vacuously")
14 }
15 if len(missing) > 0 {
16 t.Fatal("base.css reads undefined tokens:", missing)
17 }
18}
19
20// Every selector in base.css must be wrapped in :where(), so that it has
21// zero specificity and cannot outrank a component's own link colour.
22// A bare "a { color }" here would repaint every menu item, row title and
23// button in the suite.
24func TestBaseRulesHaveZeroSpecificity(t *testing.T) {
25 src := regexp.MustCompile(`(?s)/\*.*?\*/`).ReplaceAll(CSS(), nil)
26 selectors := regexp.MustCompile(`(?m)^([^{}]+)\{`).FindAllSubmatch(src, -1)
27 if len(selectors) == 0 {
28 t.Fatal("no rules found in base.css")
29 }
30 for _, m := range selectors {
31 sel := string(m[1])
32 if !regexp.MustCompile(`^\s*:where\([^)]*\)\s*$`).MatchString(sel) {
33 t.Errorf("selector %q is not a bare :where(...) and has specificity", sel)
34 }
35 }
36}
37