mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-20 21:31:32 +02:00
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:
@@ -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
|
||||
|
Reference in New Issue
Block a user