MCPcopy
hub / github.com/tdewolff/minify / TestHTMLGoTemplates

Function TestHTMLGoTemplates

html/html_test.go:370–408  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

368}
369
370func TestHTMLGoTemplates(t *testing.T) {
371 htmlTests := []struct {
372 html string
373 expected string
374 }{
375 {`<a href={{ .Link }} />`, `<a href={{ .Link }}>`},
376 {`<input type="file" accept="{{ .Accept }}, image/jpeg">`, `<input type=file accept="{{ .Accept }}, image/jpeg">`},
377 {`<option value="0" {{ if eq .Type 0 }}selected{{ end }}>Foo</option>`, `<option value=0 {{ if eq .Type 0 }}selected{{ end }}>Foo`},
378 {`<style>a { color: {{.Color}} }</style>`, `<style>a { color: {{.Color}} }</style>`},
379 {`<div style=" color: {{.Color}} ">`, `<div style=" color: {{.Color}} ">`},
380 {`<script>alert( {{.Alert}} )</script>`, `<script>alert( {{.Alert}} )</script>`},
381 {`<button onclick=" alert( {{.Alert}} ) ">`, `<button onclick=" alert( {{.Alert}} ) ">`},
382 {`<select>{{ range . }}<option>{{ . }}{{ end }}</select>`, `<select>{{ range . }}<option>{{ . }}{{ end }}</select>`},
383 {`<p>Hello <code>{{""}}</code> there</p>`, `<p>Hello <code>{{""}}</code> there`},
384 {`<select><option>Default</option>{{range $i, $lang := .Languages}}<option>{{$lang}}</option>{{end}}</select>`, `<select><option>Default{{range $i, $lang := .Languages}}<option>{{$lang}}{{end}}</select>`},
385 {`<tr{{if .Deleted}} class="is-disabled"{{end}}>`, `<tr{{if .Deleted}} class="is-disabled"{{end}}>`},
386 {`<a {{.Foo}}{{xx .Bar}}>`, `<a {{.Foo}}{{xx .Bar}}>`},
387
388 // whitespace
389 {`{{ printf " ! " }}`, `{{ printf " ! " }}`},
390 {`a<p> {{a}} </p>b`, `a<p>{{a}}</p>b`},
391 {`a<span> {{a}} </span>b`, `a<span> {{a}} </span>b`},
392 {`a <span> {{a}} </span> b`, `a <span>{{a}} </span>b`},
393 {` {{a}} {{b}} `, `{{a}} {{b}}`},
394 }
395
396 m := minify.New()
397 m.AddFunc("text/css", css.Minify)
398 m.AddFunc("application/javascript", js.Minify)
399 htmlMinifier := &Minifier{TemplateDelims: GoTemplateDelims}
400 for _, tt := range htmlTests {
401 t.Run(tt.html, func(t *testing.T) {
402 r := bytes.NewBufferString(tt.html)
403 w := &bytes.Buffer{}
404 err := htmlMinifier.Minify(m, w, r, nil)
405 test.Minify(t, tt.html, err, w.String(), tt.expected)
406 })
407 }
408}
409
410func TestHTMLPHPTemplates(t *testing.T) {
411 htmlTests := []struct {

Callers

nothing calls this directly

Calls 5

MinifyMethod · 0.95
AddFuncMethod · 0.80
RunMethod · 0.80
MinifyMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…