File: fuzz_test.go

package info (click to toggle)
golang-toml 0.4.1%2Bgit20210923.e0af6a2-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,028 kB
  • sloc: makefile: 13; python: 11
file content (50 lines) | stat: -rw-r--r-- 812 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// +build gofuzzbeta

package toml

import (
	"bytes"
	"testing"
)

func FuzzDecode(f *testing.F) {
	buf := make([]byte, 0, 2048)

	f.Add(`
# This is a TOML document

title = "TOML Example"

[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00

[database]
enabled = true
ports = [ 8000, 8001, 8002 ]
data = [ ["delta", "phi"], [3.14] ]
temp_targets = { cpu = 79.5, case = 72.0 }

[servers]

[servers.alpha]
ip = "10.0.0.1"
role = "frontend"

[servers.beta]
ip = "10.0.0.2"
role = "backend"
`)
	f.Fuzz(func(t *testing.T, file string) {
		var m map[string]interface{}
		_, err := Decode(file, &m)
		if err != nil {
			t.Skip()
		}

		NewEncoder(bytes.NewBuffer(buf)).Encode(m)

		// TODO: should check if the output is equal to the input, too, but some
		// information is lost when encoding.
	})
}