compare, hugolib, tpl: Add Eqer interface

And use it in `eq` and `ne` so `Page` values can be compared directly in the templates without thinking about it being a `Page` or a `PageOutput` wrapper.

Fixes #3807
This commit is contained in:
Bjørn Erik Pedersen
2017-08-17 10:24:17 +02:00
parent 2fc121ce23
commit 08f48b91d6
4 changed files with 59 additions and 0 deletions

View File

@@ -26,6 +26,25 @@ import (
"github.com/stretchr/testify/require"
)
type tstEqerType1 string
type tstEqerType2 string
func (t tstEqerType2) Eq(other interface{}) bool {
return cast.ToString(t) == cast.ToString(other)
}
func (t tstEqerType2) String() string {
return string(t)
}
func (t tstEqerType1) Eq(other interface{}) bool {
return cast.ToString(t) == cast.ToString(other)
}
func (t tstEqerType1) String() string {
return string(t)
}
type tstCompareType int
const (
@@ -148,6 +167,10 @@ func doTestCompare(t *testing.T, tp tstCompareType, funcUnderTest func(a, b inte
{"a", "a", 0},
{"a", "b", -1},
{"b", "a", 1},
{tstEqerType1("a"), tstEqerType1("a"), 0},
{tstEqerType1("a"), tstEqerType2("a"), 0},
{tstEqerType2("a"), tstEqerType1("a"), 0},
{tstEqerType2("a"), tstEqerType1("b"), -1},
} {
result := funcUnderTest(test.left, test.right)
success := false