hugolib: Simplify Page.Eq

This commit is contained in:
Bjørn Erik Pedersen 2017-08-17 09:43:39 +02:00
parent a7555c5431
commit 2a2e690707
2 changed files with 6 additions and 12 deletions

View file

@ -112,14 +112,13 @@ func (p *Page) IsAncestor(other interface{}) (bool, error) {
// Eq returns whether the current page equals the given page. // Eq returns whether the current page equals the given page.
// Note that this is more accurate than doing `{{ if eq $page $otherPage }}` // Note that this is more accurate than doing `{{ if eq $page $otherPage }}`
// since a Page can be embedded in another type. // since a Page can be embedded in another type.
func (p *Page) Eq(other interface{}) (bool, error) { func (p *Page) Eq(other interface{}) bool {
pp, err := unwrapPage(other) pp, err := unwrapPage(other)
if err != nil { if err != nil {
// Do not return an error on type mismatch. return false
return false, nil
} }
return p == pp, nil return p == pp
} }
func unwrapPage(in interface{}) (*Page, error) { func unwrapPage(in interface{}) (*Page, error) {

View file

@ -150,14 +150,9 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
assert.NotNil(d) assert.NotNil(d)
assert.Equal("T41_-1", d.Title) assert.Equal("T41_-1", d.Title)
equals, err := c.Eq(d) assert.False(c.Eq(d))
assert.NoError(err) assert.True(c.Eq(c))
assert.False(equals) assert.False(c.Eq("asdf"))
equals, err = c.Eq(c)
assert.NoError(err)
assert.True(equals)
_, err = c.Eq("asdf")
assert.Error(err)
}}, }},
{"empty3", func(p *Page) { {"empty3", func(p *Page) {