aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/serializer/serializer_test.go
blob: e4efa67194a40f80977a5775d362b6222f216bb4 (plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright 2017 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.

package serializer

import (
	"bytes"
	"testing"

	"github.com/google/go-cmp/cmp"
)

func TestSerializer(t *testing.T) {
	x := &X{
		Y: Y{1},
		P: &Y{2},
		A: []Y{{3}, {4}},
		B: true,
		S: "a\x09b",
		T: T1,
		I: []interface{}{
			nil,
			Y{V: 42},
			new(Y),
			(*Y)(nil),
			0,
			42,
			T(0),
			T(42),
			U(96),
			false,
			B(false),
			"",
			"foo",
			S(""),
			S("foo"),
		},
		F: nil,
	}
	want := `&X{Y{1},&Y{2},[]Y{
{3},
{4},
},true,"a\tb",1,[]{
nil,
Y{},
&Y{},
nil,
0,
42,
T(0),
T(42),
U(96),
false,
B(false),
"",
"foo",
S(""),
S("foo"),
},nil}`
	buf := new(bytes.Buffer)
	Write(buf, x)
	if diff := cmp.Diff(want, buf.String()); diff != "" {
		t.Fatal(diff)
	}
}

type X struct {
	Y Y
	P *Y
	A []Y
	B bool
	S string
	T T
	I []interface{}
	F func()
}

type Y struct {
	V int
}

type (
	S string
	B bool
	T int
	U uint16
)

const (
	_ T = iota
	T1
)