Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion array.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (s *Selection) Eq(index int) *Selection {
}

if index >= len(s.Nodes) || index < 0 {
return newEmptySelection(s.document)
return pushStack(s, nil)
}

return s.Slice(index, index+1)
Expand Down
11 changes: 11 additions & 0 deletions array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ func TestEqRollback(t *testing.T) {
assertEqual(t, sel, sel2)
}

func TestEqOutOfRangeRollback(t *testing.T) {
for _, sel := range []*Selection{Doc().Find(".pvk-content"), Doc().Find("missing")} {
for _, index := range []int{sel.Length(), -sel.Length() - 1} {
empty := sel.Eq(index)
assertLength(t, empty.Nodes, 0)
assertEqual(t, sel, empty.End())
assertLength(t, empty.AddBack().Nodes, sel.Length())
}
}
}

func TestSlice(t *testing.T) {
sel := Doc().Find(".pvk-content").Slice(0, 2)

Expand Down
Loading