forked from tailscale/hujson
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuzz_test.go
More file actions
45 lines (37 loc) · 939 Bytes
/
fuzz_test.go
File metadata and controls
45 lines (37 loc) · 939 Bytes
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
// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//+build dev.fuzz
package hujson
import (
"bytes"
"encoding/json"
"testing"
"github.com/google/go-cmp/cmp"
)
func Fuzz(f *testing.F) {
for _, tt := range testdata {
f.Add([]byte(tt.in))
}
f.Fuzz(func(t *testing.T, b []byte) {
if len(b) > 1<<12 {
t.Skip("input too large")
}
// Parse for valid HuJSON input.
v, err := Parse(b)
if err != nil {
t.Skipf("input %q: Parse error: %v", b, err)
}
// Pack should preserve the original input exactly.
if b1 := v.Pack(); !bytes.Equal(b, b1) {
t.Fatalf("input %q: Pack mismatch: %s", b, cmp.Diff(b, b1))
}
// Standardize should produce valid JSON.
v2 := v.Clone()
v2.Standardize()
b2 := v2.Pack()
if !json.Valid(b2) {
t.Fatalf("input %q: Standardize failure", b)
}
})
}