Skip to content

Commit

Permalink
tests/parser: Title
Browse files Browse the repository at this point in the history
  • Loading branch information
iawia002 committed Apr 24, 2018
1 parent 697332f commit 2526302
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,45 @@ func TestGetDoc(t *testing.T) {
})
}
}

func TestGetTitle(t *testing.T) {
type args struct {
html string
}
tests := []struct {
name string
args args
want string
}{
{
name: "title test",
args: args{
html: `<html><head><title>hello</title></head><body>hello</body></html>`,
},
want: "hello",
},
{
name: "h1 test",
args: args{
html: `<html><head><title>hello</title></head><body><h1> aa</h1></body></html>`,
},
want: "aa",
},
{
name: "og:title test",
args: args{
html: `<html><head><meta property="og:title" content="你的名字。"></head><body>hello</body></html>`,
},
want: "你的名字。",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
doc := GetDoc(tt.args.html)
title := Title(doc)
if title != tt.want {
t.Errorf("Title() = %s, want %s", title, tt.want)
}
})
}
}

0 comments on commit 2526302

Please sign in to comment.