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:
Bjørn Erik Pedersen
2025-10-22 12:13:02 +02:00
parent 0579afc3c5
commit 29e2c2fa92
3 changed files with 8 additions and 2 deletions
@@ -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" }}|
`
+2 -2
View File
@@ -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
}
}
+5
View File
@@ -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},