package htmlx import ( "github.com/stretchr/testify/assert" "testing" ) func TestStrip(t *testing.T) { tests := []struct { tag string html string expected string }{ {"t0", "
hello
", "hello"}, {"t1", `
hello
`, "hello"}, {"t3", "
hello
", "hello"}, {"t4", "
hello
", "hello"}, {"t4", `
hello
`, "hello"}, {"t5", `
hello
`, "hello"}, {"t6", `

Custom flags for your garden are a great way to show your personality to your friends and neighbors. Design and turn it into an eye-catching flag all year round. This will be a beautiful addition to your yard and garden, also a simple sign to show your patriotism on Memorial Day, 4th of July or Veterans Day, Christmas holidays or any holiday of the year.

`, "Custom flags for your garden are a great way to show your personality to your friends and neighbors. Design and turn it into an eye-catching flag all year round. This will be a beautiful addition to your yard and garden, also a simple sign to show your patriotism on Memorial Day, 4th of July or Veterans Day, Christmas holidays or any holiday of the year."}, {"t7", "<div>hello
", "hello"}, {"t8", "
hello world
", "hello world"}, } for _, test := range tests { equal := Strip(test.html) assert.Equal(t, test.expected, equal, test.tag) } } func BenchmarkStrip(b *testing.B) { for i := 0; i < b.N; i++ { Strip(`

Custom flags for your garden are a great way to show your personality to your friends and neighbors. Design and turn it into an eye-catching flag all year round. This will be a beautiful addition to your yard and garden, also a simple sign to show your patriotism on Memorial Day, 4th of July or Veterans Day, Christmas holidays or any holiday of the year.

`) } } func TestSpaceless(t *testing.T) { tests := []struct { tag string html string expected string }{ {"t0", "
hello
", "
hello
"}, {"t1", `
hello
`, "
hello
"}, {"t3", "
hello
", "
hello
"}, {"t4", "
hello
", "
hello
"}, {"t4", `
hello
`, `
hello
`}, {"t7", "
hello
", "
hello
"}, {"t8", `

Custom flags for your garden are a great way to show your personality to your friends and neighbors. Design and turn it into an eye-catching flag all year round. This will be a beautiful addition to your yard and garden, also a simple sign to show your patriotism on Memorial Day, 4th of July or Veterans Day, Christmas holidays or any holiday of the year.

`, `

Custom flags for your garden are a great way to show your personality to your friends and neighbors. Design and turn it into an eye-catching flag all year round. This will be a beautiful addition to your yard and garden, also a simple sign to show your patriotism on Memorial Day, 4th of July or Veterans Day, Christmas holidays or any holiday of the year.

`}, } for _, test := range tests { html := Spaceless(test.html) assert.Equal(t, test.expected, html, test.tag) } } func TestClean(t *testing.T) { tests := []struct { tag string html string cleanMode CleanMode expected string }{ {"tcss1", "
hello
", CleanModeCSS, "
hello
"}, {"tcss2", "
hello
", CleanModeCSS, "
hello
"}, {"tjavascript1", `
hello
`, CleanModeJavascript, "
hello
"}, {"tcomment1", `
hello
`, CleanModeComment, "
hello
"}, {"tcss,javascript,comment", `
hello
`, CleanModeCSS | CleanModeJavascript | CleanModeComment, "
hello
"}, {"tall1", `
hello
`, CleanModeAll, "
hello
"}, {"tall2", `

Product details: +++ Material: 100% Ceramic +++ Size: 11oz or 15oz +++ Dye Sublimation graphics for exceptional prints. +++ Dishwasher and microwave safe. +++ Image is printed on both sides of mug. +++ Printed in the U.S.A. +++ Shipping info: Shipping time is approximately 5-7 business days.

`, CleanModeAll, "

Product details: +++ Material: 100% Ceramic +++ Size: 11oz or 15oz +++ Dye Sublimation graphics for exceptional prints. +++ Dishwasher and microwave safe. +++ Image is printed on both sides of mug. +++ Printed in the U.S.A. +++ Shipping info: Shipping time is approximately 5-7 business days.

"}, {"tall3", `
1 2
2
`, CleanModeAll, `
1 2
2
`}, } for _, testCase := range tests { html := Clean(testCase.html, testCase.cleanMode) assert.Equal(t, testCase.expected, html, testCase.tag) } } func TestTag(t *testing.T) { tests := []struct { tag string elementTag string content string attributes map[string]string styles map[string]string expected string }{ {"t0", "div", "hello", nil, nil, "
hello
"}, {"t1", "div", "hello", map[string]string{"id": "name"}, nil, `
hello
`}, {"t1.1", "div", "hello", map[string]string{"id": "name", "name": "name"}, nil, `
hello
`}, {"t2", "div", "hello", map[string]string{"id": "name", "data-tag": "123"}, map[string]string{"font-size": "1", "font-weight": "bold"}, `
hello
`}, } for _, test := range tests { equal := Tag(test.elementTag, test.content, test.attributes, test.styles) assert.Equal(t, test.expected, equal, test.tag) } } func BenchmarkTag(b *testing.B) { for i := 0; i < b.N; i++ { Tag("div", "hello", map[string]string{"id": "name"}, map[string]string{"font-size": "1"}) } }