all repos — grayfriday @ b98aa06008196b3fd3c561305a871978113be869

blackfriday fork with a few changes

esc_test.go (view raw)

 1package blackfriday
 2
 3import (
 4	"bytes"
 5	"testing"
 6)
 7
 8func TestEsc(t *testing.T) {
 9	t.Parallel()
10	tests := []string{
11		"abc", "abc",
12		"a&c", "a&c",
13		"<", "&lt;",
14		"[]:<", "[]:&lt;",
15		"Hello <!--", "Hello &lt;!--",
16	}
17	for i := 0; i < len(tests); i += 2 {
18		var b bytes.Buffer
19		escapeHTML(&b, []byte(tests[i]))
20		if !bytes.Equal(b.Bytes(), []byte(tests[i+1])) {
21			t.Errorf("\nInput   [%#v]\nExpected[%#v]\nActual  [%#v]",
22				tests[i], tests[i+1], b.String())
23		}
24	}
25}
26
27func BenchmarkEscapeHTML(b *testing.B) {
28	tests := [][]byte{
29		[]byte(""),
30		[]byte("AT&T has an ampersand in their name."),
31		[]byte("AT&amp;T is another way to write it."),
32		[]byte("This & that."),
33		[]byte("4 < 5."),
34		[]byte("6 > 5."),
35		[]byte("Here's a [link] [1] with an ampersand in the URL."),
36		[]byte("Here's a link with an ampersand in the link text: [AT&T] [2]."),
37		[]byte("Here's an inline [link](/script?foo=1&bar=2)."),
38		[]byte("Here's an inline [link](</script?foo=1&bar=2>)."),
39		[]byte("[1]: http://example.com/?foo=1&bar=2"),
40		[]byte("[2]: http://att.com/  \"AT&T\""),
41	}
42	var buf bytes.Buffer
43	for n := 0; n < b.N; n++ {
44		for _, t := range tests {
45			escapeHTML(&buf, t)
46			buf.Reset()
47		}
48	}
49}