mirror of
https://github.com/gohugoio/hugo.git
synced 2026-08-24 15:28:54 +00:00
tpl/compare: Fix compare/sort of uint64s
`uint64` is used by github.com/goccy/go-yaml for unsigned integers, which is the reason why this long-living bug has surfaced now. Fixes #14078
This commit is contained in:
@@ -33,6 +33,7 @@ t:
|
||||
|
||||
-- layouts/all.html --
|
||||
{{ $mydata := resources.Get "mydata.yaml" | transform.Unmarshal }}
|
||||
Type: {{ printf "%T" $mydata.a.weight }}|
|
||||
Sorted: {{ sort $mydata "weight" }}|
|
||||
|
||||
`
|
||||
|
||||
@@ -244,11 +244,11 @@ func (ns *Namespace) compareGet(a any, b any) (float64, float64) {
|
||||
|
||||
func (ns *Namespace) compareTwoUints(a uint64, b uint64) (float64, float64) {
|
||||
if a < b {
|
||||
return 1, 0
|
||||
return 0, 1
|
||||
} else if a == b {
|
||||
return 0, 0
|
||||
} else {
|
||||
return 0, 1
|
||||
return 1, 0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -207,6 +207,11 @@ func doTestCompare(t *testing.T, tp tstCompareType, funcUnderTest func(a, b any)
|
||||
{uint32(4), uint16(3), 1},
|
||||
{uint64(4), 4, 0},
|
||||
{4, uint64(4), 0},
|
||||
{uint64(4), 5, -1},
|
||||
{5, uint64(4), 1},
|
||||
{uint64(5), uint64(4), 1},
|
||||
{uint64(4), uint64(5), -1},
|
||||
{uint64(5), uint64(5), 0},
|
||||
{uint64(math.MaxUint32), uint32(math.MaxUint32), 0},
|
||||
{uint64(math.MaxUint16), int(math.MaxUint16), 0},
|
||||
{int16(4), int(5), -1},
|
||||
|
||||
Reference in New Issue
Block a user