]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
tpl/compare: Fix compare/sort of uint64s
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 22 Oct 2025 10:13:02 +0000 (12:13 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 22 Oct 2025 11:40:03 +0000 (13:40 +0200)
`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

parser/metadecoders/decoder_integration_test.go
tpl/compare/compare.go
tpl/compare/compare_test.go

index 2e533c5e4b6b96295cbe53f3fe2635f6a02b0b62..9c8a15e8909f2f4693c95bf83e72339bfa8bc5c7 100644 (file)
@@ -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" }}|
 
 `
index d32f3df9511b7dca88e0d61714ec22449b17a3a6..c5eaa87f5c6b1a1b535ed51da2cfed33b07511bf 100644 (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
        }
 }
 
index 0ebebef4b8ee42c91904945e9dc12deb4d8b1fb2..c55322fe3b703e83a473935b34ade94b46dcc73d 100644 (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},