Пример #1
0
func emptyChildren(node *html.Node) bool {
	if len(h5.Children(node)) == 0 {
		return true
	}
	sum := ""
	for _, ch := range h5.Children(node) {
		sum += ch.Data
	}
	return strings.TrimSpace(sum) == ""
}
Пример #2
0
func TestEveryEntryHasCaptchaSection(t *testing.T) {
	for _, e := range testPosts {
		node := htmltest.QueryOne(t, e.URL, ".author")
		assertElem(t, node, "div")
		require.NotEmpty(t, h5.Children(node), "Empty author div!")
		checkAuthorSection(T{t}, node)
	}
}
Пример #3
0
func TestEntriesHaveTagsInList(t *testing.T) {
	nodes := htmltest.Query(t, "", "+", ".tags")
	for _, node := range nodes {
		assertElem(t, node, "div")
		require.NotEmpty(t, h5.Children(node), "Empty tags div!")
		checkTagsSection(T{t}, node)
	}
}
Пример #4
0
func TestEntryListHasAuthor(t *testing.T) {
	nodes := htmltest.Query(t, "", "+", ".author")
	for _, node := range nodes {
		assertElem(t, node, "div")
		require.NotEmpty(t, h5.Children(node), "Empty author div!")
		checkAuthorSection(T{t}, node)
	}
}
Пример #5
0
func checkAuthorSection(t T, node *html.Node) {
	date := node.FirstChild.Data
	dateRe, _ := regexp.Compile("[0-9]{4}-[0-9]{2}-[0-9]{2}")
	m := dateRe.FindString(date)
	t.failIf(m == "", "No date found in author section!")
	n2 := htmltest.CssSelect(t.T, node, "strong")
	t.failIf(len(n2) != 1, "Author node not found in section: %q", h5.NewTree(node).String())
	t.failIf(h5.Children(n2[0]) == nil, "Author node not found in section: %q", h5.NewTree(node).String())
}
Пример #6
0
func TestTagFormattingInPostPage(t *testing.T) {
	for _, e := range testPosts {
		nodes := htmltest.Query(t, e.URL, "*", ".tags")
		if len(nodes) > 0 {
			for _, node := range nodes {
				assertElem(t, node, "div")
				require.NotEmpty(t, h5.Children(node), "Empty tags div!")
				checkTagsSection(T{t}, node)
			}
		}
	}
}