...
1
2
3
4 package toml_test
5
6 import (
7 "io/ioutil"
8 "strings"
9 "testing"
10
11 "github.com/pelletier/go-toml/v2"
12 "github.com/stretchr/testify/require"
13 )
14
15 func FuzzUnmarshal(f *testing.F) {
16 file, err := ioutil.ReadFile("benchmark/benchmark.toml")
17 if err != nil {
18 panic(err)
19 }
20 f.Add(file)
21
22 f.Fuzz(func(t *testing.T, b []byte) {
23 if strings.Contains(string(b), "nan") {
24
25
26 t.Skip("can't compare NaNs")
27 }
28
29 t.Log("INITIAL DOCUMENT ===========================")
30 t.Log(string(b))
31
32 var v interface{}
33 err := toml.Unmarshal(b, &v)
34 if err != nil {
35 return
36 }
37
38 t.Log("DECODED VALUE ===========================")
39 t.Logf("%#+v", v)
40
41 encoded, err := toml.Marshal(v)
42 if err != nil {
43 t.Fatalf("cannot marshal unmarshaled document: %s", err)
44 }
45
46 t.Log("ENCODED DOCUMENT ===========================")
47 t.Log(string(encoded))
48
49 var v2 interface{}
50 err = toml.Unmarshal(encoded, &v2)
51 if err != nil {
52 t.Fatalf("failed round trip: %s", err)
53 }
54 require.Equal(t, v, v2)
55 })
56 }
57
View as plain text