forked from gomarkdown/markdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarkdown_test.go
61 lines (54 loc) · 1.08 KB
/
markdown_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package markdown
import (
"bytes"
"testing"
)
func TestDocument(t *testing.T) {
var tests = []string{
// Empty document.
"",
"",
" ",
"",
// This shouldn't panic.
// https://github.com/russross/blackfriday/issues/172
"[]:<",
"<p>[]:<</p>\n",
// This shouldn't panic.
// https://github.com/russross/blackfriday/issues/173
" [",
"<p>[</p>\n",
}
doTests(t, tests)
}
func TestNormalizeNewlines(t *testing.T) {
var tests = [][]byte{
{},
{10},
{13},
{13, 10, 13},
{'a', 13, 10, 13, 'b'},
{'a', 13, 10},
{'b', 13},
{13, 10, 13, 10},
{13, 10, 13, 10, 'a'},
{13, 10, 13, 10, 10},
{13, 10, 13, 10, 13},
}
ref := func(d []byte) []byte {
d = bytes.Replace(d, []byte{13, 10}, []byte{10}, -1) // CRLF => LF
d = bytes.Replace(d, []byte{13}, []byte{10}, -1) // CR => LF
return d
}
dup := func(d []byte) []byte {
return append([]byte{}, d...)
}
for i := 0; i < len(tests); i++ {
d := tests[i]
got := NormalizeNewlines(dup(d))
exp := ref(dup(d))
if !bytes.Equal(got, exp) {
t.Errorf("got: %v, exp: %v, i: %d\n", got, exp, i)
}
}
}