Beispiel #1
0
func TestTypedefI64(t *testing.T) {
	tests := []struct {
		x td.Timestamp
		v wire.Value
	}{
		{
			td.Timestamp(1),
			wire.NewValueI64(1),
		},
		{
			td.Timestamp(-1),
			wire.NewValueI64(-1),
		},
	}

	for _, tt := range tests {
		assertRoundTrip(t, &tt.x, tt.v, "Timestamp")
	}
}
Beispiel #2
0
func TestConstants(t *testing.T) {
	enumDefaultBaz := te.EnumDefaultBaz

	tests := []struct {
		name string
		i    interface{}
		o    interface{}
	}{
		{
			"primitiveContainers",
			tk.PrimitiveContainers,
			&tc.PrimitiveContainers{
				ListOfInts: []int64{1, 2, 3},
				SetOfStrings: map[string]struct{}{
					"foo": {},
					"bar": {},
				},
				SetOfBytes: map[int8]struct{}{
					1: {},
					2: {},
					3: {},
				},
				MapOfIntToString: map[int32]string{
					1: "1",
					2: "2",
					3: "3",
				},
				MapOfStringToBool: map[string]bool{
					"1": false,
					"2": true,
					"3": true,
				},
			},
		},
		{
			"enumContainers",
			tk.EnumContainers,
			&tc.EnumContainers{
				ListOfEnums: []te.EnumDefault{te.EnumDefaultBar, te.EnumDefaultFoo},
				SetOfEnums: map[te.EnumWithValues]struct{}{
					te.EnumWithValuesX: {},
					te.EnumWithValuesY: {},
				},
				MapOfEnums: map[te.EnumWithDuplicateValues]int32{
					te.EnumWithDuplicateValuesP: 1,
					te.EnumWithDuplicateValuesQ: 2,
				},
			},
		},
		{
			"containersOfContainers",
			tk.ContainersOfContainers,
			&tc.ContainersOfContainers{
				ListOfLists: [][]int32{
					{1, 2, 3},
					{4, 5, 6},
				},
				ListOfSets: []map[int32]struct{}{
					{
						1: struct{}{},
						2: struct{}{},
						3: struct{}{},
					},
					{
						4: struct{}{},
						5: struct{}{},
						6: struct{}{},
					},
				},
				ListOfMaps: []map[int32]int32{
					{
						1: 2,
						3: 4,
						5: 6,
					},
					{
						7:  8,
						9:  10,
						11: 12,
					},
				},
				SetOfSets: []map[string]struct{}{
					{
						"1": struct{}{},
						"2": struct{}{},
						"3": struct{}{},
					},
					{
						"4": struct{}{},
						"5": struct{}{},
						"6": struct{}{},
					},
				},
				SetOfLists: [][]string{
					{"1", "2", "3"},
					{"4", "5", "6"},
				},
				SetOfMaps: []map[string]string{
					{
						"1": "2",
						"3": "4",
						"5": "6",
					},
					{
						"7":  "8",
						"9":  "10",
						"11": "12",
					},
				},
				MapOfMapToInt: []struct {
					Key   map[string]int32
					Value int64
				}{
					{
						Key:   map[string]int32{"1": 1, "2": 2, "3": 3},
						Value: 100,
					},
					{
						Key:   map[string]int32{"4": 4, "5": 5, "6": 6},
						Value: 200,
					},
				},
				MapOfListToSet: []struct {
					Key   []int32
					Value map[int64]struct{}
				}{
					{
						Key: []int32{1, 2, 3},
						Value: map[int64]struct{}{
							1: {},
							2: {},
							3: {},
						},
					},
					{
						Key: []int32{4, 5, 6},
						Value: map[int64]struct{}{
							4: {},
							5: {},
							6: {},
						},
					},
				},
				MapOfSetToListOfDouble: []struct {
					Key   map[int32]struct{}
					Value []float64
				}{
					{
						Key: map[int32]struct{}{
							1: {},
							2: {},
							3: {},
						},
						Value: []float64{1.2, 3.4},
					},
					{
						Key: map[int32]struct{}{
							4: {},
							5: {},
							6: {},
						},
						Value: []float64{5.6, 7.8},
					},
				},
			},
		},
		{
			"structWithOptionalEnum",
			tk.StructWithOptionalEnum,
			&te.StructWithOptionalEnum{E: &enumDefaultBaz},
		},
		{
			"emptyException",
			tk.EmptyException,
			&tx.EmptyException{},
		},
		{
			"graph",
			tk.Graph,
			&ts.Graph{
				Edges: []*ts.Edge{
					{
						StartPoint: &ts.Point{X: 1, Y: 2},
						EndPoint:   &ts.Point{X: 3, Y: 4},
					},
					{
						StartPoint: &ts.Point{X: 5, Y: 6},
						EndPoint:   &ts.Point{X: 7, Y: 8},
					},
				},
			},
		},
		{
			"arbitraryValue",
			tk.ArbitraryValue,
			&tu.ArbitraryValue{
				ListValue: []*tu.ArbitraryValue{
					{BoolValue: boolp(true)},
					{Int64Value: int64p(2)},
					{StringValue: stringp("hello")},
					{
						MapValue: map[string]*tu.ArbitraryValue{
							"foo": {StringValue: stringp("bar")},
						},
					},
				},
			},
		},
		{
			"lastNode",
			tk.LastNode,
			&ts.Node{Value: 3},
		},
		{
			"node",
			tk.Node,
			&ts.Node{Value: 1, Tail: &ts.List{Value: 2, Tail: &ts.List{Value: 3}}},
		},
		{
			"i128",
			tk.I128,
			&td.I128{High: 1234, Low: 5678},
		},
		{
			"uuid",
			tk.UUID,
			&td.UUID{High: 1234, Low: 5678},
		},
		{
			"beginningOfTime",
			tk.BeginningOfTime,
			td.Timestamp(0),
		},
		{
			"frameGroup",
			tk.FrameGroup,
			td.FrameGroup{
				&ts.Frame{
					TopLeft: &ts.Point{X: 1, Y: 2},
					Size:    &ts.Size{Width: 100, Height: 200},
				},
				&ts.Frame{
					TopLeft: &ts.Point{X: 3, Y: 4},
					Size:    &ts.Size{Width: 300, Height: 400},
				},
			},
		},
		{
			"myEnum",
			tk.MyEnum,
			td.MyEnum(te.EnumWithValuesY),
		},
	}

	for _, tt := range tests {
		assert.Equal(t, tt.o, tt.i, tt.name)
	}
}
Beispiel #3
0
	"go.uber.org/thriftrw/gen/testdata/exceptions"
	"go.uber.org/thriftrw/gen/testdata/structs"
	"go.uber.org/thriftrw/gen/testdata/typedefs"
	"go.uber.org/thriftrw/gen/testdata/unions"
	"go.uber.org/thriftrw/ptr"
)

