From c0a26cb25413e31a1802d2f3d09b243ccab076bc Mon Sep 17 00:00:00 2001 From: Martin Tournoij Date: Tue, 10 Oct 2023 02:30:49 +0100 Subject: [PATCH] Write "inf" instead of "Inf" in JSON tests Doesn't really matter for the toml-test test runner, but we use toml-test-decoder for generating tests, and "Inf" with capital was causing issues for some: https://github.com/toml-lang/toml-test/pull/143 --- internal/tag/add.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/tag/add.go b/internal/tag/add.go index 07fc138b..1df6ee40 100644 --- a/internal/tag/add.go +++ b/internal/tag/add.go @@ -60,11 +60,16 @@ func Add(key string, tomlData any) any { case int64: return tag("integer", fmt.Sprintf("%d", orig)) case float64: - // Special case for nan since NaN == NaN is false. - if math.IsNaN(orig) { + switch { + case math.IsNaN(orig): return tag("float", "nan") + case math.IsInf(orig, 1): + return tag("float", "inf") + case math.IsInf(orig, -1): + return tag("float", "-inf") + default: + return tag("float", fmt.Sprintf("%v", orig)) } - return tag("float", fmt.Sprintf("%v", orig)) } }