// Values are formatted as with encoding/json.Marshal, with the following
// exceptions:
// - Floating-point NaNs and infinities are formatted as one of the strings
-// "NaN", "+Inf" or "-Inf".
+// "NaN", "Infinity" or "-Infinity".
// - Levels are formatted as with Level.String.
// - HTML characters are not escaped.
//
// json.Marshal fails on special floats, so handle them here.
switch {
case math.IsInf(f, 1):
- s.buf.WriteString(`"+Inf"`)
+ s.buf.WriteString(`"Infinity"`)
case math.IsInf(f, -1):
- s.buf.WriteString(`"-Inf"`)
+ s.buf.WriteString(`"-Infinity"`)
case math.IsNaN(f):
s.buf.WriteString(`"NaN"`)
default:
want string
}{
{math.NaN(), `"NaN"`},
- {math.Inf(+1), `"+Inf"`},
- {math.Inf(-1), `"-Inf"`},
+ {math.Inf(+1), `"Infinity"`},
+ {math.Inf(-1), `"-Infinity"`},
{LevelWarn, `"WARN"`},
} {
got := jsonValueString(t, AnyValue(test.value))