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

Function TestHTMLKeepWhitespace

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

Source from the content-addressed store, hash-verified

274}
275
276func TestHTMLKeepWhitespace(t *testing.T) {
277 htmlTests := []struct {
278 html string
279 expected string
280 }{
281 {`cats and dogs `, `cats and dogs`},
282 {` <div> <i> test </i> <b> test </b> </div> `, `<div> <i> test </i> <b> test </b> </div>`},
283 {`<strong>x </strong>y`, `<strong>x </strong>y`},
284 {`<strong>x </strong> y`, `<strong>x </strong> y`},
285 {"<strong>x </strong>\ny", "<strong>x </strong>\ny"},
286 {`<p>x </p>y`, `<p>x </p>y`},
287 {`x <p>y</p>`, `x <p>y`},
288 {` <!doctype html> <!--comment--> <html> <body><p></p></body></html> `, `<!doctype html><p>`}, // spaces before html and at the start of html are dropped
289 {`<p>x<br> y`, `<p>x<br> y`},
290 {`<p>x </b> <b> y`, `<p>x </b> <b> y`},
291 {`a <code>code</code> b`, `a <code>code</code> b`},
292 {`a <code></code> b`, `a <code></code> b`},
293 {`a <script>script</script> b`, `a <script>script</script> b`},
294 {"text\n<!--comment-->\ntext", "text\ntext"},
295 {"text\n<!--comment-->text<!--comment--> text", "text\ntext text"},
296 {"abc\n</body>\ndef", "abc\ndef"},
297 {"<x>\n<!--y-->\n</x>", "<x>\n</x>"},
298 {"<style>lala{color:red}</style>", "<style>lala{color:red}</style>"},
299 {"<li>one\n</li>\n<li>two", "<li>one\n<li>two"}, // #442
300 }
301
302 m := minify.New()
303 htmlMinifier := &Minifier{KeepWhitespace: true}
304 for _, tt := range htmlTests {
305 t.Run(tt.html, func(t *testing.T) {
306 r := bytes.NewBufferString(tt.html)
307 w := &bytes.Buffer{}
308 err := htmlMinifier.Minify(m, w, r, nil)
309 test.Minify(t, tt.html, err, w.String(), tt.expected)
310 })
311 }
312}
313
314func TestHTMLKeepQuotes(t *testing.T) {
315 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…