8bbb673431
* encode: fix localdate formatting * encode: fix empty key marshaling * encode: fix invalid quotation of time.Time * encode: ensure control chars are escaped * decode: always use UTC for zero tz * encode: check for invalid characters in keys * encode: always construct map for empty array tables * fuzz: add go 1.18 fuzz test * encode: handle NaNs * encode: allow new lines in quoted keys * encode: never emit table inside array * encode: don't capitalize inf
57 lines
1.1 KiB
Go
57 lines
1.1 KiB
Go
//go:build go1.18
|
|
// +build go1.18
|
|
|
|
package toml_test
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/pelletier/go-toml/v2"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func FuzzUnmarshal(f *testing.F) {
|
|
file, err := ioutil.ReadFile("benchmark/benchmark.toml")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
f.Add(file)
|
|
|
|
f.Fuzz(func(t *testing.T, b []byte) {
|
|
if strings.Contains(string(b), "nan") {
|
|
// Current limitation of testify.
|
|
// https://github.com/stretchr/testify/issues/624
|
|
t.Skip("can't compare NaNs")
|
|
}
|
|
|
|
t.Log("INITIAL DOCUMENT ===========================")
|
|
t.Log(string(b))
|
|
|
|
var v interface{}
|
|
err := toml.Unmarshal(b, &v)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
t.Log("DECODED VALUE ===========================")
|
|
t.Logf("%#+v", v)
|
|
|
|
encoded, err := toml.Marshal(v)
|
|
if err != nil {
|
|
t.Fatalf("cannot marshal unmarshaled document: %s", err)
|
|
}
|
|
|
|
t.Log("ENCODED DOCUMENT ===========================")
|
|
t.Log(string(encoded))
|
|
|
|
var v2 interface{}
|
|
err = toml.Unmarshal(encoded, &v2)
|
|
if err != nil {
|
|
t.Fatalf("failed round trip: %s", err)
|
|
}
|
|
require.Equal(t, v, v2)
|
|
})
|
|
}
|