MCPcopy Create free account
hub / github.com/coder/coder / TestSVGIconAttributes

Function TestSVGIconAttributes

scripts/gensite/generate_icon_list_test.go:17–57  ·  view source on GitHub ↗

TestSVGIconAttributes validates that all SVG icons have the required attributes: width="256", height="256", and viewBox="0 0 256 256".

(t *testing.T)

Source from the content-addressed store, hash-verified

15// TestSVGIconAttributes validates that all SVG icons have the required
16// attributes: width="256", height="256", and viewBox="0 0 256 256".
17func TestSVGIconAttributes(t *testing.T) {
18 t.Parallel()
19
20 _, testFile, _, ok := runtime.Caller(0)
21 require.True(t, ok, "failed to get test file location")
22 testDir := filepath.Dir(testFile)
23 repoRoot := filepath.Join(testDir, "..", "..")
24 iconDir := filepath.Join(repoRoot, "site", "static", "icon")
25
26 files, err := os.ReadDir(iconDir)
27 require.NoError(t, err, "failed to read icon directory")
28
29 for _, file := range files {
30 if !file.Type().IsRegular() {
31 continue
32 }
33
34 fileName := file.Name()
35 if !strings.HasSuffix(fileName, ".svg") {
36 continue
37 }
38
39 t.Run(fileName, func(t *testing.T) {
40 t.Parallel()
41 filePath := filepath.Join(iconDir, fileName)
42
43 content, err := os.ReadFile(filePath)
44 require.NoError(t, err, "failed to read SVG file")
45
46 attrs, err := parseSVGAttributes(string(content))
47 require.NoError(t, err, "failed to parse SVG")
48
49 require.Equal(t, "256", attrs["width"],
50 "SVG must have width=\"256\"")
51 require.Equal(t, "256", attrs["height"],
52 "SVG must have height=\"256\"")
53 require.Equal(t, "0 0 256 256", attrs["viewBox"],
54 "SVG must have viewBox=\"0 0 256 256\"")
55 })
56 }
57}
58
59// parseSVGAttributes parses the root SVG element and returns its attributes.
60func parseSVGAttributes(content string) (map[string]string, error) {

Callers

nothing calls this directly

Calls 7

parseSVGAttributesFunction · 0.85
ReadDirMethod · 0.80
TypeMethod · 0.65
NameMethod · 0.65
RunMethod · 0.65
ReadFileMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected