mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 18:53:35 +00:00
vendor files
This commit is contained in:
231
vendor/github.com/mailru/easyjson/tests/basic_test.go
generated
vendored
Normal file
231
vendor/github.com/mailru/easyjson/tests/basic_test.go
generated
vendored
Normal file
@ -0,0 +1,231 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"encoding/json"
|
||||
|
||||
"github.com/mailru/easyjson"
|
||||
"github.com/mailru/easyjson/jwriter"
|
||||
)
|
||||
|
||||
type testType interface {
|
||||
json.Marshaler
|
||||
json.Unmarshaler
|
||||
}
|
||||
|
||||
var testCases = []struct {
|
||||
Decoded testType
|
||||
Encoded string
|
||||
}{
|
||||
{&primitiveTypesValue, primitiveTypesString},
|
||||
{&namedPrimitiveTypesValue, namedPrimitiveTypesString},
|
||||
{&structsValue, structsString},
|
||||
{&omitEmptyValue, omitEmptyString},
|
||||
{&snakeStructValue, snakeStructString},
|
||||
{&omitEmptyDefaultValue, omitEmptyDefaultString},
|
||||
{&optsValue, optsString},
|
||||
{&rawValue, rawString},
|
||||
{&stdMarshalerValue, stdMarshalerString},
|
||||
{&userMarshalerValue, userMarshalerString},
|
||||
{&unexportedStructValue, unexportedStructString},
|
||||
{&excludedFieldValue, excludedFieldString},
|
||||
{&sliceValue, sliceString},
|
||||
{&arrayValue, arrayString},
|
||||
{&mapsValue, mapsString},
|
||||
{&deepNestValue, deepNestString},
|
||||
{&IntsValue, IntsString},
|
||||
{&mapStringStringValue, mapStringStringString},
|
||||
{&namedTypeValue, namedTypeValueString},
|
||||
{&mapMyIntStringValue, mapMyIntStringValueString},
|
||||
{&mapIntStringValue, mapIntStringValueString},
|
||||
{&mapInt32StringValue, mapInt32StringValueString},
|
||||
{&mapInt64StringValue, mapInt64StringValueString},
|
||||
{&mapUintStringValue, mapUintStringValueString},
|
||||
{&mapUint32StringValue, mapUint32StringValueString},
|
||||
{&mapUint64StringValue, mapUint64StringValueString},
|
||||
{&mapUintptrStringValue, mapUintptrStringValueString},
|
||||
{&intKeyedMapStructValue, intKeyedMapStructValueString},
|
||||
}
|
||||
|
||||
func TestMarshal(t *testing.T) {
|
||||
for i, test := range testCases {
|
||||
data, err := test.Decoded.MarshalJSON()
|
||||
if err != nil {
|
||||
t.Errorf("[%d, %T] MarshalJSON() error: %v", i, test.Decoded, err)
|
||||
}
|
||||
|
||||
got := string(data)
|
||||
if got != test.Encoded {
|
||||
t.Errorf("[%d, %T] MarshalJSON(): got \n%v\n\t\t want \n%v", i, test.Decoded, got, test.Encoded)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshal(t *testing.T) {
|
||||
for i, test := range testCases {
|
||||
v1 := reflect.New(reflect.TypeOf(test.Decoded).Elem()).Interface()
|
||||
v := v1.(testType)
|
||||
|
||||
err := v.UnmarshalJSON([]byte(test.Encoded))
|
||||
if err != nil {
|
||||
t.Errorf("[%d, %T] UnmarshalJSON() error: %v", i, test.Decoded, err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(v, test.Decoded) {
|
||||
t.Errorf("[%d, %T] UnmarshalJSON(): got \n%+v\n\t\t want \n%+v", i, test.Decoded, v, test.Decoded)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRawMessageSTD(t *testing.T) {
|
||||
type T struct {
|
||||
F easyjson.RawMessage
|
||||
Fnil easyjson.RawMessage
|
||||
}
|
||||
|
||||
val := T{F: easyjson.RawMessage([]byte(`"test"`))}
|
||||
str := `{"F":"test","Fnil":null}`
|
||||
|
||||
data, err := json.Marshal(val)
|
||||
if err != nil {
|
||||
t.Errorf("json.Marshal() error: %v", err)
|
||||
}
|
||||
got := string(data)
|
||||
if got != str {
|
||||
t.Errorf("json.Marshal() = %v; want %v", got, str)
|
||||
}
|
||||
|
||||
wantV := T{F: easyjson.RawMessage([]byte(`"test"`)), Fnil: easyjson.RawMessage([]byte("null"))}
|
||||
var gotV T
|
||||
|
||||
err = json.Unmarshal([]byte(str), &gotV)
|
||||
if err != nil {
|
||||
t.Errorf("json.Unmarshal() error: %v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(gotV, wantV) {
|
||||
t.Errorf("json.Unmarshal() = %v; want %v", gotV, wantV)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseNull(t *testing.T) {
|
||||
var got, want SubStruct
|
||||
if err := easyjson.Unmarshal([]byte("null"), &got); err != nil {
|
||||
t.Errorf("Unmarshal() error: %v", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("Unmarshal() = %+v; want %+v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
var testSpecialCases = []struct {
|
||||
EncodedString string
|
||||
Value string
|
||||
}{
|
||||
{`"Username \u003cuser@example.com\u003e"`, `Username <user@example.com>`},
|
||||
{`"Username\ufffd"`, "Username\xc5"},
|
||||
{`"тестzтест"`, "тестzтест"},
|
||||
{`"тест\ufffdтест"`, "тест\xc5тест"},
|
||||
{`"绿茶"`, "绿茶"},
|
||||
{`"绿\ufffd茶"`, "绿\xc5茶"},
|
||||
{`"тест\u2028"`, "тест\xE2\x80\xA8"},
|
||||
{`"\\\r\n\t\""`, "\\\r\n\t\""},
|
||||
{`"ü"`, "ü"},
|
||||
}
|
||||
|
||||
func TestSpecialCases(t *testing.T) {
|
||||
for i, test := range testSpecialCases {
|
||||
w := jwriter.Writer{}
|
||||
w.String(test.Value)
|
||||
got := string(w.Buffer.BuildBytes())
|
||||
if got != test.EncodedString {
|
||||
t.Errorf("[%d] Encoded() = %+v; want %+v", i, got, test.EncodedString)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestOverflowArray(t *testing.T) {
|
||||
var a Arrays
|
||||
err := easyjson.Unmarshal([]byte(arrayOverflowString), &a)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if a != arrayValue {
|
||||
t.Errorf("Unmarshal(%v) = %+v; want %+v", arrayOverflowString, a, arrayValue)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnderflowArray(t *testing.T) {
|
||||
var a Arrays
|
||||
err := easyjson.Unmarshal([]byte(arrayUnderflowString), &a)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if a != arrayUnderflowValue {
|
||||
t.Errorf("Unmarshal(%v) = %+v; want %+v", arrayUnderflowString, a, arrayUnderflowValue)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncodingFlags(t *testing.T) {
|
||||
for i, test := range []struct {
|
||||
Flags jwriter.Flags
|
||||
In easyjson.Marshaler
|
||||
Want string
|
||||
}{
|
||||
{0, EncodingFlagsTestMap{}, `{"F":null}`},
|
||||
{0, EncodingFlagsTestSlice{}, `{"F":null}`},
|
||||
{jwriter.NilMapAsEmpty, EncodingFlagsTestMap{}, `{"F":{}}`},
|
||||
{jwriter.NilSliceAsEmpty, EncodingFlagsTestSlice{}, `{"F":[]}`},
|
||||
} {
|
||||
w := &jwriter.Writer{Flags: test.Flags}
|
||||
test.In.MarshalEasyJSON(w)
|
||||
|
||||
data, err := w.BuildBytes()
|
||||
if err != nil {
|
||||
t.Errorf("[%v] easyjson.Marshal(%+v) error: %v", i, test.In, err)
|
||||
}
|
||||
|
||||
v := string(data)
|
||||
if v != test.Want {
|
||||
t.Errorf("[%v] easyjson.Marshal(%+v) = %v; want %v", i, test.In, v, test.Want)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestNestedEasyJsonMarshal(t *testing.T) {
|
||||
n := map[string]*NestedEasyMarshaler{
|
||||
"Value": {},
|
||||
"Slice1": {},
|
||||
"Slice2": {},
|
||||
"Map1": {},
|
||||
"Map2": {},
|
||||
}
|
||||
|
||||
ni := NestedInterfaces{
|
||||
Value: n["Value"],
|
||||
Slice: []interface{}{n["Slice1"], n["Slice2"]},
|
||||
Map: map[string]interface{}{"1": n["Map1"], "2": n["Map2"]},
|
||||
}
|
||||
easyjson.Marshal(ni)
|
||||
|
||||
for k, v := range n {
|
||||
if !v.EasilyMarshaled {
|
||||
t.Errorf("Nested interface %s wasn't easily marshaled", k)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalStructWithEmbeddedPtrStruct(t *testing.T) {
|
||||
var s = StructWithInterface{Field2: &EmbeddedStruct{}}
|
||||
var err error
|
||||
err = easyjson.Unmarshal([]byte(structWithInterfaceString), &s)
|
||||
if err != nil {
|
||||
t.Errorf("easyjson.Unmarshal() error: %v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(s, structWithInterfaceValueFilled) {
|
||||
t.Errorf("easyjson.Unmarshal() = %#v; want %#v", s, structWithInterfaceValueFilled)
|
||||
}
|
||||
}
|
759
vendor/github.com/mailru/easyjson/tests/data.go
generated
vendored
Normal file
759
vendor/github.com/mailru/easyjson/tests/data.go
generated
vendored
Normal file
@ -0,0 +1,759 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/mailru/easyjson"
|
||||
"github.com/mailru/easyjson/opt"
|
||||
)
|
||||
|
||||
type PrimitiveTypes struct {
|
||||
String string
|
||||
Bool bool
|
||||
|
||||
Int int
|
||||
Int8 int8
|
||||
Int16 int16
|
||||
Int32 int32
|
||||
Int64 int64
|
||||
|
||||
Uint uint
|
||||
Uint8 uint8
|
||||
Uint16 uint16
|
||||
Uint32 uint32
|
||||
Uint64 uint64
|
||||
|
||||
IntString int `json:",string"`
|
||||
Int8String int8 `json:",string"`
|
||||
Int16String int16 `json:",string"`
|
||||
Int32String int32 `json:",string"`
|
||||
Int64String int64 `json:",string"`
|
||||
|
||||
UintString uint `json:",string"`
|
||||
Uint8String uint8 `json:",string"`
|
||||
Uint16String uint16 `json:",string"`
|
||||
Uint32String uint32 `json:",string"`
|
||||
Uint64String uint64 `json:",string"`
|
||||
|
||||
Float32 float32
|
||||
Float64 float64
|
||||
|
||||
Ptr *string
|
||||
PtrNil *string
|
||||
}
|
||||
|
||||
var str = "bla"
|
||||
|
||||
var primitiveTypesValue = PrimitiveTypes{
|
||||
String: "test", Bool: true,
|
||||
|
||||
Int: math.MinInt32,
|
||||
Int8: math.MinInt8,
|
||||
Int16: math.MinInt16,
|
||||
Int32: math.MinInt32,
|
||||
Int64: math.MinInt64,
|
||||
|
||||
Uint: math.MaxUint32,
|
||||
Uint8: math.MaxUint8,
|
||||
Uint16: math.MaxUint16,
|
||||
Uint32: math.MaxUint32,
|
||||
Uint64: math.MaxUint64,
|
||||
|
||||
IntString: math.MinInt32,
|
||||
Int8String: math.MinInt8,
|
||||
Int16String: math.MinInt16,
|
||||
Int32String: math.MinInt32,
|
||||
Int64String: math.MinInt64,
|
||||
|
||||
UintString: math.MaxUint32,
|
||||
Uint8String: math.MaxUint8,
|
||||
Uint16String: math.MaxUint16,
|
||||
Uint32String: math.MaxUint32,
|
||||
Uint64String: math.MaxUint64,
|
||||
|
||||
Float32: 1.5,
|
||||
Float64: math.MaxFloat64,
|
||||
|
||||
Ptr: &str,
|
||||
}
|
||||
|
||||
var primitiveTypesString = "{" +
|
||||
`"String":"test","Bool":true,` +
|
||||
|
||||
`"Int":` + fmt.Sprint(math.MinInt32) + `,` +
|
||||
`"Int8":` + fmt.Sprint(math.MinInt8) + `,` +
|
||||
`"Int16":` + fmt.Sprint(math.MinInt16) + `,` +
|
||||
`"Int32":` + fmt.Sprint(math.MinInt32) + `,` +
|
||||
`"Int64":` + fmt.Sprint(int64(math.MinInt64)) + `,` +
|
||||
|
||||
`"Uint":` + fmt.Sprint(uint32(math.MaxUint32)) + `,` +
|
||||
`"Uint8":` + fmt.Sprint(math.MaxUint8) + `,` +
|
||||
`"Uint16":` + fmt.Sprint(math.MaxUint16) + `,` +
|
||||
`"Uint32":` + fmt.Sprint(uint32(math.MaxUint32)) + `,` +
|
||||
`"Uint64":` + fmt.Sprint(uint64(math.MaxUint64)) + `,` +
|
||||
|
||||
`"IntString":"` + fmt.Sprint(math.MinInt32) + `",` +
|
||||
`"Int8String":"` + fmt.Sprint(math.MinInt8) + `",` +
|
||||
`"Int16String":"` + fmt.Sprint(math.MinInt16) + `",` +
|
||||
`"Int32String":"` + fmt.Sprint(math.MinInt32) + `",` +
|
||||
`"Int64String":"` + fmt.Sprint(int64(math.MinInt64)) + `",` +
|
||||
|
||||
`"UintString":"` + fmt.Sprint(uint32(math.MaxUint32)) + `",` +
|
||||
`"Uint8String":"` + fmt.Sprint(math.MaxUint8) + `",` +
|
||||
`"Uint16String":"` + fmt.Sprint(math.MaxUint16) + `",` +
|
||||
`"Uint32String":"` + fmt.Sprint(uint32(math.MaxUint32)) + `",` +
|
||||
`"Uint64String":"` + fmt.Sprint(uint64(math.MaxUint64)) + `",` +
|
||||
|
||||
`"Float32":` + fmt.Sprint(1.5) + `,` +
|
||||
`"Float64":` + fmt.Sprint(math.MaxFloat64) + `,` +
|
||||
|
||||
`"Ptr":"bla",` +
|
||||
`"PtrNil":null` +
|
||||
|
||||
"}"
|
||||
|
||||
type (
|
||||
NamedString string
|
||||
NamedBool bool
|
||||
|
||||
NamedInt int
|
||||
NamedInt8 int8
|
||||
NamedInt16 int16
|
||||
NamedInt32 int32
|
||||
NamedInt64 int64
|
||||
|
||||
NamedUint uint
|
||||
NamedUint8 uint8
|
||||
NamedUint16 uint16
|
||||
NamedUint32 uint32
|
||||
NamedUint64 uint64
|
||||
|
||||
NamedFloat32 float32
|
||||
NamedFloat64 float64
|
||||
|
||||
NamedStrPtr *string
|
||||
)
|
||||
|
||||
type NamedPrimitiveTypes struct {
|
||||
String NamedString
|
||||
Bool NamedBool
|
||||
|
||||
Int NamedInt
|
||||
Int8 NamedInt8
|
||||
Int16 NamedInt16
|
||||
Int32 NamedInt32
|
||||
Int64 NamedInt64
|
||||
|
||||
Uint NamedUint
|
||||
Uint8 NamedUint8
|
||||
Uint16 NamedUint16
|
||||
Uint32 NamedUint32
|
||||
Uint64 NamedUint64
|
||||
|
||||
Float32 NamedFloat32
|
||||
Float64 NamedFloat64
|
||||
|
||||
Ptr NamedStrPtr
|
||||
PtrNil NamedStrPtr
|
||||
}
|
||||
|
||||
var namedPrimitiveTypesValue = NamedPrimitiveTypes{
|
||||
String: "test",
|
||||
Bool: true,
|
||||
|
||||
Int: math.MinInt32,
|
||||
Int8: math.MinInt8,
|
||||
Int16: math.MinInt16,
|
||||
Int32: math.MinInt32,
|
||||
Int64: math.MinInt64,
|
||||
|
||||
Uint: math.MaxUint32,
|
||||
Uint8: math.MaxUint8,
|
||||
Uint16: math.MaxUint16,
|
||||
Uint32: math.MaxUint32,
|
||||
Uint64: math.MaxUint64,
|
||||
|
||||
Float32: 1.5,
|
||||
Float64: math.MaxFloat64,
|
||||
|
||||
Ptr: NamedStrPtr(&str),
|
||||
}
|
||||
|
||||
var namedPrimitiveTypesString = "{" +
|
||||
`"String":"test",` +
|
||||
`"Bool":true,` +
|
||||
|
||||
`"Int":` + fmt.Sprint(math.MinInt32) + `,` +
|
||||
`"Int8":` + fmt.Sprint(math.MinInt8) + `,` +
|
||||
`"Int16":` + fmt.Sprint(math.MinInt16) + `,` +
|
||||
`"Int32":` + fmt.Sprint(math.MinInt32) + `,` +
|
||||
`"Int64":` + fmt.Sprint(int64(math.MinInt64)) + `,` +
|
||||
|
||||
`"Uint":` + fmt.Sprint(uint32(math.MaxUint32)) + `,` +
|
||||
`"Uint8":` + fmt.Sprint(math.MaxUint8) + `,` +
|
||||
`"Uint16":` + fmt.Sprint(math.MaxUint16) + `,` +
|
||||
`"Uint32":` + fmt.Sprint(uint32(math.MaxUint32)) + `,` +
|
||||
`"Uint64":` + fmt.Sprint(uint64(math.MaxUint64)) + `,` +
|
||||
|
||||
`"Float32":` + fmt.Sprint(1.5) + `,` +
|
||||
`"Float64":` + fmt.Sprint(math.MaxFloat64) + `,` +
|
||||
|
||||
`"Ptr":"bla",` +
|
||||
`"PtrNil":null` +
|
||||
"}"
|
||||
|
||||
type SubStruct struct {
|
||||
Value string
|
||||
Value2 string
|
||||
unexpored bool
|
||||
}
|
||||
|
||||
type SubP struct {
|
||||
V string
|
||||
}
|
||||
|
||||
type SubStructAlias SubStruct
|
||||
|
||||
type Structs struct {
|
||||
SubStruct
|
||||
*SubP
|
||||
|
||||
Value2 int
|
||||
|
||||
Sub1 SubStruct `json:"substruct"`
|
||||
Sub2 *SubStruct
|
||||
SubNil *SubStruct
|
||||
|
||||
SubSlice []SubStruct
|
||||
SubSliceNil []SubStruct
|
||||
|
||||
SubPtrSlice []*SubStruct
|
||||
SubPtrSliceNil []*SubStruct
|
||||
|
||||
SubA1 SubStructAlias
|
||||
SubA2 *SubStructAlias
|
||||
|
||||
Anonymous struct {
|
||||
V string
|
||||
I int
|
||||
}
|
||||
Anonymous1 *struct {
|
||||
V string
|
||||
}
|
||||
|
||||
AnonymousSlice []struct{ V int }
|
||||
AnonymousPtrSlice []*struct{ V int }
|
||||
|
||||
Slice []string
|
||||
|
||||
unexported bool
|
||||
}
|
||||
|
||||
var structsValue = Structs{
|
||||
SubStruct: SubStruct{Value: "test"},
|
||||
SubP: &SubP{V: "subp"},
|
||||
|
||||
Value2: 5,
|
||||
|
||||
Sub1: SubStruct{Value: "test1", Value2: "v"},
|
||||
Sub2: &SubStruct{Value: "test2", Value2: "v2"},
|
||||
|
||||
SubSlice: []SubStruct{
|
||||
{Value: "s1"},
|
||||
{Value: "s2"},
|
||||
},
|
||||
|
||||
SubPtrSlice: []*SubStruct{
|
||||
{Value: "p1"},
|
||||
{Value: "p2"},
|
||||
},
|
||||
|
||||
SubA1: SubStructAlias{Value: "test3", Value2: "v3"},
|
||||
SubA2: &SubStructAlias{Value: "test4", Value2: "v4"},
|
||||
|
||||
Anonymous: struct {
|
||||
V string
|
||||
I int
|
||||
}{V: "bla", I: 5},
|
||||
|
||||
Anonymous1: &struct {
|
||||
V string
|
||||
}{V: "bla1"},
|
||||
|
||||
AnonymousSlice: []struct{ V int }{{1}, {2}},
|
||||
AnonymousPtrSlice: []*struct{ V int }{{3}, {4}},
|
||||
|
||||
Slice: []string{"test5", "test6"},
|
||||
}
|
||||
|
||||
var structsString = "{" +
|
||||
`"Value2":5,` +
|
||||
|
||||
`"substruct":{"Value":"test1","Value2":"v"},` +
|
||||
`"Sub2":{"Value":"test2","Value2":"v2"},` +
|
||||
`"SubNil":null,` +
|
||||
|
||||
`"SubSlice":[{"Value":"s1","Value2":""},{"Value":"s2","Value2":""}],` +
|
||||
`"SubSliceNil":null,` +
|
||||
|
||||
`"SubPtrSlice":[{"Value":"p1","Value2":""},{"Value":"p2","Value2":""}],` +
|
||||
`"SubPtrSliceNil":null,` +
|
||||
|
||||
`"SubA1":{"Value":"test3","Value2":"v3"},` +
|
||||
`"SubA2":{"Value":"test4","Value2":"v4"},` +
|
||||
|
||||
`"Anonymous":{"V":"bla","I":5},` +
|
||||
`"Anonymous1":{"V":"bla1"},` +
|
||||
|
||||
`"AnonymousSlice":[{"V":1},{"V":2}],` +
|
||||
`"AnonymousPtrSlice":[{"V":3},{"V":4}],` +
|
||||
|
||||
`"Slice":["test5","test6"],` +
|
||||
|
||||
// Embedded fields go last.
|
||||
`"V":"subp",` +
|
||||
`"Value":"test"` +
|
||||
"}"
|
||||
|
||||
type OmitEmpty struct {
|
||||
// NOTE: first field is empty to test comma printing.
|
||||
|
||||
StrE, StrNE string `json:",omitempty"`
|
||||
PtrE, PtrNE *string `json:",omitempty"`
|
||||
|
||||
IntNE int `json:"intField,omitempty"`
|
||||
IntE int `json:",omitempty"`
|
||||
|
||||
// NOTE: omitempty has no effect on non-pointer struct fields.
|
||||
SubE, SubNE SubStruct `json:",omitempty"`
|
||||
SubPE, SubPNE *SubStruct `json:",omitempty"`
|
||||
}
|
||||
|
||||
var omitEmptyValue = OmitEmpty{
|
||||
StrNE: "str",
|
||||
PtrNE: &str,
|
||||
IntNE: 6,
|
||||
SubNE: SubStruct{Value: "1", Value2: "2"},
|
||||
SubPNE: &SubStruct{Value: "3", Value2: "4"},
|
||||
}
|
||||
|
||||
var omitEmptyString = "{" +
|
||||
`"StrNE":"str",` +
|
||||
`"PtrNE":"bla",` +
|
||||
`"intField":6,` +
|
||||
`"SubE":{"Value":"","Value2":""},` +
|
||||
`"SubNE":{"Value":"1","Value2":"2"},` +
|
||||
`"SubPNE":{"Value":"3","Value2":"4"}` +
|
||||
"}"
|
||||
|
||||
type Opts struct {
|
||||
StrNull opt.String
|
||||
StrEmpty opt.String
|
||||
Str opt.String
|
||||
StrOmitempty opt.String `json:",omitempty"`
|
||||
|
||||
IntNull opt.Int
|
||||
IntZero opt.Int
|
||||
Int opt.Int
|
||||
}
|
||||
|
||||
var optsValue = Opts{
|
||||
StrEmpty: opt.OString(""),
|
||||
Str: opt.OString("test"),
|
||||
|
||||
IntZero: opt.OInt(0),
|
||||
Int: opt.OInt(5),
|
||||
}
|
||||
|
||||
var optsString = `{` +
|
||||
`"StrNull":null,` +
|
||||
`"StrEmpty":"",` +
|
||||
`"Str":"test",` +
|
||||
`"IntNull":null,` +
|
||||
`"IntZero":0,` +
|
||||
`"Int":5` +
|
||||
`}`
|
||||
|
||||
type Raw struct {
|
||||
Field easyjson.RawMessage
|
||||
Field2 string
|
||||
}
|
||||
|
||||
var rawValue = Raw{
|
||||
Field: []byte(`{"a" : "b"}`),
|
||||
Field2: "test",
|
||||
}
|
||||
|
||||
var rawString = `{` +
|
||||
`"Field":{"a" : "b"},` +
|
||||
`"Field2":"test"` +
|
||||
`}`
|
||||
|
||||
type StdMarshaler struct {
|
||||
T time.Time
|
||||
IP net.IP
|
||||
}
|
||||
|
||||
var stdMarshalerValue = StdMarshaler{
|
||||
T: time.Date(2016, 01, 02, 14, 15, 10, 0, time.UTC),
|
||||
IP: net.IPv4(192, 168, 0, 1),
|
||||
}
|
||||
var stdMarshalerString = `{` +
|
||||
`"T":"2016-01-02T14:15:10Z",` +
|
||||
`"IP":"192.168.0.1"` +
|
||||
`}`
|
||||
|
||||
type UserMarshaler struct {
|
||||
V vMarshaler
|
||||
T tMarshaler
|
||||
}
|
||||
|
||||
type vMarshaler net.IP
|
||||
|
||||
func (v vMarshaler) MarshalJSON() ([]byte, error) {
|
||||
return []byte(`"0::0"`), nil
|
||||
}
|
||||
|
||||
func (v *vMarshaler) UnmarshalJSON([]byte) error {
|
||||
*v = vMarshaler(net.IPv6zero)
|
||||
return nil
|
||||
}
|
||||
|
||||
type tMarshaler net.IP
|
||||
|
||||
func (v tMarshaler) MarshalText() ([]byte, error) {
|
||||
return []byte(`[0::0]`), nil
|
||||
}
|
||||
|
||||
func (v *tMarshaler) UnmarshalText([]byte) error {
|
||||
*v = tMarshaler(net.IPv6zero)
|
||||
return nil
|
||||
}
|
||||
|
||||
var userMarshalerValue = UserMarshaler{
|
||||
V: vMarshaler(net.IPv6zero),
|
||||
T: tMarshaler(net.IPv6zero),
|
||||
}
|
||||
var userMarshalerString = `{` +
|
||||
`"V":"0::0",` +
|
||||
`"T":"[0::0]"` +
|
||||
`}`
|
||||
|
||||
type unexportedStruct struct {
|
||||
Value string
|
||||
}
|
||||
|
||||
var unexportedStructValue = unexportedStruct{"test"}
|
||||
var unexportedStructString = `{"Value":"test"}`
|
||||
|
||||
type ExcludedField struct {
|
||||
Process bool `json:"process"`
|
||||
DoNotProcess bool `json:"-"`
|
||||
DoNotProcess1 bool `json:"-"`
|
||||
}
|
||||
|
||||
var excludedFieldValue = ExcludedField{
|
||||
Process: true,
|
||||
DoNotProcess: false,
|
||||
DoNotProcess1: false,
|
||||
}
|
||||
var excludedFieldString = `{"process":true}`
|
||||
|
||||
type Slices struct {
|
||||
ByteSlice []byte
|
||||
EmptyByteSlice []byte
|
||||
NilByteSlice []byte
|
||||
IntSlice []int
|
||||
EmptyIntSlice []int
|
||||
NilIntSlice []int
|
||||
}
|
||||
|
||||
var sliceValue = Slices{
|
||||
ByteSlice: []byte("abc"),
|
||||
EmptyByteSlice: []byte{},
|
||||
NilByteSlice: []byte(nil),
|
||||
IntSlice: []int{1, 2, 3, 4, 5},
|
||||
EmptyIntSlice: []int{},
|
||||
NilIntSlice: []int(nil),
|
||||
}
|
||||
|
||||
var sliceString = `{` +
|
||||
`"ByteSlice":"YWJj",` +
|
||||
`"EmptyByteSlice":"",` +
|
||||
`"NilByteSlice":null,` +
|
||||
`"IntSlice":[1,2,3,4,5],` +
|
||||
`"EmptyIntSlice":[],` +
|
||||
`"NilIntSlice":null` +
|
||||
`}`
|
||||
|
||||
type Arrays struct {
|
||||
ByteArray [3]byte
|
||||
EmptyByteArray [0]byte
|
||||
IntArray [5]int
|
||||
EmptyIntArray [0]int
|
||||
}
|
||||
|
||||
var arrayValue = Arrays{
|
||||
ByteArray: [3]byte{'a', 'b', 'c'},
|
||||
EmptyByteArray: [0]byte{},
|
||||
IntArray: [5]int{1, 2, 3, 4, 5},
|
||||
EmptyIntArray: [0]int{},
|
||||
}
|
||||
|
||||
var arrayString = `{` +
|
||||
`"ByteArray":"YWJj",` +
|
||||
`"EmptyByteArray":"",` +
|
||||
`"IntArray":[1,2,3,4,5],` +
|
||||
`"EmptyIntArray":[]` +
|
||||
`}`
|
||||
|
||||
var arrayOverflowString = `{` +
|
||||
`"ByteArray":"YWJjbnNk",` +
|
||||
`"EmptyByteArray":"YWJj",` +
|
||||
`"IntArray":[1,2,3,4,5,6],` +
|
||||
`"EmptyIntArray":[7,8]` +
|
||||
`}`
|
||||
|
||||
var arrayUnderflowValue = Arrays{
|
||||
ByteArray: [3]byte{'x', 0, 0},
|
||||
EmptyByteArray: [0]byte{},
|
||||
IntArray: [5]int{1, 2, 0, 0, 0},
|
||||
EmptyIntArray: [0]int{},
|
||||
}
|
||||
|
||||
var arrayUnderflowString = `{` +
|
||||
`"ByteArray":"eA==",` +
|
||||
`"IntArray":[1,2]` +
|
||||
`}`
|
||||
|
||||
type Str string
|
||||
|
||||
type Maps struct {
|
||||
Map map[string]string
|
||||
InterfaceMap map[string]interface{}
|
||||
NilMap map[string]string
|
||||
|
||||
CustomMap map[Str]Str
|
||||
}
|
||||
|
||||
var mapsValue = Maps{
|
||||
Map: map[string]string{"A": "b"}, // only one item since map iteration is randomized
|
||||
InterfaceMap: map[string]interface{}{"G": float64(1)},
|
||||
|
||||
CustomMap: map[Str]Str{"c": "d"},
|
||||
}
|
||||
|
||||
var mapsString = `{` +
|
||||
`"Map":{"A":"b"},` +
|
||||
`"InterfaceMap":{"G":1},` +
|
||||
`"NilMap":null,` +
|
||||
`"CustomMap":{"c":"d"}` +
|
||||
`}`
|
||||
|
||||
type NamedSlice []Str
|
||||
type NamedMap map[Str]Str
|
||||
|
||||
type DeepNest struct {
|
||||
SliceMap map[Str][]Str
|
||||
SliceMap1 map[Str][]Str
|
||||
SliceMap2 map[Str][]Str
|
||||
NamedSliceMap map[Str]NamedSlice
|
||||
NamedMapMap map[Str]NamedMap
|
||||
MapSlice []map[Str]Str
|
||||
NamedSliceSlice []NamedSlice
|
||||
NamedMapSlice []NamedMap
|
||||
NamedStringSlice []NamedString
|
||||
}
|
||||
|
||||
var deepNestValue = DeepNest{
|
||||
SliceMap: map[Str][]Str{
|
||||
"testSliceMap": []Str{
|
||||
"0",
|
||||
"1",
|
||||
},
|
||||
},
|
||||
SliceMap1: map[Str][]Str{
|
||||
"testSliceMap1": []Str(nil),
|
||||
},
|
||||
SliceMap2: map[Str][]Str{
|
||||
"testSliceMap2": []Str{},
|
||||
},
|
||||
NamedSliceMap: map[Str]NamedSlice{
|
||||
"testNamedSliceMap": NamedSlice{
|
||||
"2",
|
||||
"3",
|
||||
},
|
||||
},
|
||||
NamedMapMap: map[Str]NamedMap{
|
||||
"testNamedMapMap": NamedMap{
|
||||
"key1": "value1",
|
||||
},
|
||||
},
|
||||
MapSlice: []map[Str]Str{
|
||||
map[Str]Str{
|
||||
"testMapSlice": "someValue",
|
||||
},
|
||||
},
|
||||
NamedSliceSlice: []NamedSlice{
|
||||
NamedSlice{
|
||||
"someValue1",
|
||||
"someValue2",
|
||||
},
|
||||
NamedSlice{
|
||||
"someValue3",
|
||||
"someValue4",
|
||||
},
|
||||
},
|
||||
NamedMapSlice: []NamedMap{
|
||||
NamedMap{
|
||||
"key2": "value2",
|
||||
},
|
||||
NamedMap{
|
||||
"key3": "value3",
|
||||
},
|
||||
},
|
||||
NamedStringSlice: []NamedString{
|
||||
"value4", "value5",
|
||||
},
|
||||
}
|
||||
|
||||
var deepNestString = `{` +
|
||||
`"SliceMap":{` +
|
||||
`"testSliceMap":["0","1"]` +
|
||||
`},` +
|
||||
`"SliceMap1":{` +
|
||||
`"testSliceMap1":null` +
|
||||
`},` +
|
||||
`"SliceMap2":{` +
|
||||
`"testSliceMap2":[]` +
|
||||
`},` +
|
||||
`"NamedSliceMap":{` +
|
||||
`"testNamedSliceMap":["2","3"]` +
|
||||
`},` +
|
||||
`"NamedMapMap":{` +
|
||||
`"testNamedMapMap":{"key1":"value1"}` +
|
||||
`},` +
|
||||
`"MapSlice":[` +
|
||||
`{"testMapSlice":"someValue"}` +
|
||||
`],` +
|
||||
`"NamedSliceSlice":[` +
|
||||
`["someValue1","someValue2"],` +
|
||||
`["someValue3","someValue4"]` +
|
||||
`],` +
|
||||
`"NamedMapSlice":[` +
|
||||
`{"key2":"value2"},` +
|
||||
`{"key3":"value3"}` +
|
||||
`],` +
|
||||
`"NamedStringSlice":["value4","value5"]` +
|
||||
`}`
|
||||
|
||||
//easyjson:json
|
||||
type Ints []int
|
||||
|
||||
var IntsValue = Ints{1, 2, 3, 4, 5}
|
||||
|
||||
var IntsString = `[1,2,3,4,5]`
|
||||
|
||||
//easyjson:json
|
||||
type MapStringString map[string]string
|
||||
|
||||
var mapStringStringValue = MapStringString{"a": "b"}
|
||||
|
||||
var mapStringStringString = `{"a":"b"}`
|
||||
|
||||
type RequiredOptionalStruct struct {
|
||||
FirstName string `json:"first_name,required"`
|
||||
Lastname string `json:"last_name"`
|
||||
}
|
||||
|
||||
//easyjson:json
|
||||
type EncodingFlagsTestMap struct {
|
||||
F map[string]string
|
||||
}
|
||||
|
||||
//easyjson:json
|
||||
type EncodingFlagsTestSlice struct {
|
||||
F []string
|
||||
}
|
||||
|
||||
type StructWithInterface struct {
|
||||
Field1 int `json:"f1"`
|
||||
Field2 interface{} `json:"f2"`
|
||||
Field3 string `json:"f3"`
|
||||
}
|
||||
|
||||
type EmbeddedStruct struct {
|
||||
Field1 int `json:"f1"`
|
||||
Field2 string `json:"f2"`
|
||||
}
|
||||
|
||||
var structWithInterfaceString = `{"f1":1,"f2":{"f1":11,"f2":"22"},"f3":"3"}`
|
||||
var structWithInterfaceValueFilled = StructWithInterface{1, &EmbeddedStruct{11, "22"}, "3"}
|
||||
|
||||
//easyjson:json
|
||||
type MapIntString map[int]string
|
||||
|
||||
var mapIntStringValue = MapIntString{3: "hi"}
|
||||
var mapIntStringValueString = `{"3":"hi"}`
|
||||
|
||||
//easyjson:json
|
||||
type MapInt32String map[int32]string
|
||||
|
||||
var mapInt32StringValue = MapInt32String{-354634382: "life"}
|
||||
var mapInt32StringValueString = `{"-354634382":"life"}`
|
||||
|
||||
//easyjson:json
|
||||
type MapInt64String map[int64]string
|
||||
|
||||
var mapInt64StringValue = MapInt64String{-3546343826724305832: "life"}
|
||||
var mapInt64StringValueString = `{"-3546343826724305832":"life"}`
|
||||
|
||||
//easyjson:json
|
||||
type MapUintString map[uint]string
|
||||
|
||||
var mapUintStringValue = MapUintString{42: "life"}
|
||||
var mapUintStringValueString = `{"42":"life"}`
|
||||
|
||||
//easyjson:json
|
||||
type MapUint32String map[uint32]string
|
||||
|
||||
var mapUint32StringValue = MapUint32String{354634382: "life"}
|
||||
var mapUint32StringValueString = `{"354634382":"life"}`
|
||||
|
||||
//easyjson:json
|
||||
type MapUint64String map[uint64]string
|
||||
|
||||
var mapUint64StringValue = MapUint64String{3546343826724305832: "life"}
|
||||
var mapUint64StringValueString = `{"3546343826724305832":"life"}`
|
||||
|
||||
//easyjson:json
|
||||
type MapUintptrString map[uintptr]string
|
||||
|
||||
var mapUintptrStringValue = MapUintptrString{272679208: "obj"}
|
||||
var mapUintptrStringValueString = `{"272679208":"obj"}`
|
||||
|
||||
type MyInt int
|
||||
|
||||
//easyjson:json
|
||||
type MapMyIntString map[MyInt]string
|
||||
|
||||
var mapMyIntStringValue = MapMyIntString{MyInt(42): "life"}
|
||||
var mapMyIntStringValueString = `{"42":"life"}`
|
||||
|
||||
//easyjson:json
|
||||
type IntKeyedMapStruct struct {
|
||||
Foo MapMyIntString `json:"foo"`
|
||||
Bar map[int16]MapUint32String `json:"bar"`
|
||||
}
|
||||
|
||||
var intKeyedMapStructValue = IntKeyedMapStruct{
|
||||
Foo: mapMyIntStringValue,
|
||||
Bar: map[int16]MapUint32String{32: mapUint32StringValue},
|
||||
}
|
||||
var intKeyedMapStructValueString = `{` +
|
||||
`"foo":{"42":"life"},` +
|
||||
`"bar":{"32":{"354634382":"life"}}` +
|
||||
`}`
|
26
vendor/github.com/mailru/easyjson/tests/errors.go
generated
vendored
Normal file
26
vendor/github.com/mailru/easyjson/tests/errors.go
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
package tests
|
||||
|
||||
//easyjson:json
|
||||
type ErrorIntSlice []int
|
||||
|
||||
//easyjson:json
|
||||
type ErrorBoolSlice []bool
|
||||
|
||||
//easyjson:json
|
||||
type ErrorUintSlice []uint
|
||||
|
||||
//easyjson:json
|
||||
type ErrorStruct struct {
|
||||
Int int `json:"int"`
|
||||
String string `json:"string"`
|
||||
Slice []int `json:"slice"`
|
||||
IntSlice []int `json:"int_slice"`
|
||||
}
|
||||
|
||||
type ErrorNestedStruct struct {
|
||||
ErrorStruct ErrorStruct `json:"error_struct"`
|
||||
Int int `json:"int"`
|
||||
}
|
||||
|
||||
//easyjson:json
|
||||
type ErrorIntMap map[uint32]string
|
285
vendor/github.com/mailru/easyjson/tests/errors_test.go
generated
vendored
Normal file
285
vendor/github.com/mailru/easyjson/tests/errors_test.go
generated
vendored
Normal file
@ -0,0 +1,285 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mailru/easyjson/jlexer"
|
||||
)
|
||||
|
||||
func TestMultipleErrorsInt(t *testing.T) {
|
||||
for i, test := range []struct {
|
||||
Data []byte
|
||||
Offsets []int
|
||||
}{
|
||||
{
|
||||
Data: []byte(`[1, 2, 3, "4", "5"]`),
|
||||
Offsets: []int{10, 15},
|
||||
},
|
||||
{
|
||||
Data: []byte(`[1, {"2":"3"}, 3, "4"]`),
|
||||
Offsets: []int{4, 18},
|
||||
},
|
||||
{
|
||||
Data: []byte(`[1, "2", "3", "4", "5", "6"]`),
|
||||
Offsets: []int{4, 9, 14, 19, 24},
|
||||
},
|
||||
{
|
||||
Data: []byte(`[1, 2, 3, 4, "5"]`),
|
||||
Offsets: []int{13},
|
||||
},
|
||||
{
|
||||
Data: []byte(`[{"1": "2"}]`),
|
||||
Offsets: []int{1},
|
||||
},
|
||||
} {
|
||||
l := jlexer.Lexer{
|
||||
Data: test.Data,
|
||||
UseMultipleErrors: true,
|
||||
}
|
||||
|
||||
var v ErrorIntSlice
|
||||
|
||||
v.UnmarshalEasyJSON(&l)
|
||||
|
||||
errors := l.GetNonFatalErrors()
|
||||
|
||||
if len(errors) != len(test.Offsets) {
|
||||
t.Errorf("[%d] TestMultipleErrorsInt(): errornum: want: %d, got %d", i, len(test.Offsets), len(errors))
|
||||
return
|
||||
}
|
||||
|
||||
for ii, e := range errors {
|
||||
if e.Offset != test.Offsets[ii] {
|
||||
t.Errorf("[%d] TestMultipleErrorsInt(): offset[%d]: want %d, got %d", i, ii, test.Offsets[ii], e.Offset)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMultipleErrorsBool(t *testing.T) {
|
||||
for i, test := range []struct {
|
||||
Data []byte
|
||||
Offsets []int
|
||||
}{
|
||||
{
|
||||
Data: []byte(`[true, false, true, false]`),
|
||||
},
|
||||
{
|
||||
Data: []byte(`["test", "value", "lol", "1"]`),
|
||||
Offsets: []int{1, 9, 18, 25},
|
||||
},
|
||||
{
|
||||
Data: []byte(`[true, 42, {"a":"b", "c":"d"}, false]`),
|
||||
Offsets: []int{7, 11},
|
||||
},
|
||||
} {
|
||||
l := jlexer.Lexer{
|
||||
Data: test.Data,
|
||||
UseMultipleErrors: true,
|
||||
}
|
||||
|
||||
var v ErrorBoolSlice
|
||||
v.UnmarshalEasyJSON(&l)
|
||||
|
||||
errors := l.GetNonFatalErrors()
|
||||
|
||||
if len(errors) != len(test.Offsets) {
|
||||
t.Errorf("[%d] TestMultipleErrorsBool(): errornum: want: %d, got %d", i, len(test.Offsets), len(errors))
|
||||
return
|
||||
}
|
||||
for ii, e := range errors {
|
||||
if e.Offset != test.Offsets[ii] {
|
||||
t.Errorf("[%d] TestMultipleErrorsBool(): offset[%d]: want %d, got %d", i, ii, test.Offsets[ii], e.Offset)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMultipleErrorsUint(t *testing.T) {
|
||||
for i, test := range []struct {
|
||||
Data []byte
|
||||
Offsets []int
|
||||
}{
|
||||
{
|
||||
Data: []byte(`[42, 42, 42]`),
|
||||
},
|
||||
{
|
||||
Data: []byte(`[17, "42", 32]`),
|
||||
Offsets: []int{5},
|
||||
},
|
||||
{
|
||||
Data: []byte(`["zz", "zz"]`),
|
||||
Offsets: []int{1, 7},
|
||||
},
|
||||
{
|
||||
Data: []byte(`[{}, 42]`),
|
||||
Offsets: []int{1},
|
||||
},
|
||||
} {
|
||||
l := jlexer.Lexer{
|
||||
Data: test.Data,
|
||||
UseMultipleErrors: true,
|
||||
}
|
||||
|
||||
var v ErrorUintSlice
|
||||
v.UnmarshalEasyJSON(&l)
|
||||
|
||||
errors := l.GetNonFatalErrors()
|
||||
|
||||
if len(errors) != len(test.Offsets) {
|
||||
t.Errorf("[%d] TestMultipleErrorsUint(): errornum: want: %d, got %d", i, len(test.Offsets), len(errors))
|
||||
return
|
||||
}
|
||||
for ii, e := range errors {
|
||||
if e.Offset != test.Offsets[ii] {
|
||||
t.Errorf("[%d] TestMultipleErrorsUint(): offset[%d]: want %d, got %d", i, ii, test.Offsets[ii], e.Offset)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMultipleErrorsStruct(t *testing.T) {
|
||||
for i, test := range []struct {
|
||||
Data []byte
|
||||
Offsets []int
|
||||
}{
|
||||
{
|
||||
Data: []byte(`{"string": "test", "slice":[42, 42, 42], "int_slice":[1, 2, 3]}`),
|
||||
},
|
||||
{
|
||||
Data: []byte(`{"string": {"test": "test"}, "slice":[42, 42, 42], "int_slice":["1", 2, 3]}`),
|
||||
Offsets: []int{11, 64},
|
||||
},
|
||||
{
|
||||
Data: []byte(`{"slice": [42, 42], "string": {"test": "test"}, "int_slice":["1", "2", 3]}`),
|
||||
Offsets: []int{30, 61, 66},
|
||||
},
|
||||
{
|
||||
Data: []byte(`{"string": "test", "slice": {}}`),
|
||||
Offsets: []int{28},
|
||||
},
|
||||
{
|
||||
Data: []byte(`{"slice":5, "string" : "test"}`),
|
||||
Offsets: []int{9},
|
||||
},
|
||||
{
|
||||
Data: []byte(`{"slice" : "test", "string" : "test"}`),
|
||||
Offsets: []int{11},
|
||||
},
|
||||
{
|
||||
Data: []byte(`{"slice": "", "string" : {}, "int":{}}`),
|
||||
Offsets: []int{10, 25, 35},
|
||||
},
|
||||
} {
|
||||
l := jlexer.Lexer{
|
||||
Data: test.Data,
|
||||
UseMultipleErrors: true,
|
||||
}
|
||||
var v ErrorStruct
|
||||
v.UnmarshalEasyJSON(&l)
|
||||
|
||||
errors := l.GetNonFatalErrors()
|
||||
|
||||
if len(errors) != len(test.Offsets) {
|
||||
t.Errorf("[%d] TestMultipleErrorsStruct(): errornum: want: %d, got %d", i, len(test.Offsets), len(errors))
|
||||
return
|
||||
}
|
||||
for ii, e := range errors {
|
||||
if e.Offset != test.Offsets[ii] {
|
||||
t.Errorf("[%d] TestMultipleErrorsStruct(): offset[%d]: want %d, got %d", i, ii, test.Offsets[ii], e.Offset)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMultipleErrorsNestedStruct(t *testing.T) {
|
||||
for i, test := range []struct {
|
||||
Data []byte
|
||||
Offsets []int
|
||||
}{
|
||||
{
|
||||
Data: []byte(`{"error_struct":{}}`),
|
||||
},
|
||||
{
|
||||
Data: []byte(`{"error_struct":5}`),
|
||||
Offsets: []int{16},
|
||||
},
|
||||
{
|
||||
Data: []byte(`{"error_struct":[]}`),
|
||||
Offsets: []int{16},
|
||||
},
|
||||
{
|
||||
Data: []byte(`{"error_struct":{"int":{}}}`),
|
||||
Offsets: []int{23},
|
||||
},
|
||||
{
|
||||
Data: []byte(`{"error_struct":{"int_slice":{}}, "int":4}`),
|
||||
Offsets: []int{29},
|
||||
},
|
||||
{
|
||||
Data: []byte(`{"error_struct":{"int_slice":["1", 2, "3"]}, "int":[]}`),
|
||||
Offsets: []int{30, 38, 51},
|
||||
},
|
||||
} {
|
||||
l := jlexer.Lexer{
|
||||
Data: test.Data,
|
||||
UseMultipleErrors: true,
|
||||
}
|
||||
var v ErrorNestedStruct
|
||||
v.UnmarshalEasyJSON(&l)
|
||||
|
||||
errors := l.GetNonFatalErrors()
|
||||
|
||||
if len(errors) != len(test.Offsets) {
|
||||
t.Errorf("[%d] TestMultipleErrorsNestedStruct(): errornum: want: %d, got %d", i, len(test.Offsets), len(errors))
|
||||
return
|
||||
}
|
||||
for ii, e := range errors {
|
||||
if e.Offset != test.Offsets[ii] {
|
||||
t.Errorf("[%d] TestMultipleErrorsNestedStruct(): offset[%d]: want %d, got %d", i, ii, test.Offsets[ii], e.Offset)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMultipleErrorsIntMap(t *testing.T) {
|
||||
for i, test := range []struct {
|
||||
Data []byte
|
||||
Offsets []int
|
||||
}{
|
||||
{
|
||||
Data: []byte(`{"a":"NumErr"}`),
|
||||
Offsets: []int{1},
|
||||
},
|
||||
{
|
||||
Data: []byte(`{"":"ErrSyntax"}`),
|
||||
Offsets: []int{1},
|
||||
},
|
||||
{
|
||||
Data: []byte(`{"a":"NumErr","33147483647":"ErrRange","-1":"ErrRange"}`),
|
||||
Offsets: []int{1, 14, 39},
|
||||
},
|
||||
} {
|
||||
l := jlexer.Lexer{
|
||||
Data: test.Data,
|
||||
UseMultipleErrors: true,
|
||||
}
|
||||
|
||||
var v ErrorIntMap
|
||||
|
||||
v.UnmarshalEasyJSON(&l)
|
||||
|
||||
errors := l.GetNonFatalErrors()
|
||||
|
||||
if len(errors) != len(test.Offsets) {
|
||||
t.Errorf("[%d] TestMultipleErrorsInt(): errornum: want: %d, got %d", i, len(test.Offsets), len(errors))
|
||||
return
|
||||
}
|
||||
|
||||
for ii, e := range errors {
|
||||
if e.Offset != test.Offsets[ii] {
|
||||
t.Errorf("[%d] TestMultipleErrorsInt(): offset[%d]: want %d, got %d", i, ii, test.Offsets[ii], e.Offset)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
22
vendor/github.com/mailru/easyjson/tests/named_type.go
generated
vendored
Normal file
22
vendor/github.com/mailru/easyjson/tests/named_type.go
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
package tests
|
||||
|
||||
//easyjson:json
|
||||
type NamedType struct {
|
||||
Inner struct {
|
||||
// easyjson is mistakenly naming the type of this field 'tests.MyString' in the generated output
|
||||
// something about a named type inside an anonmymous type is triggering this bug
|
||||
Field MyString `tag:"value"`
|
||||
Field2 int "tag:\"value with ` in it\""
|
||||
}
|
||||
}
|
||||
|
||||
type MyString string
|
||||
|
||||
var namedTypeValue NamedType
|
||||
|
||||
func init() {
|
||||
namedTypeValue.Inner.Field = "test"
|
||||
namedTypeValue.Inner.Field2 = 123
|
||||
}
|
||||
|
||||
var namedTypeValueString = `{"Inner":{"Field":"test","Field2":123}}`
|
25
vendor/github.com/mailru/easyjson/tests/nested_easy.go
generated
vendored
Normal file
25
vendor/github.com/mailru/easyjson/tests/nested_easy.go
generated
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"github.com/mailru/easyjson"
|
||||
"github.com/mailru/easyjson/jwriter"
|
||||
)
|
||||
|
||||
//easyjson:json
|
||||
type NestedInterfaces struct {
|
||||
Value interface{}
|
||||
Slice []interface{}
|
||||
Map map[string]interface{}
|
||||
}
|
||||
|
||||
type NestedEasyMarshaler struct {
|
||||
EasilyMarshaled bool
|
||||
}
|
||||
|
||||
var _ easyjson.Marshaler = &NestedEasyMarshaler{}
|
||||
|
||||
func (i *NestedEasyMarshaler) MarshalEasyJSON(w *jwriter.Writer) {
|
||||
// We use this method only to indicate that easyjson.Marshaler
|
||||
// interface was really used while encoding.
|
||||
i.EasilyMarshaled = true
|
||||
}
|
3
vendor/github.com/mailru/easyjson/tests/nothing.go
generated
vendored
Normal file
3
vendor/github.com/mailru/easyjson/tests/nothing.go
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
package tests
|
||||
|
||||
// No structs in this file
|
12
vendor/github.com/mailru/easyjson/tests/omitempty.go
generated
vendored
Normal file
12
vendor/github.com/mailru/easyjson/tests/omitempty.go
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
package tests
|
||||
|
||||
//easyjson:json
|
||||
type OmitEmptyDefault struct {
|
||||
Field string
|
||||
Str string
|
||||
Str1 string `json:"s,!omitempty"`
|
||||
Str2 string `json:",!omitempty"`
|
||||
}
|
||||
|
||||
var omitEmptyDefaultValue = OmitEmptyDefault{Field: "test"}
|
||||
var omitEmptyDefaultString = `{"Field":"test","s":"","Str2":""}`
|
70
vendor/github.com/mailru/easyjson/tests/opt_test.go
generated
vendored
Normal file
70
vendor/github.com/mailru/easyjson/tests/opt_test.go
generated
vendored
Normal file
@ -0,0 +1,70 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"math"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"encoding/json"
|
||||
|
||||
"github.com/mailru/easyjson/opt"
|
||||
)
|
||||
|
||||
// This struct type must NOT have a generated marshaler
|
||||
type OptsVanilla struct {
|
||||
Int opt.Int
|
||||
Uint opt.Uint
|
||||
|
||||
Int8 opt.Int8
|
||||
Int16 opt.Int16
|
||||
Int32 opt.Int32
|
||||
Int64 opt.Int64
|
||||
|
||||
Uint8 opt.Uint8
|
||||
Uint16 opt.Uint16
|
||||
Uint32 opt.Uint32
|
||||
Uint64 opt.Uint64
|
||||
|
||||
Float32 opt.Float32
|
||||
Float64 opt.Float64
|
||||
|
||||
Bool opt.Bool
|
||||
String opt.String
|
||||
}
|
||||
|
||||
var optsVanillaValue = OptsVanilla{
|
||||
Int: opt.OInt(-123),
|
||||
Uint: opt.OUint(123),
|
||||
|
||||
Int8: opt.OInt8(math.MaxInt8),
|
||||
Int16: opt.OInt16(math.MaxInt16),
|
||||
Int32: opt.OInt32(math.MaxInt32),
|
||||
Int64: opt.OInt64(math.MaxInt64),
|
||||
|
||||
Uint8: opt.OUint8(math.MaxUint8),
|
||||
Uint16: opt.OUint16(math.MaxUint16),
|
||||
Uint32: opt.OUint32(math.MaxUint32),
|
||||
Uint64: opt.OUint64(math.MaxUint64),
|
||||
|
||||
Float32: opt.OFloat32(math.MaxFloat32),
|
||||
Float64: opt.OFloat64(math.MaxFloat64),
|
||||
|
||||
Bool: opt.OBool(true),
|
||||
String: opt.OString("foo"),
|
||||
}
|
||||
|
||||
func TestOptsVanilla(t *testing.T) {
|
||||
data, err := json.Marshal(optsVanillaValue)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to marshal vanilla opts: %v", err)
|
||||
}
|
||||
|
||||
var ov OptsVanilla
|
||||
if err := json.Unmarshal(data, &ov); err != nil {
|
||||
t.Errorf("Failed to unmarshal vanilla opts: %v", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(optsVanillaValue, ov) {
|
||||
t.Errorf("Vanilla opts unmarshal returned invalid value %+v, want %+v", ov, optsVanillaValue)
|
||||
}
|
||||
}
|
28
vendor/github.com/mailru/easyjson/tests/required_test.go
generated
vendored
Normal file
28
vendor/github.com/mailru/easyjson/tests/required_test.go
generated
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRequiredField(t *testing.T) {
|
||||
cases := []struct{ json, errorMessage string }{
|
||||
{`{"first_name":"Foo", "last_name": "Bar"}`, ""},
|
||||
{`{"last_name":"Bar"}`, "key 'first_name' is required"},
|
||||
{"{}", "key 'first_name' is required"},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
var v RequiredOptionalStruct
|
||||
err := v.UnmarshalJSON([]byte(tc.json))
|
||||
if tc.errorMessage == "" {
|
||||
if err != nil {
|
||||
t.Errorf("%s. UnmarshalJSON didn`t expect error: %v", tc.json, err)
|
||||
}
|
||||
} else {
|
||||
if fmt.Sprintf("%v", err) != tc.errorMessage {
|
||||
t.Errorf("%s. UnmarshalJSON expected error: %v. got: %v", tc.json, tc.errorMessage, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
10
vendor/github.com/mailru/easyjson/tests/snake.go
generated
vendored
Normal file
10
vendor/github.com/mailru/easyjson/tests/snake.go
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
package tests
|
||||
|
||||
//easyjson:json
|
||||
type SnakeStruct struct {
|
||||
WeirdHTTPStuff bool
|
||||
CustomNamedField string `json:"cUsToM"`
|
||||
}
|
||||
|
||||
var snakeStructValue SnakeStruct
|
||||
var snakeStructString = `{"weird_http_stuff":false,"cUsToM":""}`
|
Reference in New Issue
Block a user