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