mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-28 14:40:43 +03:00
hugolib: Improve nil handling in IsDescendant and IsAncestor
Fixes #5461
This commit is contained in:
parent
7540a62834
commit
b09a40333f
2 changed files with 23 additions and 2 deletions
|
@ -238,6 +238,8 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
|
|||
assert.Len(p.Sections(), 0)
|
||||
}},
|
||||
{"l1,l2,l3", func(p *Page) {
|
||||
var nilp *Page
|
||||
|
||||
assert.Equal("T3_-1", p.title)
|
||||
assert.Len(p.Pages, 2)
|
||||
assert.Equal("T2_-1", p.Parent().title)
|
||||
|
@ -247,6 +249,12 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
|
|||
isDescendant, err := l1.IsDescendant(p)
|
||||
assert.NoError(err)
|
||||
assert.False(isDescendant)
|
||||
isDescendant, err = l1.IsDescendant(nil)
|
||||
assert.NoError(err)
|
||||
assert.False(isDescendant)
|
||||
isDescendant, err = nilp.IsDescendant(p)
|
||||
assert.NoError(err)
|
||||
assert.False(isDescendant)
|
||||
isDescendant, err = p.IsDescendant(l1)
|
||||
assert.NoError(err)
|
||||
assert.True(isDescendant)
|
||||
|
@ -258,6 +266,12 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
|
|||
assert.NoError(err)
|
||||
assert.False(isAncestor)
|
||||
assert.Equal(l1, p.FirstSection())
|
||||
isAncestor, err = p.IsAncestor(nil)
|
||||
assert.NoError(err)
|
||||
assert.False(isAncestor)
|
||||
isAncestor, err = nilp.IsAncestor(l1)
|
||||
assert.NoError(err)
|
||||
assert.False(isAncestor)
|
||||
|
||||
}},
|
||||
{"perm a,link", func(p *Page) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue