12345678910111213141516171819202122 | package render
import "testing"
func TestThemeSVG(t *testing.T) {
const style = `<style>:root{color:#fff}</style>`
cases := []struct{ name, svg, want string }{
{"plain", `<svg><rect/></svg>`, `<svg>` + style + `<rect/></svg>`},
{"prolog", `<?xml version="1.0"?><!-- c --><!DOCTYPE svg><svg a="1"><g/></svg>`,
`<?xml version="1.0"?><!-- c --><!DOCTYPE svg><svg a="1">` + style + `<g/></svg>`},
{"quoted gt", `<svg title="a>b" x='/'><g/></svg>`, `<svg title="a>b" x='/'>` + style + `<g/></svg>`},
{"multiline", "<svg\n viewBox=\"0 0 1 1\"\n><g/></svg>", "<svg\n viewBox=\"0 0 1 1\"\n>" + style + "<g/></svg>"},
{"empty", `<svg a="1"/>`, `<svg a="1"/>`},
{"other root", `<html><svg><g/></svg></html>`, `<html><svg><g/></svg></html>`},
{"unparsable", `<svg a=1><g/></svg>`, `<svg a=1><g/></svg>`},
}
for _, c := range cases {
if got := string(themeSVG([]byte(c.svg), svgRootEnd([]byte(c.svg)), "#fff", "")); got != c.want {
t.Errorf("%s: got %s, want %s", c.name, got, c.want)
}
}
}
|