-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpage_test.go
82 lines (61 loc) · 1.14 KB
/
page_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package hype
import (
"strings"
"testing"
"testing/fstest"
"github.com/stretchr/testify/require"
)
func Test_Pages(t *testing.T) {
t.Parallel()
r := require.New(t)
mod := `# Page 1
<include src="second/second.md"></include>
more text
<include src="third/third.md"></include>
adfadf`
cab := fstest.MapFS{
"hype.md": &fstest.MapFile{
Data: []byte(mod),
},
"second/second.md": &fstest.MapFile{
Data: []byte(`# Second`),
},
"third/third.md": &fstest.MapFile{
Data: []byte(`# Third`),
},
}
p := NewParser(cab)
doc, err := p.Parse(strings.NewReader(mod))
r.NoError(err)
act := doc.String()
act = strings.TrimSpace(act)
// fmt.Println(act)
exp := `<html><head></head><body><page>
<h1>Page 1</h1>
</page>
<page>
<h1>Second</h1>
</page>
<page>
<p>more text</p>
</page>
<page>
<h1>Third</h1>
</page>
<page>
<p>adfadf</p>
</page>
</body></html>`
r.Equal(exp, act)
pages := ByType[*Page](doc.Nodes)
r.Len(pages, 5)
}
func Test_Pages_MarshalJSON(t *testing.T) {
t.Parallel()
p := &Page{
Title: "Page 1",
Element: NewEl("page", nil),
}
p.Nodes = append(p.Nodes, Text("more text"))
testJSON(t, "page", p)
}