Esempio n. 1
0
func TestSelectorMatch(t *testing.T) {
	for _, spec := range matchers {
		chn, err := Selector(spec.s)
		if err != nil {
			t.Errorf("Error parsing selector %q", err)
		}
		if !chn.Head.Match(spec.n) {
			t.Errorf("spec %q didn't match %q when it should have",
				chn, h5.RenderNodesToString([]*html.Node{spec.n}))
		}
		if chn.Head.Match(spec.n2) {
			t.Errorf("spec %q matched %q when it shouldn't have",
				chn, h5.RenderNodesToString([]*html.Node{spec.n2}))
		}
	}
}
Esempio n. 2
0
func TestSelectorFind(t *testing.T) {
	for _, spec := range finders {
		chn, err := Selector(spec.s)
		if err != nil {
			t.Errorf("Error parsing selector %q", err)
		}
		ns := chn.Find(spec.n)
		if len(ns) < 1 {
			t.Errorf("%q didn't find any nodes in %q",
				chn, h5.RenderNodesToString([]*html.Node{spec.n}))
		}
		if h5.RenderNodesToString(ns) != h5.RenderNodesToString(spec.ns) {
			t.Errorf("Got: %q Expected: %q",
				h5.RenderNodesToString(ns), h5.RenderNodesToString(spec.ns))
		}
	}
}