[PR rtl-optimization/115877][2/n] Improve liveness computation for constant initializ...
[official-gcc.git] / libgo / go / encoding / json / fuzz_test.go
blob778664c3e57e28059ff2793d123282f45b9d4cf5
1 // Copyright 2021 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 package json
7 import (
8 "bytes"
9 "io"
10 "testing"
13 func FuzzUnmarshalJSON(f *testing.F) {
14 f.Add([]byte(`{
15 "object": {
16 "slice": [
18 2.0,
19 "3",
20 [4],
21 {5: {}}
24 "slice": [[]],
25 "string": ":)",
26 "int": 1e5,
27 "float": 3e-9"
28 }`))
30 f.Fuzz(func(t *testing.T, b []byte) {
31 for _, typ := range []func() interface{}{
32 func() interface{} { return new(interface{}) },
33 func() interface{} { return new(map[string]interface{}) },
34 func() interface{} { return new([]interface{}) },
35 } {
36 i := typ()
37 if err := Unmarshal(b, i); err != nil {
38 return
41 encoded, err := Marshal(i)
42 if err != nil {
43 t.Fatalf("failed to marshal: %s", err)
46 if err := Unmarshal(encoded, i); err != nil {
47 t.Fatalf("failed to roundtrip: %s", err)
53 func FuzzDecoderToken(f *testing.F) {
54 f.Add([]byte(`{
55 "object": {
56 "slice": [
58 2.0,
59 "3",
60 [4],
61 {5: {}}
64 "slice": [[]],
65 "string": ":)",
66 "int": 1e5,
67 "float": 3e-9"
68 }`))
70 f.Fuzz(func(t *testing.T, b []byte) {
71 r := bytes.NewReader(b)
72 d := NewDecoder(r)
73 for {
74 _, err := d.Token()
75 if err != nil {
76 if err == io.EOF {
77 break
79 return