mirror of
https://github.com/PuerkitoBio/goquery.git
synced 2024-04-21 12:31:36 +00:00
add PrevUntil() with tests
This commit is contained in:
Vendored
+4
-4
@@ -22,7 +22,7 @@
|
||||
<div class="pvk-content">
|
||||
<div ng-controller="HeroCtrl" class="hero-unit">
|
||||
<div class="container-fluid" id="cf2">
|
||||
<div class="row-fluid">
|
||||
<div class="row-fluid" id="cf2-1">
|
||||
<div class="span12">
|
||||
<h1>
|
||||
<a href="/">Provok<span class="green">.</span><span class="red">i</span>n</a>
|
||||
@@ -32,15 +32,15 @@
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row-fluid">
|
||||
<div class="row-fluid" id="cf2-2">
|
||||
<div class="span12 alert alert-error">
|
||||
<strong>Beta Version.</strong> Things may change. Or disappear. Or fail miserably. If it's the latter, <a href="https://github.com/PuerkitoBio/Provok.in-issues" target="_blank" class="link">please file an issue.</a>
|
||||
</div>
|
||||
</div>
|
||||
<div ng-cloak="" ng-show="isLoggedOut() && !hideLogin" class="row-fluid">
|
||||
<div ng-cloak="" ng-show="isLoggedOut() && !hideLogin" class="row-fluid" id="cf2-3">
|
||||
<a ng-href="{{ROUTES.login}}" class="btn btn-primary">Sign in. Painless.</a> <span>or</span> <a ng-href="{{ROUTES.help}}" class="link">learn more about provok.in.</a>
|
||||
</div>
|
||||
<div ng-cloak="" ng-show="isLoggedIn()" class="row-fluid logged-in-state">
|
||||
<div ng-cloak="" ng-show="isLoggedIn()" class="row-fluid logged-in-state" id="cf2-4">
|
||||
<span>Welcome,</span> <a ng-href="{{ROUTES.profile}}" class="link">{{getUserName()}}</a> <span>(</span> <a ng-click="doLogout($event)" class="link">logout</a> <span>)</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+5
-1
@@ -220,8 +220,12 @@ func (this *Selection) PrevAllFiltered(selector string) *Selection {
|
||||
return filterAndPush(this, getSiblingNodes(this.Nodes, siblingPrevAll, "", nil), selector)
|
||||
}
|
||||
|
||||
// PrevUntil() gets all preceding siblings of each element up to but not
|
||||
// including the element matched by the selector. It returns a new Selection
|
||||
// object containing the matched elements.
|
||||
func (this *Selection) PrevUntil(selector string) *Selection {
|
||||
return nil
|
||||
return pushStack(this, getSiblingNodes(this.Nodes, siblingPrevUntil,
|
||||
selector, nil))
|
||||
}
|
||||
|
||||
// Filter and push filters the nodes based on a selector, and pushes the results
|
||||
|
||||
@@ -406,3 +406,36 @@ func TestPrevAllFilteredRollback(t *testing.T) {
|
||||
sel2 := sel.PrevAllFiltered(".pvk-content").End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestPrevUntil(t *testing.T) {
|
||||
sel := Doc().Root.Find(".alert p").PrevUntil("a")
|
||||
AssertLength(t, sel.Nodes, 1)
|
||||
if !sel.Eq(0).Is("h4") {
|
||||
t.Errorf("Expected node 0 to be h4, found %+v.", sel.Get(0))
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrevUntil2(t *testing.T) {
|
||||
sel := Doc().Root.Find("[ng-cloak]").PrevUntil(":not([ng-cloak])")
|
||||
AssertLength(t, sel.Nodes, 1)
|
||||
if !sel.Eq(0).Is("[ng-cloak]") {
|
||||
t.Errorf("Expected node 0 to be [ng-cloak], found %+v.", sel.Get(0))
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrevUntilOrder(t *testing.T) {
|
||||
sel := Doc().Root.Find("#cf2-4").PrevUntil("#cf2-1")
|
||||
AssertLength(t, sel.Nodes, 2)
|
||||
if !sel.Eq(0).Is("#cf2-3") {
|
||||
t.Errorf("Expected node 0 to be cf2-3, found %+v.", sel.Get(0))
|
||||
}
|
||||
if !sel.Eq(1).Is("#cf2-2") {
|
||||
t.Errorf("Expected node 1 to be cf2-2, found %+v.", sel.Get(1))
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrevUntilRollback(t *testing.T) {
|
||||
sel := Doc().Root.Find("#cf2-4")
|
||||
sel2 := sel.PrevUntil("#cf2-1").End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user