2021-01-16 16:16:26 +03:00
|
|
|
package json_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/goccy/go-json"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCoverUint8(t *testing.T) {
|
|
|
|
type structUint8 struct {
|
|
|
|
A uint8 `json:"a"`
|
|
|
|
}
|
2021-01-19 08:54:27 +03:00
|
|
|
type structUint8OmitEmpty struct {
|
|
|
|
A uint8 `json:"a,omitempty"`
|
|
|
|
}
|
|
|
|
type structUint8String struct {
|
|
|
|
A uint8 `json:"a,string"`
|
|
|
|
}
|
|
|
|
|
2021-01-16 16:16:26 +03:00
|
|
|
type structUint8Ptr struct {
|
|
|
|
A *uint8 `json:"a"`
|
|
|
|
}
|
2021-01-19 08:54:27 +03:00
|
|
|
type structUint8PtrOmitEmpty struct {
|
|
|
|
A *uint8 `json:"a,omitempty"`
|
|
|
|
}
|
|
|
|
type structUint8PtrString struct {
|
|
|
|
A *uint8 `json:"a,string"`
|
|
|
|
}
|
2021-01-16 16:16:26 +03:00
|
|
|
|
|
|
|
tests := []struct {
|
2021-02-15 05:27:37 +03:00
|
|
|
name string
|
|
|
|
data interface{}
|
2021-01-16 16:16:26 +03:00
|
|
|
}{
|
2021-01-19 08:54:27 +03:00
|
|
|
// HeadUint8Zero
|
2021-01-16 16:16:26 +03:00
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "HeadUint8Zero",
|
2021-01-16 16:16:26 +03:00
|
|
|
data: struct {
|
|
|
|
A uint8 `json:"a"`
|
|
|
|
}{},
|
|
|
|
},
|
2021-01-19 08:54:27 +03:00
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "HeadUint8ZeroOmitEmpty",
|
2021-01-19 08:54:27 +03:00
|
|
|
data: struct {
|
|
|
|
A uint8 `json:"a,omitempty"`
|
|
|
|
}{},
|
|
|
|
},
|
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "HeadUint8ZeroString",
|
2021-01-19 08:54:27 +03:00
|
|
|
data: struct {
|
|
|
|
A uint8 `json:"a,string"`
|
|
|
|
}{},
|
|
|
|
},
|
|
|
|
|
|
|
|
// HeadUint8
|
2021-01-16 16:16:26 +03:00
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "HeadUint8",
|
2021-01-16 16:16:26 +03:00
|
|
|
data: struct {
|
|
|
|
A uint8 `json:"a"`
|
|
|
|
}{A: 1},
|
|
|
|
},
|
2021-01-19 08:54:27 +03:00
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "HeadUint8OmitEmpty",
|
2021-01-19 08:54:27 +03:00
|
|
|
data: struct {
|
|
|
|
A uint8 `json:"a,omitempty"`
|
|
|
|
}{A: 1},
|
|
|
|
},
|
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "HeadUint8String",
|
2021-01-19 08:54:27 +03:00
|
|
|
data: struct {
|
|
|
|
A uint8 `json:"a,string"`
|
|
|
|
}{A: 1},
|
|
|
|
},
|
|
|
|
|
|
|
|
// HeadUint8Ptr
|
2021-01-16 16:16:26 +03:00
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "HeadUint8Ptr",
|
2021-01-16 16:16:26 +03:00
|
|
|
data: struct {
|
|
|
|
A *uint8 `json:"a"`
|
|
|
|
}{A: uint8ptr(1)},
|
|
|
|
},
|
2021-01-19 08:54:27 +03:00
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "HeadUint8PtrOmitEmpty",
|
2021-01-19 08:54:27 +03:00
|
|
|
data: struct {
|
|
|
|
A *uint8 `json:"a,omitempty"`
|
|
|
|
}{A: uint8ptr(1)},
|
|
|
|
},
|
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "HeadUint8PtrString",
|
2021-01-19 08:54:27 +03:00
|
|
|
data: struct {
|
|
|
|
A *uint8 `json:"a,string"`
|
|
|
|
}{A: uint8ptr(1)},
|
|
|
|
},
|
|
|
|
|
|
|
|
// HeadUint8PtrNil
|
2021-01-16 16:16:26 +03:00
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "HeadUint8PtrNil",
|
2021-01-16 16:16:26 +03:00
|
|
|
data: struct {
|
|
|
|
A *uint8 `json:"a"`
|
|
|
|
}{A: nil},
|
|
|
|
},
|
2021-01-19 08:54:27 +03:00
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "HeadUint8PtrNilOmitEmpty",
|
2021-01-19 08:54:27 +03:00
|
|
|
data: struct {
|
|
|
|
A *uint8 `json:"a,omitempty"`
|
|
|
|
}{A: nil},
|
|
|
|
},
|
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "HeadUint8PtrNilString",
|
2021-01-19 08:54:27 +03:00
|
|
|
data: struct {
|
|
|
|
A *uint8 `json:"a,string"`
|
|
|
|
}{A: nil},
|
|
|
|
},
|
|
|
|
|
|
|
|
// PtrHeadUint8Zero
|
2021-01-16 16:16:26 +03:00
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "PtrHeadUint8Zero",
|
2021-01-16 16:16:26 +03:00
|
|
|
data: &struct {
|
|
|
|
A uint8 `json:"a"`
|
|
|
|
}{},
|
|
|
|
},
|
2021-01-19 08:54:27 +03:00
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "PtrHeadUint8ZeroOmitEmpty",
|
2021-01-19 08:54:27 +03:00
|
|
|
data: &struct {
|
|
|
|
A uint8 `json:"a,omitempty"`
|
|
|
|
}{},
|
|
|
|
},
|
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "PtrHeadUint8ZeroString",
|
2021-01-19 08:54:27 +03:00
|
|
|
data: &struct {
|
|
|
|
A uint8 `json:"a,string"`
|
|
|
|
}{},
|
|
|
|
},
|
|
|
|
|
|
|
|
// PtrHeadUint8
|
2021-01-16 16:16:26 +03:00
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "PtrHeadUint8",
|
2021-01-16 16:16:26 +03:00
|
|
|
data: &struct {
|
|
|
|
A uint8 `json:"a"`
|
|
|
|
}{A: 1},
|
|
|
|
},
|
2021-01-19 08:54:27 +03:00
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "PtrHeadUint8OmitEmpty",
|
2021-01-19 08:54:27 +03:00
|
|
|
data: &struct {
|
|
|
|
A uint8 `json:"a,omitempty"`
|
|
|
|
}{A: 1},
|
|
|
|
},
|
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "PtrHeadUint8String",
|
2021-01-19 08:54:27 +03:00
|
|
|
data: &struct {
|
|
|
|
A uint8 `json:"a,string"`
|
|
|
|
}{A: 1},
|
|
|
|
},
|
|
|
|
|
|
|
|
// PtrHeadUint8Ptr
|
2021-01-16 16:16:26 +03:00
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "PtrHeadUint8Ptr",
|
2021-01-16 16:16:26 +03:00
|
|
|
data: &struct {
|
|
|
|
A *uint8 `json:"a"`
|
|
|
|
}{A: uint8ptr(1)},
|
|
|
|
},
|
2021-01-19 08:54:27 +03:00
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "PtrHeadUint8PtrOmitEmpty",
|
2021-01-19 08:54:27 +03:00
|
|
|
data: &struct {
|
|
|
|
A *uint8 `json:"a,omitempty"`
|
|
|
|
}{A: uint8ptr(1)},
|
|
|
|
},
|
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "PtrHeadUint8PtrString",
|
2021-01-19 08:54:27 +03:00
|
|
|
data: &struct {
|
|
|
|
A *uint8 `json:"a,string"`
|
|
|
|
}{A: uint8ptr(1)},
|
|
|
|
},
|
|
|
|
|
|
|
|
// PtrHeadUint8PtrNil
|
2021-01-16 16:16:26 +03:00
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "PtrHeadUint8PtrNil",
|
2021-01-16 16:16:26 +03:00
|
|
|
data: &struct {
|
|
|
|
A *uint8 `json:"a"`
|
|
|
|
}{A: nil},
|
|
|
|
},
|
2021-01-19 08:54:27 +03:00
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "PtrHeadUint8PtrNilOmitEmpty",
|
2021-01-19 08:54:27 +03:00
|
|
|
data: &struct {
|
|
|
|
A *uint8 `json:"a,omitempty"`
|
|
|
|
}{A: nil},
|
|
|
|
},
|
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "PtrHeadUint8PtrNilString",
|
2021-01-19 08:54:27 +03:00
|
|
|
data: &struct {
|
|
|
|
A *uint8 `json:"a,string"`
|
|
|
|
}{A: nil},
|
|
|
|
},
|
|
|
|
|
|
|
|
// PtrHeadUint8Nil
|
2021-01-16 16:16:26 +03:00
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "PtrHeadUint8Nil",
|
2021-01-16 16:16:26 +03:00
|
|
|
data: (*struct {
|
|
|
|
A *uint8 `json:"a"`
|
|
|
|
})(nil),
|
|
|
|
},
|
2021-01-19 08:54:27 +03:00
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "PtrHeadUint8NilOmitEmpty",
|
2021-01-19 08:54:27 +03:00
|
|
|
data: (*struct {
|
|
|
|
A *uint8 `json:"a,omitempty"`
|
|
|
|
})(nil),
|
|
|
|
},
|
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "PtrHeadUint8NilString",
|
2021-01-19 08:54:27 +03:00
|
|
|
data: (*struct {
|
|
|
|
A *uint8 `json:"a,string"`
|
|
|
|
})(nil),
|
|
|
|
},
|
|
|
|
|
|
|
|
// HeadUint8ZeroMultiFields
|
2021-01-16 16:16:26 +03:00
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "HeadUint8ZeroMultiFields",
|
2021-01-16 16:16:26 +03:00
|
|
|
data: struct {
|
|
|
|
A uint8 `json:"a"`
|
|
|
|
B uint8 `json:"b"`
|
2021-02-15 05:27:37 +03:00
|
|
|
C uint8 `json:"c"`
|
2021-01-16 16:16:26 +03:00
|
|
|
}{},
|
|
|
|
},
|
2021-01-19 08:54:27 +03:00
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "HeadUint8ZeroMultiFieldsOmitEmpty",
|
2021-01-19 08:54:27 +03:00
|
|
|
data: struct {
|
|
|
|
A uint8 `json:"a,omitempty"`
|
|
|
|
B uint8 `json:"b,omitempty"`
|
2021-02-15 05:27:37 +03:00
|
|
|
C uint8 `json:"c,omitempty"`
|
2021-01-19 08:54:27 +03:00
|
|
|
}{},
|
|
|
|
},
|
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "HeadUint8ZeroMultiFields",
|
2021-01-19 08:54:27 +03:00
|
|
|
data: struct {
|
|
|
|
A uint8 `json:"a,string"`
|
|
|
|
B uint8 `json:"b,string"`
|
2021-02-15 05:27:37 +03:00
|
|
|
C uint8 `json:"c,string"`
|
2021-01-19 08:54:27 +03:00
|
|
|
}{},
|
|
|
|
},
|
|
|
|
|
|
|
|
// HeadUint8MultiFields
|
2021-01-16 16:16:26 +03:00
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "HeadUint8MultiFields",
|
2021-01-16 16:16:26 +03:00
|
|
|
data: struct {
|
|
|
|
A uint8 `json:"a"`
|
|
|
|
B uint8 `json:"b"`
|
2021-02-15 05:27:37 +03:00
|
|
|
C uint8 `json:"c"`
|
|
|
|
}{A: 1, B: 2, C: 3},
|
2021-01-16 16:16:26 +03:00
|
|
|
},
|
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "HeadUint8MultiFieldsOmitEmpty",
|
2021-01-16 16:16:26 +03:00
|
|
|
data: struct {
|
2021-01-19 08:54:27 +03:00
|
|
|
A uint8 `json:"a,omitempty"`
|
|
|
|
B uint8 `json:"b,omitempty"`
|
2021-02-15 05:27:37 +03:00
|
|
|
C uint8 `json:"c,omitempty"`
|
|
|
|
}{A: 1, B: 2, C: 3},
|
2021-01-16 16:16:26 +03:00
|
|
|
},
|
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "HeadUint8MultiFieldsString",
|
2021-01-16 16:16:26 +03:00
|
|
|
data: struct {
|
2021-01-19 08:54:27 +03:00
|
|
|
A uint8 `json:"a,string"`
|
|
|
|
B uint8 `json:"b,string"`
|
2021-02-15 05:27:37 +03:00
|
|
|
C uint8 `json:"c,string"`
|
|
|
|
}{A: 1, B: 2, C: 3},
|
2021-01-16 16:16:26 +03:00
|
|
|
},
|
2021-01-19 08:54:27 +03:00
|
|
|
|
|
|
|
// HeadUint8PtrMultiFields
|
2021-01-16 16:16:26 +03:00
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "HeadUint8PtrMultiFields",
|
2021-01-19 08:54:27 +03:00
|
|
|
data: struct {
|
|
|
|
A *uint8 `json:"a"`
|
|
|
|
B *uint8 `json:"b"`
|
2021-02-15 05:27:37 +03:00
|
|
|
C *uint8 `json:"c"`
|
|
|
|
}{A: uint8ptr(1), B: uint8ptr(2), C: uint8ptr(3)},
|
2021-01-16 16:16:26 +03:00
|
|
|
},
|
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "HeadUint8PtrMultiFieldsOmitEmpty",
|
2021-01-19 08:54:27 +03:00
|
|
|
data: struct {
|
|
|
|
A *uint8 `json:"a,omitempty"`
|
|
|
|
B *uint8 `json:"b,omitempty"`
|
2021-02-15 05:27:37 +03:00
|
|
|
C *uint8 `json:"c,omitempty"`
|
|
|
|
}{A: uint8ptr(1), B: uint8ptr(2), C: uint8ptr(3)},
|
2021-01-16 16:16:26 +03:00
|
|
|
},
|
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "HeadUint8PtrMultiFieldsString",
|
2021-01-19 08:54:27 +03:00
|
|
|
data: struct {
|
|
|
|
A *uint8 `json:"a,string"`
|
|
|
|
B *uint8 `json:"b,string"`
|
2021-02-15 05:27:37 +03:00
|
|
|
C *uint8 `json:"c,string"`
|
|
|
|
}{A: uint8ptr(1), B: uint8ptr(2), C: uint8ptr(3)},
|
2021-01-16 16:16:26 +03:00
|
|
|
},
|
2021-01-19 08:54:27 +03:00
|
|
|
|
|
|
|
// HeadUint8PtrNilMultiFields
|
2021-01-16 16:16:26 +03:00
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "HeadUint8PtrNilMultiFields",
|
2021-01-19 08:54:27 +03:00
|
|
|
data: struct {
|
2021-01-16 16:16:26 +03:00
|
|
|
A *uint8 `json:"a"`
|
|
|
|
B *uint8 `json:"b"`
|
2021-02-15 05:27:37 +03:00
|
|
|
C *uint8 `json:"c"`
|
|
|
|
}{A: nil, B: nil, C: nil},
|
2021-01-16 16:16:26 +03:00
|
|
|
},
|
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "HeadUint8PtrNilMultiFieldsOmitEmpty",
|
2021-01-19 08:54:27 +03:00
|
|
|
data: struct {
|
|
|
|
A *uint8 `json:"a,omitempty"`
|
|
|
|
B *uint8 `json:"b,omitempty"`
|
2021-02-15 05:27:37 +03:00
|
|
|
C *uint8 `json:"c,omitempty"`
|
|
|
|
}{A: nil, B: nil, C: nil},
|
2021-01-16 16:16:26 +03:00
|
|
|
},
|
|
|
|
{
|
2021-02-15 05:27:37 +03:00
|
|
|
name: "HeadUint8PtrNilMultiFieldsString",
|
2021-01-19 08:54:27 +03:00
|
|