-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathparser_test.go
65 lines (56 loc) · 1.08 KB
/
parser_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
package mdtt
import (
"io"
"os"
"testing"
)
func TestParse(t *testing.T) {
cols1 := []column{
{title: NewCell("Key binding"), width: 4},
{title: NewCell("Description"), width: 20},
}
rows1 := []naiveRow{
{"`Arrows`, `hjkl`", "Move"},
}
want1 := NewTableModel(
WithColumns(cols1),
WithNaiveRows(rows1),
)
cols2 := []column{
{title: NewCell("Key binding"), width: 4},
{title: NewCell("Description"), width: 20},
}
rows2 := []naiveRow{
{"**Esc**, _q_", "Exit"},
}
want2 := NewTableModel(
WithColumns(cols2),
WithNaiveRows(rows2),
)
f, _ := os.Open("testdata/01.md")
defer f.Close()
s, _ := io.ReadAll(f)
got := parse(s)
if !isEqualTables(want1, got[0]) {
t.Error("Table value is mismatch")
}
if !isEqualTables(want2, got[1]) {
t.Error("Table value is mismatch")
}
}
func isEqualTables(x, y TableModel) bool {
ret := true
for i, c := range x.cols {
if c.title.value() != y.cols[i].title.value() {
ret = false
}
}
for i, r := range x.rows {
for j, c := range r {
if c.value() != y.rows[i][j].value() {
ret = false
}
}
}
return ret
}