showcase
- v0.2.4
- 37 commits
- 1 branch
- 6 tags
- updated
- CI 2/2
icons_test.go
1.9 KB · 54 lines
1package render23import (4 "regexp"5 "strings"6 "testing"7)89// Icons reuse ids ("a", "folder"), so each symbol's ids carry its own prefix.10func TestSymbolIDsArePrefixed(t *testing.T) {11 syms, err := loadSymbols()12 if err != nil {13 t.Fatal(err)14 }15 for id, want := range map[string]string{16 "f-kotlin": `fill="url(#xf-kotlin-a)"`,17 "f-folder-css": `href="#xf-folder-css-a"`,18 } {19 if s := string(syms[id]); !strings.Contains(s, want) || !strings.Contains(s, `id="xf-`+id[2:]+`-a"`) {20 t.Errorf("%s: ids not prefixed: %.200s", id, s)21 }22 }23 // a root fill="none" keeps hiding the icon's background square24 for _, id := range []string{"f-document", "f-readme", "f-changelog", "f-log", "f-settings", "f-just"} {25 if !strings.HasPrefix(string(syms[id]), `<symbol id="`+id+`" viewBox="0 0 `) || !strings.Contains(string(syms[id][:60]), `fill="none"`) {26 t.Errorf("%s lost its root fill: %.80s", id, syms[id])27 }28 }29 bare := regexp.MustCompile(`id="[^x]|href="#[^x]|url\(#[^x]`)30 for id, s := range syms {31 if m := bare.Find(s[len(`<symbol id="`):]); m != nil {32 t.Errorf("%s has an unprefixed reference %s", id, m)33 }34 if strings.Contains(string(s), "style=") {35 t.Errorf("%s has an inline style, which the CSP blocks", id)36 }37 }38}3940func TestFileIcon(t *testing.T) {41 for name, want := range map[string]string{42 "main.go": "go", "go.mod": "go-mod", "README.md": "readme", "README.MD": "readme",43 "Dockerfile": "docker", "justfile": "just", "a.test.weird.ts": "typescript", "noext": "file",44 } {45 if got := string(fileIcon(name, "blob")); !strings.Contains(got, `#f-`+want+`"`) {46 t.Errorf("%s: got %s, want f-%s", name, got, want)47 }48 }49 for typ, want := range map[string]string{"tree": "folder-docs", "tree-open": "folder-open", "commit": "folder-docs"} {50 if got := string(fileIcon("docs", typ)); !strings.Contains(got, `#f-`+want+`"`) {51 t.Errorf("docs as %s: got %s, want f-%s", typ, got, want)52 }53 }54}