oficina / home Public

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

Plain git — no account needed to clone.

Download

Download this file

1package home
2
3import (
4 "os"
5 "path/filepath"
6 "regexp"
7 "strings"
8 "testing"
9)
10
11func TestTemplateComponentSpelling(t *testing.T) {
12 allowed := map[string]bool{"rst-sr-only": true, "rst-mono": true, "rst-m-hide": true, "rst-grow": true, "rst-nm": true, "rst-danger": true, "rst-cell-mut": true}
13 classes := regexp.MustCompile(`(?i)(?:^|\s)class\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))`)
14 paths, err := filepath.Glob("templates/*.html")
15 if err != nil || len(paths) == 0 {
16 t.Fatalf("template enumeration: %v", err)
17 }
18 for _, path := range paths {
19 data, err := os.ReadFile(path)
20 if err != nil {
21 t.Fatal(err)
22 }
23 for _, match := range classes.FindAllStringSubmatch(string(data), -1) {
24 for _, value := range match[1:] {
25 for _, class := range strings.Fields(value) {
26 if strings.HasPrefix(class, "rst-") && !allowed[class] {
27 t.Errorf("%s: component class %q must use attribute spelling", path, class)
28 }
29 }
30 }
31 }
32 }
33}
34