all repos — grayfriday @ d9ffdb74649c9a714d43540d0f9dc596f742ebba

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
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 amersand 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 buff bytes.Buffer
43	for n := 0; n < b.N; n++ {
44		for _, t := range tests {
45			escapeHTML(&buff, t)
46			buff.Reset()
47		}
48	}
49}
50*/