mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
2bee4a1570
Consumes less memory, slightly faster.
35 lines
884 B
Go
35 lines
884 B
Go
package helpers
|
|
|
|
import (
|
|
"github.com/stretchr/testify/assert"
|
|
"html/template"
|
|
"testing"
|
|
)
|
|
|
|
func TestStripHTML(t *testing.T) {
|
|
type test struct {
|
|
input, expected string
|
|
}
|
|
data := []test{
|
|
{"<h1>strip h1 tag <h1>", "strip h1 tag "},
|
|
{"<p> strip p tag </p>", " strip p tag \n"},
|
|
{"</br> strip br<br>", " strip br\n"},
|
|
{"</br> strip br2<br />", " strip br2\n"},
|
|
{"This <strong>is</strong> a\nnewline", "This is a newline"},
|
|
}
|
|
for i, d := range data {
|
|
output := StripHTML(d.input)
|
|
if d.expected != output {
|
|
t.Errorf("Test %d failed. Expected %q got %q", i, d.expected, output)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestStripEmptyNav(t *testing.T) {
|
|
cleaned := StripEmptyNav([]byte("do<nav>\n</nav>\n\nbedobedo"))
|
|
assert.Equal(t, []byte("dobedobedo"), cleaned)
|
|
}
|
|
|
|
func TestBytesToHTML(t *testing.T) {
|
|
assert.Equal(t, template.HTML("dobedobedo"), BytesToHTML([]byte("dobedobedo")))
|
|
}
|