-
Notifications
You must be signed in to change notification settings - Fork 3
/
parser_html_test.go
58 lines (49 loc) · 1.21 KB
/
parser_html_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
package table
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)
type parseHTMLSuite struct{ suite.Suite }
func TestParseHTML(t *testing.T) { suite.Run(t, new(parseHTMLSuite)) }
func (s *parseHTMLSuite) TestParseFromHTML() {
// Given
const htmlStr = `
<html>
<body>
<table>
<tr>
<th>Location</th>
<th>Delivery</th>
<th>Price</th>
</tr>
<tr>
<td>Delhi</td>
<td>January</td>
<td>100</td>
</tr>
<tr>
<td>Pune</td>
<td>February</td>
<td>80</td>
</tr>
<tr>
<td>Pune</td>
<td colspan="2">No prices</td>
</tr>
</table>
</body>
</html>
`
var expectedParsedHTML = Parsed{
{original: "", parsed: []string{}}, // ParseFromHTML doesn't parse row headers
{original: "Delhi\tJanuary\t100", parsed: []string{"Delhi", "January", "100"}},
{original: "Pune\tFebruary\t80", parsed: []string{"Pune", "February", "80"}},
{original: "Pune\tNo prices\t", parsed: []string{"Pune", "No prices", ""}},
}
// When
parsedHTML, err := ParseFromHTML(htmlStr)
// Then
require.Nil(s.T(), err)
require.Equal(s.T(), expectedParsedHTML, parsedHTML)
}