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

Function TestHTMLURL

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

Source from the content-addressed store, hash-verified

335}
336
337func TestHTMLURL(t *testing.T) {
338 htmlTests := []struct {
339 url string
340 html string
341 expected string
342 }{
343 {`http://example.com/`, `<a href=http://example.com/>link</a>`, `<a href=//example.com/>link</a>`},
344 {`https://example.com/`, `<a href=http://example.com/>link</a>`, `<a href=http://example.com/>link</a>`},
345 {`http://example.com/`, `<a href=https://example.com/>link</a>`, `<a href=https://example.com/>link</a>`},
346 {`https://example.com/`, `<a href=https://example.com/>link</a>`, `<a href=//example.com/>link</a>`},
347 {`http://example.com/`, `<a href=" http://example.com ">x</a>`, `<a href=//example.com>x</a>`},
348 {`http://example.com/`, `<link rel="stylesheet" type="text/css" href="http://example.com">`, `<link rel=stylesheet href=//example.com>`},
349 {`http://example.com/`, `<!doctype html> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head profile="http://dublincore.org/documents/dcq-html/"> <!-- Barlesque 2.75.0 --> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />`,
350 `<!doctype html><html xmlns=//www.w3.org/1999/xhtml xml:lang=en><head profile=//dublincore.org/documents/dcq-html/><meta charset=utf-8>`},
351 {`http://example.com/`, `<html xmlns="http://www.w3.org/1999/xhtml"></html>`, `<html xmlns=//www.w3.org/1999/xhtml>`},
352 {`https://example.com/`, `<html xmlns="http://www.w3.org/1999/xhtml"></html>`, `<html xmlns=http://www.w3.org/1999/xhtml>`},
353 {`http://example.com/`, `<html xmlns="https://www.w3.org/1999/xhtml"></html>`, `<html xmlns=https://www.w3.org/1999/xhtml>`},
354 {`https://example.com/`, `<html xmlns="https://www.w3.org/1999/xhtml"></html>`, `<html xmlns=//www.w3.org/1999/xhtml>`},
355 }
356
357 m := minify.New()
358 m.AddFunc("text/html", Minify)
359 for _, tt := range htmlTests {
360 t.Run(tt.url, func(t *testing.T) {
361 r := bytes.NewBufferString(tt.html)
362 w := &bytes.Buffer{}
363 m.URL, _ = url.Parse(tt.url)
364 err := Minify(m, w, r, nil)
365 test.Minify(t, tt.html, err, w.String(), tt.expected)
366 })
367 }
368}
369
370func TestHTMLGoTemplates(t *testing.T) {
371 htmlTests := []struct {

Callers

nothing calls this directly

Calls 5

AddFuncMethod · 0.80
RunMethod · 0.80
MinifyFunction · 0.70
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…