This repository was archived by the owner on Sep 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathparser_test.go
More file actions
114 lines (105 loc) · 1.95 KB
/
Copy pathparser_test.go
File metadata and controls
114 lines (105 loc) · 1.95 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package mark
import (
"testing"
)
type parseTest struct {
name string
items []item
nodes []NodeType
}
type mockLexer struct {
items []item
}
func (l *mockLexer) nextItem() (t item) {
if len(l.items) == 0 {
return item{itemEOF, 0, ""}
}
t, l.items = l.items[0], l.items[1:]
return
}
func newMockLex(items []item) *mockLexer {
return &mockLexer{items: items}
}
var blockparseTests = []parseTest{
{"eof", []item{}, []NodeType{}},
{"text-1",
[]item{item{itemText, 0, "hello"}},
[]NodeType{NodeParagraph},
},
{"text-2",
[]item{
item{itemText, 0, "hello"},
item{itemNewLine, 0, "\n"},
item{itemText, 0, "world"},
},
[]NodeType{NodeParagraph},
},
{"text-3",
[]item{
item{itemText, 0, "hello"},
item{itemNewLine, 0, "\n"},
item{itemNewLine, 0, "\n\n"},
item{itemText, 0, "world"},
},
[]NodeType{NodeParagraph, NodeParagraph},
},
{"header",
[]item{
item{itemHeading, 0, "# Hello"},
},
[]NodeType{NodeHeading},
},
{"code-block",
[]item{
item{itemCodeBlock, 0, " js\n hello"},
},
[]NodeType{NodeCode},
},
{"table",
[]item{
item{itemTable, 0, ""},
},
[]NodeType{NodeTable},
},
{"list",
[]item{
item{itemList, 0, "-"},
item{itemListItem, 0, "hello"},
},
[]NodeType{NodeList},
},
{"HTML",
[]item{
item{itemHTML, 0, "<hello>\nworld</hello>"},
},
[]NodeType{NodeHTML},
},
}
func collectNodes(t *parseTest) []Node {
tr := &parse{
lex: newMockLex(t.items),
links: make(map[string]*DefLinkNode),
options: DefaultOptions(),
}
tr.parse()
return tr.Nodes
}
func equalTypes(n1 []Node, n2 []NodeType) bool {
if len(n1) != len(n2) {
return false
}
for i := range n1 {
if n1[i].Type() != n2[i] {
return false
}
}
return true
}
func TestBlocksparse(t *testing.T) {
for _, test := range blockparseTests {
nodes := collectNodes(&test)
if !equalTypes(nodes, test.nodes) {
t.Errorf("%s: got\n\t%+v\nexpected\n\t%+v", test.name, nodes, test.nodes)
}
}
}