Commit 4228201736
Verified · cmc
internal/web/classes_test.go +7 −8
| @@ -9,10 +9,10 @@ import ( | ||
| 9 | 9 | ) |
| 10 | 10 | |
| 11 | 11 | // TestEveryTemplateClassHasARule fails on a class a template uses that |
| 12 | // no selector in style.css mentions. Class tokens containing template | |
| 13 | // actions ({{...}}) are composed at render time and skipped; their | |
| 14 | // prefixes (chip-, badge-, check-, lang-) are covered by the rules for | |
| 15 | // the concrete values. | |
| 12 | // no selector in style.css mentions. Template actions are removed before | |
| 13 | // matching, so a class composed at render time (chip-{{.State}}) | |
| 14 | // contributes only its literal part; the rules for the concrete values | |
| 15 | // cover the rest. | |
| 16 | 16 | func TestEveryTemplateClassHasARule(t *testing.T) { |
| 17 | 17 | css := string(StyleCSS) |
| 18 | 18 | // Every ".name" that appears in a selector position: outside braces. |
| @@ -62,6 +62,7 @@ func TestEveryTemplateClassHasARule(t *testing.T) { | ||
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | attrRe := regexp.MustCompile(`class="([^"]*)"`) |
| 65 | actionRe := regexp.MustCompile(`(?s)\{\{.*?\}\}`) | |
| 65 | 66 | missing := map[string][]string{} |
| 66 | 67 | entries, err := fs.ReadDir(templateFS, "templates") |
| 67 | 68 | if err != nil { |
| @@ -72,11 +73,9 @@ func TestEveryTemplateClassHasARule(t *testing.T) { | ||
| 72 | 73 | if err != nil { |
| 73 | 74 | t.Fatal(err) |
| 74 | 75 | } |
| 75 | for _, m := range attrRe.FindAllStringSubmatch(string(src), -1) { | |
| 76 | clean := actionRe.ReplaceAllString(string(src), " ") | |
| 77 | for _, m := range attrRe.FindAllStringSubmatch(clean, -1) { | |
| 76 | 78 | for _, c := range strings.Fields(m[1]) { |
| 77 | if strings.Contains(c, "{{") || strings.Contains(c, "}}") { | |
| 78 | continue | |
| 79 | } | |
| 80 | 79 | if !styled[c] { |
| 81 | 80 | missing[c] = append(missing[c], e.Name()) |
| 82 | 81 | } |