all repos — grayfriday @ cfdcce51965fe68951a5fa45454aa6278c3f9614

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