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

Function TestHTMLKeepSpecialComments

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

Source from the content-addressed store, hash-verified

247}
248
249func TestHTMLKeepSpecialComments(t *testing.T) {
250 htmlTests := []struct {
251 html string
252 expected string
253 }{
254 {`<!--[if IE 6]> <b> </b> <![endif]-->`, `<!--[if IE 6]><b></b><![endif]-->`},
255 {`<![if IE 6]> <b> </b> <![endif]>`, `<![if IE 6]><b></b><![endif]>`},
256 {`<!--[if IE 6]--> <b> </b> <!--[endif]-->`, `<!--[if IE 6]--><b></b><!--[endif]-->`},
257 {`<!--[if !mso]><!--> <b> </b> <!--<![endif]-->`, `<!--[if !mso]><!--><b></b><!--<![endif]-->`},
258 {`<!--[if gt IE 6]><!--> <b> </b> <![endif]-->`, `<!--[if gt IE 6]><!--><b></b><![endif]-->`},
259 {`<!--[if IE]foo<![endif]-->`, `<!--[if IE]foo<![endif]-->`}, // #596
260 {`<!--# SSI-->`, `<!--# SSI-->`}, // #657
261 {`<!--[if mso]><noscript><xml><o:OfficeDocumentSettings><o:PixelsPerInch>96</o:PixelsPerInch></o:OfficeDocumentSettings></xml></noscript><![endif]-->`, `<!--[if mso]><noscript><xml><o:OfficeDocumentSettings><o:PixelsPerInch>96</o:PixelsPerInch></o:OfficeDocumentSettings></xml></noscript><![endif]-->`}, // #832
262 }
263
264 m := minify.New()
265 htmlMinifier := &Minifier{KeepSpecialComments: true}
266 for _, tt := range htmlTests {
267 t.Run(tt.html, func(t *testing.T) {
268 r := bytes.NewBufferString(tt.html)
269 w := &bytes.Buffer{}
270 err := htmlMinifier.Minify(m, w, r, nil)
271 test.Minify(t, tt.html, err, w.String(), tt.expected)
272 })
273 }
274}
275
276func TestHTMLKeepWhitespace(t *testing.T) {
277 htmlTests := []struct {

Callers

nothing calls this directly

Calls 4

MinifyMethod · 0.95
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…