-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtable_test.go
90 lines (61 loc) · 1.41 KB
/
table_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
83
84
85
86
87
88
89
90
package hype
import (
"testing"
"github.com/markbates/table"
"github.com/stretchr/testify/require"
)
func Test_Table_Data(t *testing.T) {
t.Parallel()
r := require.New(t)
root := "testdata/table/data"
p := testParser(t, root)
doc, err := p.ParseFile("hype.md")
r.NoError(err)
// fmt.Println(doc.String())
r.NotNil(doc)
tables := ByType[*Table](doc.Children())
r.Len(tables, 1)
tab := tables[0]
r.NotNil(tab)
data, err := tab.Data()
r.NoError(err)
r.NotNil(data)
cols, err := data.Columns()
r.NoError(err)
r.Len(cols, 2)
r.Equal([]string{"Name", "Age"}, cols)
rows, err := data.Rows()
r.NoError(err)
r.Len(rows, 3)
r.Equal(table.Row{"Alice", "42"}, rows[0])
r.Equal(table.Row{"Bob", "13"}, rows[1])
r.Equal(table.Row{"Kurt", "27"}, rows[2])
}
func Test_Table_MD_in_MD(t *testing.T) {
t.Parallel()
root := "testdata/table/md_in_md"
testModule(t, root)
}
func Test_Table_MD_in_HTML(t *testing.T) {
t.Parallel()
root := "testdata/table/md_in_html"
testModule(t, root)
}
func Test_Table_No_THEAD(t *testing.T) {
t.Parallel()
t.Skip()
root := "testdata/table/headless"
testModule(t, root)
}
func Test_Table_MarshalJSON(t *testing.T) {
t.Parallel()
r := require.New(t)
p := testParser(t, "testdata/table/data")
doc, err := p.ParseFile("hype.md")
r.NoError(err)
tables := ByType[*Table](doc.Children())
r.Len(tables, 1)
tab := tables[0]
r.NotNil(tab)
testJSON(t, "table", tab)
}