-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
94 lines (80 loc) · 1.66 KB
/
main_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
91
92
93
94
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestHTMLTableTo2D_A(t *testing.T) {
rows := [][]Cell{
{
{Rowspan: 1, Colspan: 1, Text: "A"},
{Rowspan: 1, Colspan: 1, Text: "B"},
},
{
{Rowspan: 2, Colspan: 1, Text: "C"},
{Rowspan: 1, Colspan: 1, Text: "D"},
},
{
{Rowspan: 1, Colspan: 1, Text: "E"},
{Rowspan: 1, Colspan: 1, Text: "F"},
},
{
{Rowspan: 1, Colspan: 1, Text: "G"},
{Rowspan: 1, Colspan: 1, Text: "H"},
},
}
table := htmlTableTo2D(rows)
expected := [][]string{
{"A", "B", ""},
{"C", "D", ""},
{"C", "E", "F"},
{"G", "H", ""},
}
assert.Equal(t, expected, table)
}
func TestHTMLTableTo2D_B(t *testing.T) {
rows := [][]Cell{
{
{Rowspan: 1, Colspan: 1, Text: "A"},
{Rowspan: 1, Colspan: 1, Text: "B"},
},
{
{Rowspan: 2, Colspan: 1, Text: "C"},
{Rowspan: 2, Colspan: 1, Text: "D"},
},
{
{Rowspan: 1, Colspan: 1, Text: "E"},
{Rowspan: 1, Colspan: 1, Text: "F"},
},
{
{Rowspan: 1, Colspan: 1, Text: "G"},
{Rowspan: 1, Colspan: 1, Text: "H"},
},
}
table := htmlTableTo2D(rows)
expected := [][]string{
{"A", "B", "", ""},
{"C", "D", "", ""},
{"C", "D", "E", "F"},
{"G", "H", "", ""},
}
assert.Equal(t, expected, table)
}
func TestHTMLTableTo2D_C(t *testing.T) {
rows := [][]Cell{
{
{Rowspan: 3, Colspan: 1, Text: "A"},
{Rowspan: 0, Colspan: 1, Text: "B"},
{Rowspan: 1, Colspan: 1, Text: "C"},
{Rowspan: 1, Colspan: 2, Text: "D"},
},
{
{Rowspan: 1, Colspan: 0, Text: "E"},
},
}
table := htmlTableTo2D(rows)
expected := [][]string{
{"A", "B", "C", "D"},
{"A", "B", "E", "E"},
}
assert.Equal(t, expected, table)
}