From 7a694908182b12b4f5568d41ac8ea223139f7acb Mon Sep 17 00:00:00 2001 From: Martin Angers Date: Fri, 31 Aug 2012 09:06:39 -0400 Subject: [PATCH] add tests for Has() and End() --- README.md | 4 ++++ filter_test.go | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/README.md b/README.md index 0c6b108..338348a 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,10 @@ Please note that Cascadia's selectors do NOT necessarily match all supported sel [Reference documentation can be found here][doc]. +## Examples + +TODO... + ## License The [BSD 3-Clause license][bsd], the same as the [Go language][golic]. Cascadia's license is [here][caslic]. diff --git a/filter_test.go b/filter_test.go index 0b536a9..69fbcd6 100644 --- a/filter_test.go +++ b/filter_test.go @@ -91,3 +91,44 @@ func TestUnion(t *testing.T) { t.Errorf("Expected 6 nodes, found %v.", len(sel2.Nodes)) } } + +func TestHas(t *testing.T) { + sel := Doc().Find(".container-fluid").Has(".center-content") + if len(sel.Nodes) != 2 { + t.Errorf("Expected 2 nodes, found %v.", len(sel.Nodes)) + } + // Has() returns the high-level .container-fluid div, and the one that is the immediate parent of center-content +} + +func TestHasNodes(t *testing.T) { + sel := Doc().Find(".container-fluid") + sel2 := Doc().Find(".center-content") + sel = sel.HasNodes(sel2.Nodes...) + if len(sel.Nodes) != 2 { + t.Errorf("Expected 2 nodes, found %v.", len(sel.Nodes)) + } + // Has() returns the high-level .container-fluid div, and the one that is the immediate parent of center-content +} + +func TestHasSelection(t *testing.T) { + sel := Doc().Find("p") + sel2 := Doc().Find("small") + sel = sel.HasSelection(sel2) + if len(sel.Nodes) != 1 { + t.Errorf("Expected 1 node, found %v.", len(sel.Nodes)) + } +} + +func TestEnd(t *testing.T) { + sel := Doc().Find("p").Has("small").End() + if len(sel.Nodes) != 4 { + t.Errorf("Expected 4 nodes, found %v.", len(sel.Nodes)) + } +} + +func TestEndToTop(t *testing.T) { + sel := Doc().Find("p").Has("small").End().End() + if len(sel.Nodes) != 0 { + t.Errorf("Expected 0 node, found %v.", len(sel.Nodes)) + } +}