Skip to content

Commit 29e2c2f

Browse files
committed
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
1 parent 0579afc commit 29e2c2f

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

‎parser/metadecoders/decoder_integration_test.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ t:
3333
3434
-- layouts/all.html --
3535
{{ $mydata := resources.Get "mydata.yaml" | transform.Unmarshal }}
36+
Type: {{ printf "%T" $mydata.a.weight }}|
3637
Sorted: {{ sort $mydata "weight" }}|
3738
3839
`

‎tpl/compare/compare.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,11 @@ func (ns *Namespace) compareGet(a any, b any) (float64, float64) {
244244

245245
func (ns *Namespace) compareTwoUints(a uint64, b uint64) (float64, float64) {
246246
if a < b {
247-
return 1, 0
247+
return 0, 1
248248
} else if a == b {
249249
return 0, 0
250250
} else {
251-
return 0, 1
251+
return 1, 0
252252
}
253253
}
254254

‎tpl/compare/compare_test.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ func doTestCompare(t *testing.T, tp tstCompareType, funcUnderTest func(a, b any)
207207
{uint32(4), uint16(3), 1},
208208
{uint64(4), 4, 0},
209209
{4, uint64(4), 0},
210+
{uint64(4), 5, -1},
211+
{5, uint64(4), 1},
212+
{uint64(5), uint64(4), 1},
213+
{uint64(4), uint64(5), -1},
214+
{uint64(5), uint64(5), 0},
210215
{uint64(math.MaxUint32), uint32(math.MaxUint32), 0},
211216
{uint64(math.MaxUint16), int(math.MaxUint16), 0},
212217
{int16(4), int(5), -1},

0 commit comments

Comments
 (0)