summaryrefslogtreecommitdiffhomepage
path: root/hugolib/site_sections_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2017-07-02 20:14:06 +0200
committerBjørn Erik Pedersen <[email protected]>2017-07-04 09:11:49 +0200
commita1d260b41a6673adef679ec4e262c5f390432cf5 (patch)
treef9a86343fb6a73defb0805578d25eb72c6afb534 /hugolib/site_sections_test.go
parentdd9b1baab0cb860a3eb32fd9043bac18cab3f9f0 (diff)
downloadhugo-a1d260b41a6673adef679ec4e262c5f390432cf5.tar.gz
hugo-a1d260b41a6673adef679ec4e262c5f390432cf5.zip
hugolib: Extend the sections API
This commit adds some section related methods that have been asked for: * .CurrentSection * .IsDescendant * .IsAncestor Fixes #3591
Diffstat (limited to 'hugolib/site_sections_test.go')
-rw-r--r--hugolib/site_sections_test.go36
1 files changed, 33 insertions, 3 deletions
diff --git a/hugolib/site_sections_test.go b/hugolib/site_sections_test.go
index 77a85099c..441391197 100644
--- a/hugolib/site_sections_test.go
+++ b/hugolib/site_sections_test.go
@@ -166,7 +166,7 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
home := p.Parent()
assert.True(home.IsHome())
assert.Len(p.Sections(), 0)
- assert.Equal(home, home.current())
+ assert.Equal(home, home.CurrentSection())
active, err := home.InSection(home)
assert.NoError(err)
assert.True(active)
@@ -187,7 +187,7 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
assert.Len(p.Sections(), 1)
for _, child := range p.Pages {
- assert.Equal(p, child.current())
+ assert.Equal(p, child.CurrentSection())
active, err := child.InSection(p)
assert.NoError(err)
assert.True(active)
@@ -197,9 +197,23 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
active, err = p.InSection(p.s.getPage(KindHome))
assert.NoError(err)
assert.False(active)
+
+ isAncestor, err := p.IsAncestor(child)
+ assert.NoError(err)
+ assert.True(isAncestor)
+ isAncestor, err = child.IsAncestor(p)
+ assert.NoError(err)
+ assert.False(isAncestor)
+
+ isDescendant, err := p.IsDescendant(child)
+ assert.NoError(err)
+ assert.False(isDescendant)
+ isDescendant, err = child.IsDescendant(p)
+ assert.NoError(err)
+ assert.True(isDescendant)
}
- assert.Equal(p, p.current())
+ assert.Equal(p, p.CurrentSection())
}},
{"l1,l2_2", func(p *Page) {
@@ -214,6 +228,22 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
assert.Len(p.Pages, 2)
assert.Equal("T2_-1", p.Parent().Title)
assert.Len(p.Sections(), 0)
+
+ l1 := p.s.getPage(KindSection, "l1")
+ isDescendant, err := l1.IsDescendant(p)
+ assert.NoError(err)
+ assert.False(isDescendant)
+ isDescendant, err = p.IsDescendant(l1)
+ assert.NoError(err)
+ assert.True(isDescendant)
+
+ isAncestor, err := l1.IsAncestor(p)
+ assert.NoError(err)
+ assert.True(isAncestor)
+ isAncestor, err = p.IsAncestor(l1)
+ assert.NoError(err)
+ assert.False(isAncestor)
+
}},
{"perm a,link", func(p *Page) {
assert.Equal("T9_-1", p.Title)