const Home enums.RecordType = enums.RecordTypeHomeAddress

const Name enums.RecordType = enums.RecordTypeName

const WorkAddress enums.RecordType = enums.RecordTypeWorkAddress

var ArbitraryValue *unions.ArbitraryValue = &unions.ArbitraryValue{ListValue: []*unions.ArbitraryValue{&unions.ArbitraryValue{BoolValue: ptr.Bool(true)}, &unions.ArbitraryValue{Int64Value: ptr.Int64(2)}, &unions.ArbitraryValue{StringValue: ptr.String("hello")}, &unions.ArbitraryValue{MapValue: map[string]*unions.ArbitraryValue{"foo": &unions.ArbitraryValue{StringValue: ptr.String("bar")}}}}}

const BeginningOfTime typedefs.Timestamp = typedefs.Timestamp(0)

var ContainersOfContainers *containers.ContainersOfContainers = &containers.ContainersOfContainers{ListOfLists: [][]int32{[]int32{1, 2, 3}, []int32{4, 5, 6}}, ListOfMaps: []map[int32]int32{map[int32]int32{1: 2, 3: 4, 5: 6}, map[int32]int32{7: 8, 9: 10, 11: 12}}, ListOfSets: []map[int32]struct{}{map[int32]struct{}{1: struct{}{}, 2: struct{}{}, 3: struct{}{}}, map[int32]struct{}{4: struct{}{}, 5: struct{}{}, 6: struct{}{}}}, MapOfListToSet: []struct {
	Key   []int32
	Value map[int64]struct{}
}{{Key: []int32{1, 2, 3}, Value: map[int64]struct{}{1: struct{}{}, 2: struct{}{}, 3: struct{}{}}}, {Key: []int32{4, 5, 6}, Value: map[int64]struct{}{4: struct{}{}, 5: struct{}{}, 6: struct{}{}}}}, MapOfMapToInt: []struct {
	Key   map[string]int32
	Value int64
}{{Key: map[string]int32{"1": 1, "2": 2, "3": 3}, Value: 100}, {Key: map[string]int32{"4": 4, "5": 5, "6": 6}, Value: 200}}, MapOfSetToListOfDouble: []struct {
	Key   map[int32]struct{}
	Value []float64
}{{Key: map[int32]struct{}{1: struct{}{}, 2: struct{}{}, 3: struct{}{}}, Value: []float64{1.2, 3.4}}, {Key: map[int32]struct{}{4: struct{}{}, 5: struct{}{}, 6: struct{}{}}, Value: []float64{5.6, 7.8}}}, SetOfLists: [][]string{[]string{"1", "2", "3"}, []string{"4", "5", "6"}}, SetOfMaps: []map[string]string{map[string]string{"1": "2", "3": "4", "5": "6"}, map[string]string{"7": "8", "9": "10", "11": "12"}}, SetOfSets: []map[string]struct{}{map[string]struct{}{"1": struct{}{}, "2": struct{}{}, "3": struct{}{}}, map[string]struct{}{"4": struct{}{}, "5": struct{}{}, "6": struct{}{}}}}

var EmptyException *exceptions.EmptyException = &exceptions.EmptyException{}

var EnumContainers *containers.EnumContainers = &containers.EnumContainers{ListOfEnums: []enums.EnumDefault{enums.EnumDefaultBar, enums.EnumDefaultFoo}, MapOfEnums: map[enums.EnumWithDuplicateValues]int32{enums.EnumWithDuplicateValuesP: 1, enums.EnumWithDuplicateValuesQ: 2}, SetOfEnums: map[enums.EnumWithValues]struct{}{enums.EnumWithValuesX: struct{}{}, enums.EnumWithValuesY: struct{}{}}}