Skip to content

Commit

Permalink
Add tests for gdoc countTwo.
Browse files Browse the repository at this point in the history
  • Loading branch information
cassierecher committed Aug 27, 2021
1 parent ce19864 commit cd12a49
Showing 1 changed file with 79 additions and 1 deletion.
80 changes: 79 additions & 1 deletion claat/parser/gdoc/html_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,85 @@ func TestIsHeader(t *testing.T) {

// TODO: test isList

// TODO: test countTwo
func TestCountTwo(t *testing.T) {
a1 := makePNode()
a2 := makeBlinkNode()
a3 := makeTextNode("foobar")
a1.AppendChild(a2)
a2.AppendChild(a3)

b1 := makePNode()
b2 := makeTextNode("foobar")
b3 := makeMarqueeNode()
// The nodes should be siblings.
b1.AppendChild(b2)
b1.AppendChild(b3)

c1 := makePNode()
c2 := makeTextNode("foobar")
c3 := makeMarqueeNode()
c4 := makeTextNode("foobar2")
c5 := makeMarqueeNode()
// The nodes should be siblings.
c1.AppendChild(c2)
c1.AppendChild(c3)
c1.AppendChild(c4)
c1.AppendChild(c5)

d1 := makePNode()
d2 := makeTextNode("foobar")
d3 := makeMarqueeNode()
d4 := makeTextNode("foobar2")
d5 := makeMarqueeNode()
d6 := makeMarqueeNode()
d7 := makeMarqueeNode()
// The nodes should be siblings.
d1.AppendChild(d2)
d1.AppendChild(d3)
d1.AppendChild(d4)
d1.AppendChild(d5)
d1.AppendChild(d6)
d1.AppendChild(d7)

tests := []struct {
name string
inNode *html.Node
inAtom atom.Atom
out int
}{
{
name: "Zero",
inNode: a1,
inAtom: atom.Marquee,
out: 0,
},
{
name: "One",
inNode: b1,
inAtom: atom.Marquee,
out: 1,
},
{
name: "Two",
inNode: c1,
inAtom: atom.Marquee,
out: 2,
},
{
name: "MoreThanTwo",
inNode: d1,
inAtom: atom.Marquee,
out: 2,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
if out := countTwo(tc.inNode, tc.inAtom); out != tc.out {
t.Errorf("countTwo(%+v, %+v) = %d, want %d", tc.inNode, tc.inAtom, out, tc.out)
}
})
}
}

func TestCountDirect(t *testing.T) {
a1 := makePNode()
Expand Down

0 comments on commit cd12a49

Please sign in to comment.