From 496557b1d5db103f5cdee4fe34ef63c973a7f0d5 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Tue, 29 Oct 2024 12:01:07 +0100 Subject: [PATCH] proto: refactor equal_test from explicit table to use makeMessages() This is important for test coverage: the makeMessages() function is where we declare the various different test message types. Using this central function is better than explicitly having to spell out all the various cases in the test table. This CL is roughly neutral in terms of lines changed, but actually increases coverage: in the existing table, not every group of tests had coverage for all cases (proto2, proto3, editions). This was difficult to spot previously, but now the different test message types are now clearly spelled out (allTypesNoProto3). Also, the test now prints the description and message types as subtest name. This makes it easy to verify coverage by just reading the test output. Change-Id: I08f541548d087233cbb4686785c456674371c2a3 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/623115 Reviewed-by: Chressie Himpel LUCI-TryBot-Result: Go LUCI --- proto/equal_test.go | 1723 ++++++++++++++++++++----------------------- 1 file changed, 816 insertions(+), 907 deletions(-) diff --git a/proto/equal_test.go b/proto/equal_test.go index ce169fb8..346f7948 100644 --- a/proto/equal_test.go +++ b/proto/equal_test.go @@ -5,11 +5,13 @@ package proto_test import ( + "fmt" "math" "testing" "google.golang.org/protobuf/encoding/prototext" "google.golang.org/protobuf/internal/pragma" + "google.golang.org/protobuf/internal/protobuild" "google.golang.org/protobuf/proto" "google.golang.org/protobuf/testing/protopack" @@ -26,10 +28,12 @@ func TestEqual(t *testing.T) { pragma.DoNotCompare } - tests := []struct { + type test struct { + desc string x, y proto.Message eq bool - }{ + } + tests := []test{ { x: nil, y: nil, @@ -91,915 +95,820 @@ func TestEqual(t *testing.T) { y: &incomparableMessage{TestAllTypes: identicalPtrPb}, eq: true, }, - - // Proto2 scalars. - { - x: &testpb.TestAllTypes{OptionalInt32: proto.Int32(1)}, - y: &testpb.TestAllTypes{OptionalInt32: proto.Int32(2)}, - }, { - x: &testpb.TestAllTypes{OptionalInt64: proto.Int64(1)}, - y: &testpb.TestAllTypes{OptionalInt64: proto.Int64(2)}, - }, { - x: &testpb.TestAllTypes{OptionalUint32: proto.Uint32(1)}, - y: &testpb.TestAllTypes{OptionalUint32: proto.Uint32(2)}, - }, { - x: &testpb.TestAllTypes{OptionalUint64: proto.Uint64(1)}, - y: &testpb.TestAllTypes{OptionalUint64: proto.Uint64(2)}, - }, { - x: &testpb.TestAllTypes{OptionalSint32: proto.Int32(1)}, - y: &testpb.TestAllTypes{OptionalSint32: proto.Int32(2)}, - }, { - x: &testpb.TestAllTypes{OptionalSint64: proto.Int64(1)}, - y: &testpb.TestAllTypes{OptionalSint64: proto.Int64(2)}, - }, { - x: &testpb.TestAllTypes{OptionalFixed32: proto.Uint32(1)}, - y: &testpb.TestAllTypes{OptionalFixed32: proto.Uint32(2)}, - }, { - x: &testpb.TestAllTypes{OptionalFixed64: proto.Uint64(1)}, - y: &testpb.TestAllTypes{OptionalFixed64: proto.Uint64(2)}, - }, { - x: &testpb.TestAllTypes{OptionalSfixed32: proto.Int32(1)}, - y: &testpb.TestAllTypes{OptionalSfixed32: proto.Int32(2)}, - }, { - x: &testpb.TestAllTypes{OptionalSfixed64: proto.Int64(1)}, - y: &testpb.TestAllTypes{OptionalSfixed64: proto.Int64(2)}, - }, { - x: &testpb.TestAllTypes{OptionalFloat: proto.Float32(1)}, - y: &testpb.TestAllTypes{OptionalFloat: proto.Float32(2)}, - }, { - x: &testpb.TestAllTypes{OptionalDouble: proto.Float64(1)}, - y: &testpb.TestAllTypes{OptionalDouble: proto.Float64(2)}, - }, { - x: &testpb.TestAllTypes{OptionalFloat: proto.Float32(float32(math.NaN()))}, - y: &testpb.TestAllTypes{OptionalFloat: proto.Float32(0)}, - }, { - x: &testpb.TestAllTypes{OptionalDouble: proto.Float64(float64(math.NaN()))}, - y: &testpb.TestAllTypes{OptionalDouble: proto.Float64(0)}, - }, { - x: &testpb.TestAllTypes{OptionalBool: proto.Bool(true)}, - y: &testpb.TestAllTypes{OptionalBool: proto.Bool(false)}, - }, { - x: &testpb.TestAllTypes{OptionalString: proto.String("a")}, - y: &testpb.TestAllTypes{OptionalString: proto.String("b")}, - }, { - x: &testpb.TestAllTypes{OptionalBytes: []byte("a")}, - y: &testpb.TestAllTypes{OptionalBytes: []byte("b")}, - }, { - x: &testpb.TestAllTypes{OptionalNestedEnum: testpb.TestAllTypes_FOO.Enum()}, - y: &testpb.TestAllTypes{OptionalNestedEnum: testpb.TestAllTypes_BAR.Enum()}, - }, { - x: &testpb.TestAllTypes{OptionalInt32: proto.Int32(2)}, - y: &testpb.TestAllTypes{OptionalInt32: proto.Int32(2)}, - eq: true, - }, { - x: &testpb.TestAllTypes{OptionalInt64: proto.Int64(2)}, - y: &testpb.TestAllTypes{OptionalInt64: proto.Int64(2)}, - eq: true, - }, { - x: &testpb.TestAllTypes{OptionalUint32: proto.Uint32(2)}, - y: &testpb.TestAllTypes{OptionalUint32: proto.Uint32(2)}, - eq: true, - }, { - x: &testpb.TestAllTypes{OptionalUint64: proto.Uint64(2)}, - y: &testpb.TestAllTypes{OptionalUint64: proto.Uint64(2)}, - eq: true, - }, { - x: &testpb.TestAllTypes{OptionalSint32: proto.Int32(2)}, - y: &testpb.TestAllTypes{OptionalSint32: proto.Int32(2)}, - eq: true, - }, { - x: &testpb.TestAllTypes{OptionalSint64: proto.Int64(2)}, - y: &testpb.TestAllTypes{OptionalSint64: proto.Int64(2)}, - eq: true, - }, { - x: &testpb.TestAllTypes{OptionalFixed32: proto.Uint32(2)}, - y: &testpb.TestAllTypes{OptionalFixed32: proto.Uint32(2)}, - eq: true, - }, { - x: &testpb.TestAllTypes{OptionalFixed64: proto.Uint64(2)}, - y: &testpb.TestAllTypes{OptionalFixed64: proto.Uint64(2)}, - eq: true, - }, { - x: &testpb.TestAllTypes{OptionalSfixed32: proto.Int32(2)}, - y: &testpb.TestAllTypes{OptionalSfixed32: proto.Int32(2)}, - eq: true, - }, { - x: &testpb.TestAllTypes{OptionalSfixed64: proto.Int64(2)}, - y: &testpb.TestAllTypes{OptionalSfixed64: proto.Int64(2)}, - eq: true, - }, { - x: &testpb.TestAllTypes{OptionalFloat: proto.Float32(2)}, - y: &testpb.TestAllTypes{OptionalFloat: proto.Float32(2)}, - eq: true, - }, { - x: &testpb.TestAllTypes{OptionalDouble: proto.Float64(2)}, - y: &testpb.TestAllTypes{OptionalDouble: proto.Float64(2)}, - eq: true, - }, { - x: &testpb.TestAllTypes{OptionalFloat: proto.Float32(float32(math.NaN()))}, - y: &testpb.TestAllTypes{OptionalFloat: proto.Float32(float32(math.NaN()))}, - eq: true, - }, { - x: &testpb.TestAllTypes{OptionalDouble: proto.Float64(float64(math.NaN()))}, - y: &testpb.TestAllTypes{OptionalDouble: proto.Float64(float64(math.NaN()))}, - eq: true, - }, { - x: &testpb.TestAllTypes{OptionalBool: proto.Bool(true)}, - y: &testpb.TestAllTypes{OptionalBool: proto.Bool(true)}, - eq: true, - }, { - x: &testpb.TestAllTypes{OptionalString: proto.String("abc")}, - y: &testpb.TestAllTypes{OptionalString: proto.String("abc")}, - eq: true, - }, { - x: &testpb.TestAllTypes{OptionalBytes: []byte("abc")}, - y: &testpb.TestAllTypes{OptionalBytes: []byte("abc")}, - eq: true, - }, { - x: &testpb.TestAllTypes{OptionalNestedEnum: testpb.TestAllTypes_FOO.Enum()}, - y: &testpb.TestAllTypes{OptionalNestedEnum: testpb.TestAllTypes_FOO.Enum()}, - eq: true, - }, - - // Editions scalars. - { - x: &testeditionspb.TestAllTypes{OptionalInt32: proto.Int32(1)}, - y: &testeditionspb.TestAllTypes{OptionalInt32: proto.Int32(2)}, - }, { - x: &testeditionspb.TestAllTypes{OptionalInt64: proto.Int64(1)}, - y: &testeditionspb.TestAllTypes{OptionalInt64: proto.Int64(2)}, - }, { - x: &testeditionspb.TestAllTypes{OptionalUint32: proto.Uint32(1)}, - y: &testeditionspb.TestAllTypes{OptionalUint32: proto.Uint32(2)}, - }, { - x: &testeditionspb.TestAllTypes{OptionalUint64: proto.Uint64(1)}, - y: &testeditionspb.TestAllTypes{OptionalUint64: proto.Uint64(2)}, - }, { - x: &testeditionspb.TestAllTypes{OptionalSint32: proto.Int32(1)}, - y: &testeditionspb.TestAllTypes{OptionalSint32: proto.Int32(2)}, - }, { - x: &testeditionspb.TestAllTypes{OptionalSint64: proto.Int64(1)}, - y: &testeditionspb.TestAllTypes{OptionalSint64: proto.Int64(2)}, - }, { - x: &testeditionspb.TestAllTypes{OptionalFixed32: proto.Uint32(1)}, - y: &testeditionspb.TestAllTypes{OptionalFixed32: proto.Uint32(2)}, - }, { - x: &testeditionspb.TestAllTypes{OptionalFixed64: proto.Uint64(1)}, - y: &testeditionspb.TestAllTypes{OptionalFixed64: proto.Uint64(2)}, - }, { - x: &testeditionspb.TestAllTypes{OptionalSfixed32: proto.Int32(1)}, - y: &testeditionspb.TestAllTypes{OptionalSfixed32: proto.Int32(2)}, - }, { - x: &testeditionspb.TestAllTypes{OptionalSfixed64: proto.Int64(1)}, - y: &testeditionspb.TestAllTypes{OptionalSfixed64: proto.Int64(2)}, - }, { - x: &testeditionspb.TestAllTypes{OptionalFloat: proto.Float32(1)}, - y: &testeditionspb.TestAllTypes{OptionalFloat: proto.Float32(2)}, - }, { - x: &testeditionspb.TestAllTypes{OptionalDouble: proto.Float64(1)}, - y: &testeditionspb.TestAllTypes{OptionalDouble: proto.Float64(2)}, - }, { - x: &testeditionspb.TestAllTypes{OptionalFloat: proto.Float32(float32(math.NaN()))}, - y: &testeditionspb.TestAllTypes{OptionalFloat: proto.Float32(0)}, - }, { - x: &testeditionspb.TestAllTypes{OptionalDouble: proto.Float64(float64(math.NaN()))}, - y: &testeditionspb.TestAllTypes{OptionalDouble: proto.Float64(0)}, - }, { - x: &testeditionspb.TestAllTypes{OptionalBool: proto.Bool(true)}, - y: &testeditionspb.TestAllTypes{OptionalBool: proto.Bool(false)}, - }, { - x: &testeditionspb.TestAllTypes{OptionalString: proto.String("a")}, - y: &testeditionspb.TestAllTypes{OptionalString: proto.String("b")}, - }, { - x: &testeditionspb.TestAllTypes{OptionalBytes: []byte("a")}, - y: &testeditionspb.TestAllTypes{OptionalBytes: []byte("b")}, - }, { - x: &testeditionspb.TestAllTypes{OptionalNestedEnum: testeditionspb.TestAllTypes_FOO.Enum()}, - y: &testeditionspb.TestAllTypes{OptionalNestedEnum: testeditionspb.TestAllTypes_BAR.Enum()}, - }, { - x: &testeditionspb.TestAllTypes{OptionalInt32: proto.Int32(2)}, - y: &testeditionspb.TestAllTypes{OptionalInt32: proto.Int32(2)}, - eq: true, - }, { - x: &testeditionspb.TestAllTypes{OptionalInt64: proto.Int64(2)}, - y: &testeditionspb.TestAllTypes{OptionalInt64: proto.Int64(2)}, - eq: true, - }, { - x: &testeditionspb.TestAllTypes{OptionalUint32: proto.Uint32(2)}, - y: &testeditionspb.TestAllTypes{OptionalUint32: proto.Uint32(2)}, - eq: true, - }, { - x: &testeditionspb.TestAllTypes{OptionalUint64: proto.Uint64(2)}, - y: &testeditionspb.TestAllTypes{OptionalUint64: proto.Uint64(2)}, - eq: true, - }, { - x: &testeditionspb.TestAllTypes{OptionalSint32: proto.Int32(2)}, - y: &testeditionspb.TestAllTypes{OptionalSint32: proto.Int32(2)}, - eq: true, - }, { - x: &testeditionspb.TestAllTypes{OptionalSint64: proto.Int64(2)}, - y: &testeditionspb.TestAllTypes{OptionalSint64: proto.Int64(2)}, - eq: true, - }, { - x: &testeditionspb.TestAllTypes{OptionalFixed32: proto.Uint32(2)}, - y: &testeditionspb.TestAllTypes{OptionalFixed32: proto.Uint32(2)}, - eq: true, - }, { - x: &testeditionspb.TestAllTypes{OptionalFixed64: proto.Uint64(2)}, - y: &testeditionspb.TestAllTypes{OptionalFixed64: proto.Uint64(2)}, - eq: true, - }, { - x: &testeditionspb.TestAllTypes{OptionalSfixed32: proto.Int32(2)}, - y: &testeditionspb.TestAllTypes{OptionalSfixed32: proto.Int32(2)}, - eq: true, - }, { - x: &testeditionspb.TestAllTypes{OptionalSfixed64: proto.Int64(2)}, - y: &testeditionspb.TestAllTypes{OptionalSfixed64: proto.Int64(2)}, - eq: true, - }, { - x: &testeditionspb.TestAllTypes{OptionalFloat: proto.Float32(2)}, - y: &testeditionspb.TestAllTypes{OptionalFloat: proto.Float32(2)}, - eq: true, - }, { - x: &testeditionspb.TestAllTypes{OptionalDouble: proto.Float64(2)}, - y: &testeditionspb.TestAllTypes{OptionalDouble: proto.Float64(2)}, - eq: true, - }, { - x: &testeditionspb.TestAllTypes{OptionalFloat: proto.Float32(float32(math.NaN()))}, - y: &testeditionspb.TestAllTypes{OptionalFloat: proto.Float32(float32(math.NaN()))}, - eq: true, - }, { - x: &testeditionspb.TestAllTypes{OptionalDouble: proto.Float64(float64(math.NaN()))}, - y: &testeditionspb.TestAllTypes{OptionalDouble: proto.Float64(float64(math.NaN()))}, - eq: true, - }, { - x: &testeditionspb.TestAllTypes{OptionalBool: proto.Bool(true)}, - y: &testeditionspb.TestAllTypes{OptionalBool: proto.Bool(true)}, - eq: true, - }, { - x: &testeditionspb.TestAllTypes{OptionalString: proto.String("abc")}, - y: &testeditionspb.TestAllTypes{OptionalString: proto.String("abc")}, - eq: true, - }, { - x: &testeditionspb.TestAllTypes{OptionalBytes: []byte("abc")}, - y: &testeditionspb.TestAllTypes{OptionalBytes: []byte("abc")}, - eq: true, - }, { - x: &testeditionspb.TestAllTypes{OptionalNestedEnum: testeditionspb.TestAllTypes_FOO.Enum()}, - y: &testeditionspb.TestAllTypes{OptionalNestedEnum: testeditionspb.TestAllTypes_FOO.Enum()}, - eq: true, - }, - - // Proto2 presence. - { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{OptionalInt32: proto.Int32(0)}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{OptionalInt64: proto.Int64(0)}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{OptionalUint32: proto.Uint32(0)}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{OptionalUint64: proto.Uint64(0)}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{OptionalSint32: proto.Int32(0)}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{OptionalSint64: proto.Int64(0)}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{OptionalFixed32: proto.Uint32(0)}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{OptionalFixed64: proto.Uint64(0)}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{OptionalSfixed32: proto.Int32(0)}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{OptionalSfixed64: proto.Int64(0)}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{OptionalFloat: proto.Float32(0)}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{OptionalDouble: proto.Float64(0)}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{OptionalBool: proto.Bool(false)}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{OptionalString: proto.String("")}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{OptionalBytes: []byte{}}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{OptionalNestedEnum: testpb.TestAllTypes_FOO.Enum()}, - }, - - // Editions presence. - { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{OptionalInt32: proto.Int32(0)}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{OptionalInt64: proto.Int64(0)}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{OptionalUint32: proto.Uint32(0)}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{OptionalUint64: proto.Uint64(0)}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{OptionalSint32: proto.Int32(0)}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{OptionalSint64: proto.Int64(0)}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{OptionalFixed32: proto.Uint32(0)}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{OptionalFixed64: proto.Uint64(0)}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{OptionalSfixed32: proto.Int32(0)}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{OptionalSfixed64: proto.Int64(0)}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{OptionalFloat: proto.Float32(0)}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{OptionalDouble: proto.Float64(0)}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{OptionalBool: proto.Bool(false)}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{OptionalString: proto.String("")}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{OptionalBytes: []byte{}}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{OptionalNestedEnum: testeditionspb.TestAllTypes_FOO.Enum()}, - }, - - // Proto3 presence. - { - x: &test3pb.TestAllTypes{}, - y: &test3pb.TestAllTypes{OptionalInt32: proto.Int32(0)}, - }, { - x: &test3pb.TestAllTypes{}, - y: &test3pb.TestAllTypes{OptionalInt64: proto.Int64(0)}, - }, { - x: &test3pb.TestAllTypes{}, - y: &test3pb.TestAllTypes{OptionalUint32: proto.Uint32(0)}, - }, { - x: &test3pb.TestAllTypes{}, - y: &test3pb.TestAllTypes{OptionalUint64: proto.Uint64(0)}, - }, { - x: &test3pb.TestAllTypes{}, - y: &test3pb.TestAllTypes{OptionalSint32: proto.Int32(0)}, - }, { - x: &test3pb.TestAllTypes{}, - y: &test3pb.TestAllTypes{OptionalSint64: proto.Int64(0)}, - }, { - x: &test3pb.TestAllTypes{}, - y: &test3pb.TestAllTypes{OptionalFixed32: proto.Uint32(0)}, - }, { - x: &test3pb.TestAllTypes{}, - y: &test3pb.TestAllTypes{OptionalFixed64: proto.Uint64(0)}, - }, { - x: &test3pb.TestAllTypes{}, - y: &test3pb.TestAllTypes{OptionalSfixed32: proto.Int32(0)}, - }, { - x: &test3pb.TestAllTypes{}, - y: &test3pb.TestAllTypes{OptionalSfixed64: proto.Int64(0)}, - }, { - x: &test3pb.TestAllTypes{}, - y: &test3pb.TestAllTypes{OptionalFloat: proto.Float32(0)}, - }, { - x: &test3pb.TestAllTypes{}, - y: &test3pb.TestAllTypes{OptionalDouble: proto.Float64(0)}, - }, { - x: &test3pb.TestAllTypes{}, - y: &test3pb.TestAllTypes{OptionalBool: proto.Bool(false)}, - }, { - x: &test3pb.TestAllTypes{}, - y: &test3pb.TestAllTypes{OptionalString: proto.String("")}, - }, { - x: &test3pb.TestAllTypes{}, - y: &test3pb.TestAllTypes{OptionalBytes: []byte{}}, - }, { - x: &test3pb.TestAllTypes{}, - y: &test3pb.TestAllTypes{OptionalNestedEnum: test3pb.TestAllTypes_FOO.Enum()}, - }, - - // Proto2 default values are not considered by Equal, so the following are still unequal. - { - x: &testpb.TestAllTypes{DefaultInt32: proto.Int32(81)}, - y: &testpb.TestAllTypes{}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{DefaultInt32: proto.Int32(81)}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{DefaultInt64: proto.Int64(82)}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{DefaultUint32: proto.Uint32(83)}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{DefaultUint64: proto.Uint64(84)}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{DefaultSint32: proto.Int32(-85)}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{DefaultSint64: proto.Int64(86)}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{DefaultFixed32: proto.Uint32(87)}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{DefaultFixed64: proto.Uint64(88)}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{DefaultSfixed32: proto.Int32(89)}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{DefaultSfixed64: proto.Int64(-90)}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{DefaultFloat: proto.Float32(91.5)}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{DefaultDouble: proto.Float64(92e3)}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{DefaultBool: proto.Bool(true)}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{DefaultString: proto.String("hello")}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{DefaultBytes: []byte("world")}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{DefaultNestedEnum: testpb.TestAllTypes_BAR.Enum()}, - }, - - // Edition default values are not considered by Equal, so the following are still unequal. - { - x: &testeditionspb.TestAllTypes{DefaultInt32: proto.Int32(81)}, - y: &testeditionspb.TestAllTypes{}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{DefaultInt32: proto.Int32(81)}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{DefaultInt64: proto.Int64(82)}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{DefaultUint32: proto.Uint32(83)}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{DefaultUint64: proto.Uint64(84)}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{DefaultSint32: proto.Int32(-85)}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{DefaultSint64: proto.Int64(86)}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{DefaultFixed32: proto.Uint32(87)}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{DefaultFixed64: proto.Uint64(88)}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{DefaultSfixed32: proto.Int32(89)}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{DefaultSfixed64: proto.Int64(-90)}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{DefaultFloat: proto.Float32(91.5)}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{DefaultDouble: proto.Float64(92e3)}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{DefaultBool: proto.Bool(true)}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{DefaultString: proto.String("hello")}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{DefaultBytes: []byte("world")}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{DefaultNestedEnum: testeditionspb.TestAllTypes_BAR.Enum()}, - }, - - // Groups. - { - x: &testpb.TestAllTypes{Optionalgroup: &testpb.TestAllTypes_OptionalGroup{ - A: proto.Int32(1), - }}, - y: &testpb.TestAllTypes{Optionalgroup: &testpb.TestAllTypes_OptionalGroup{ - A: proto.Int32(2), - }}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{Optionalgroup: &testpb.TestAllTypes_OptionalGroup{}}, - }, { - x: &testeditionspb.TestAllTypes{Optionalgroup: &testeditionspb.TestAllTypes_OptionalGroup{ - A: proto.Int32(1), - }}, - y: &testeditionspb.TestAllTypes{Optionalgroup: &testeditionspb.TestAllTypes_OptionalGroup{ - A: proto.Int32(2), - }}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{Optionalgroup: &testeditionspb.TestAllTypes_OptionalGroup{}}, - }, - - // Messages. - { - x: &testpb.TestAllTypes{OptionalNestedMessage: &testpb.TestAllTypes_NestedMessage{ - A: proto.Int32(1), - }}, - y: &testpb.TestAllTypes{OptionalNestedMessage: &testpb.TestAllTypes_NestedMessage{ - A: proto.Int32(2), - }}, - }, { - x: &testpb.TestAllTypes{}, - y: &testpb.TestAllTypes{OptionalNestedMessage: &testpb.TestAllTypes_NestedMessage{}}, - }, { - x: &testeditionspb.TestAllTypes{}, - y: &testeditionspb.TestAllTypes{OptionalNestedMessage: &testeditionspb.TestAllTypes_NestedMessage{}}, - }, { - x: &test3pb.TestAllTypes{}, - y: &test3pb.TestAllTypes{OptionalNestedMessage: &test3pb.TestAllTypes_NestedMessage{}}, - }, - - // Lists. - { - x: &testpb.TestAllTypes{RepeatedInt32: []int32{1}}, - y: &testpb.TestAllTypes{RepeatedInt32: []int32{1, 2}}, - }, { - x: &testpb.TestAllTypes{RepeatedInt32: []int32{1, 2}}, - y: &testpb.TestAllTypes{RepeatedInt32: []int32{1, 3}}, - }, { - x: &testpb.TestAllTypes{RepeatedInt64: []int64{1, 2}}, - y: &testpb.TestAllTypes{RepeatedInt64: []int64{1, 3}}, - }, { - x: &testpb.TestAllTypes{RepeatedUint32: []uint32{1, 2}}, - y: &testpb.TestAllTypes{RepeatedUint32: []uint32{1, 3}}, - }, { - x: &testpb.TestAllTypes{RepeatedUint64: []uint64{1, 2}}, - y: &testpb.TestAllTypes{RepeatedUint64: []uint64{1, 3}}, - }, { - x: &testpb.TestAllTypes{RepeatedSint32: []int32{1, 2}}, - y: &testpb.TestAllTypes{RepeatedSint32: []int32{1, 3}}, - }, { - x: &testpb.TestAllTypes{RepeatedSint64: []int64{1, 2}}, - y: &testpb.TestAllTypes{RepeatedSint64: []int64{1, 3}}, - }, { - x: &testpb.TestAllTypes{RepeatedFixed32: []uint32{1, 2}}, - y: &testpb.TestAllTypes{RepeatedFixed32: []uint32{1, 3}}, - }, { - x: &testpb.TestAllTypes{RepeatedFixed64: []uint64{1, 2}}, - y: &testpb.TestAllTypes{RepeatedFixed64: []uint64{1, 3}}, - }, { - x: &testpb.TestAllTypes{RepeatedSfixed32: []int32{1, 2}}, - y: &testpb.TestAllTypes{RepeatedSfixed32: []int32{1, 3}}, - }, { - x: &testpb.TestAllTypes{RepeatedSfixed64: []int64{1, 2}}, - y: &testpb.TestAllTypes{RepeatedSfixed64: []int64{1, 3}}, - }, { - x: &testpb.TestAllTypes{RepeatedFloat: []float32{1, 2}}, - y: &testpb.TestAllTypes{RepeatedFloat: []float32{1, 3}}, - }, { - x: &testpb.TestAllTypes{RepeatedDouble: []float64{1, 2}}, - y: &testpb.TestAllTypes{RepeatedDouble: []float64{1, 3}}, - }, { - x: &testpb.TestAllTypes{RepeatedBool: []bool{true, false}}, - y: &testpb.TestAllTypes{RepeatedBool: []bool{true, true}}, - }, { - x: &testpb.TestAllTypes{RepeatedString: []string{"a", "b"}}, - y: &testpb.TestAllTypes{RepeatedString: []string{"a", "c"}}, - }, { - x: &testpb.TestAllTypes{RepeatedBytes: [][]byte{[]byte("a"), []byte("b")}}, - y: &testpb.TestAllTypes{RepeatedBytes: [][]byte{[]byte("a"), []byte("c")}}, - }, { - x: &testpb.TestAllTypes{RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_FOO}}, - y: &testpb.TestAllTypes{RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_BAR}}, - }, { - x: &testpb.TestAllTypes{Repeatedgroup: []*testpb.TestAllTypes_RepeatedGroup{ - {A: proto.Int32(1)}, - {A: proto.Int32(2)}, - }}, - y: &testpb.TestAllTypes{Repeatedgroup: []*testpb.TestAllTypes_RepeatedGroup{ - {A: proto.Int32(1)}, - {A: proto.Int32(3)}, - }}, - }, { - x: &testpb.TestAllTypes{RepeatedNestedMessage: []*testpb.TestAllTypes_NestedMessage{ - {A: proto.Int32(1)}, - {A: proto.Int32(2)}, - }}, - y: &testpb.TestAllTypes{RepeatedNestedMessage: []*testpb.TestAllTypes_NestedMessage{ - {A: proto.Int32(1)}, - {A: proto.Int32(3)}, - }}, - }, - - // Editions Lists. - { - x: &testeditionspb.TestAllTypes{RepeatedInt32: []int32{1}}, - y: &testeditionspb.TestAllTypes{RepeatedInt32: []int32{1, 2}}, - }, { - x: &testeditionspb.TestAllTypes{RepeatedInt32: []int32{1, 2}}, - y: &testeditionspb.TestAllTypes{RepeatedInt32: []int32{1, 3}}, - }, { - x: &testeditionspb.TestAllTypes{RepeatedInt64: []int64{1, 2}}, - y: &testeditionspb.TestAllTypes{RepeatedInt64: []int64{1, 3}}, - }, { - x: &testeditionspb.TestAllTypes{RepeatedUint32: []uint32{1, 2}}, - y: &testeditionspb.TestAllTypes{RepeatedUint32: []uint32{1, 3}}, - }, { - x: &testeditionspb.TestAllTypes{RepeatedUint64: []uint64{1, 2}}, - y: &testeditionspb.TestAllTypes{RepeatedUint64: []uint64{1, 3}}, - }, { - x: &testeditionspb.TestAllTypes{RepeatedSint32: []int32{1, 2}}, - y: &testeditionspb.TestAllTypes{RepeatedSint32: []int32{1, 3}}, - }, { - x: &testeditionspb.TestAllTypes{RepeatedSint64: []int64{1, 2}}, - y: &testeditionspb.TestAllTypes{RepeatedSint64: []int64{1, 3}}, - }, { - x: &testeditionspb.TestAllTypes{RepeatedFixed32: []uint32{1, 2}}, - y: &testeditionspb.TestAllTypes{RepeatedFixed32: []uint32{1, 3}}, - }, { - x: &testeditionspb.TestAllTypes{RepeatedFixed64: []uint64{1, 2}}, - y: &testeditionspb.TestAllTypes{RepeatedFixed64: []uint64{1, 3}}, - }, { - x: &testeditionspb.TestAllTypes{RepeatedSfixed32: []int32{1, 2}}, - y: &testeditionspb.TestAllTypes{RepeatedSfixed32: []int32{1, 3}}, - }, { - x: &testeditionspb.TestAllTypes{RepeatedSfixed64: []int64{1, 2}}, - y: &testeditionspb.TestAllTypes{RepeatedSfixed64: []int64{1, 3}}, - }, { - x: &testeditionspb.TestAllTypes{RepeatedFloat: []float32{1, 2}}, - y: &testeditionspb.TestAllTypes{RepeatedFloat: []float32{1, 3}}, - }, { - x: &testeditionspb.TestAllTypes{RepeatedDouble: []float64{1, 2}}, - y: &testeditionspb.TestAllTypes{RepeatedDouble: []float64{1, 3}}, - }, { - x: &testeditionspb.TestAllTypes{RepeatedBool: []bool{true, false}}, - y: &testeditionspb.TestAllTypes{RepeatedBool: []bool{true, true}}, - }, { - x: &testeditionspb.TestAllTypes{RepeatedString: []string{"a", "b"}}, - y: &testeditionspb.TestAllTypes{RepeatedString: []string{"a", "c"}}, - }, { - x: &testeditionspb.TestAllTypes{RepeatedBytes: [][]byte{[]byte("a"), []byte("b")}}, - y: &testeditionspb.TestAllTypes{RepeatedBytes: [][]byte{[]byte("a"), []byte("c")}}, - }, { - x: &testeditionspb.TestAllTypes{RepeatedNestedEnum: []testeditionspb.TestAllTypes_NestedEnum{testeditionspb.TestAllTypes_FOO}}, - y: &testeditionspb.TestAllTypes{RepeatedNestedEnum: []testeditionspb.TestAllTypes_NestedEnum{testeditionspb.TestAllTypes_BAR}}, - }, { - x: &testeditionspb.TestAllTypes{Repeatedgroup: []*testeditionspb.TestAllTypes_RepeatedGroup{ - {A: proto.Int32(1)}, - {A: proto.Int32(2)}, - }}, - y: &testeditionspb.TestAllTypes{Repeatedgroup: []*testeditionspb.TestAllTypes_RepeatedGroup{ - {A: proto.Int32(1)}, - {A: proto.Int32(3)}, - }}, - }, { - x: &testeditionspb.TestAllTypes{RepeatedNestedMessage: []*testeditionspb.TestAllTypes_NestedMessage{ - {A: proto.Int32(1)}, - {A: proto.Int32(2)}, - }}, - y: &testeditionspb.TestAllTypes{RepeatedNestedMessage: []*testeditionspb.TestAllTypes_NestedMessage{ - {A: proto.Int32(1)}, - {A: proto.Int32(3)}, - }}, - }, - - // Maps: various configurations. - { - x: &testpb.TestAllTypes{MapInt32Int32: map[int32]int32{1: 2}}, - y: &testpb.TestAllTypes{MapInt32Int32: map[int32]int32{3: 4}}, - }, { - x: &testpb.TestAllTypes{MapInt32Int32: map[int32]int32{1: 2}}, - y: &testpb.TestAllTypes{MapInt32Int32: map[int32]int32{1: 2, 3: 4}}, - }, { - x: &testpb.TestAllTypes{MapInt32Int32: map[int32]int32{1: 2, 3: 4}}, - y: &testpb.TestAllTypes{MapInt32Int32: map[int32]int32{1: 2}}, - }, { - x: &testeditionspb.TestAllTypes{MapInt32Int32: map[int32]int32{1: 2}}, - y: &testeditionspb.TestAllTypes{MapInt32Int32: map[int32]int32{3: 4}}, - }, { - x: &testeditionspb.TestAllTypes{MapInt32Int32: map[int32]int32{1: 2}}, - y: &testeditionspb.TestAllTypes{MapInt32Int32: map[int32]int32{1: 2, 3: 4}}, - }, { - x: &testeditionspb.TestAllTypes{MapInt32Int32: map[int32]int32{1: 2, 3: 4}}, - y: &testeditionspb.TestAllTypes{MapInt32Int32: map[int32]int32{1: 2}}, - }, - - // Maps: various types. - { - x: &testpb.TestAllTypes{MapInt32Int32: map[int32]int32{1: 2, 3: 4}}, - y: &testpb.TestAllTypes{MapInt32Int32: map[int32]int32{1: 2, 3: 5}}, - }, { - x: &testpb.TestAllTypes{MapInt64Int64: map[int64]int64{1: 2, 3: 4}}, - y: &testpb.TestAllTypes{MapInt64Int64: map[int64]int64{1: 2, 3: 5}}, - }, { - x: &testpb.TestAllTypes{MapUint32Uint32: map[uint32]uint32{1: 2, 3: 4}}, - y: &testpb.TestAllTypes{MapUint32Uint32: map[uint32]uint32{1: 2, 3: 5}}, - }, { - x: &testpb.TestAllTypes{MapUint64Uint64: map[uint64]uint64{1: 2, 3: 4}}, - y: &testpb.TestAllTypes{MapUint64Uint64: map[uint64]uint64{1: 2, 3: 5}}, - }, { - x: &testpb.TestAllTypes{MapSint32Sint32: map[int32]int32{1: 2, 3: 4}}, - y: &testpb.TestAllTypes{MapSint32Sint32: map[int32]int32{1: 2, 3: 5}}, - }, { - x: &testpb.TestAllTypes{MapSint64Sint64: map[int64]int64{1: 2, 3: 4}}, - y: &testpb.TestAllTypes{MapSint64Sint64: map[int64]int64{1: 2, 3: 5}}, - }, { - x: &testpb.TestAllTypes{MapFixed32Fixed32: map[uint32]uint32{1: 2, 3: 4}}, - y: &testpb.TestAllTypes{MapFixed32Fixed32: map[uint32]uint32{1: 2, 3: 5}}, - }, { - x: &testpb.TestAllTypes{MapFixed64Fixed64: map[uint64]uint64{1: 2, 3: 4}}, - y: &testpb.TestAllTypes{MapFixed64Fixed64: map[uint64]uint64{1: 2, 3: 5}}, - }, { - x: &testpb.TestAllTypes{MapSfixed32Sfixed32: map[int32]int32{1: 2, 3: 4}}, - y: &testpb.TestAllTypes{MapSfixed32Sfixed32: map[int32]int32{1: 2, 3: 5}}, - }, { - x: &testpb.TestAllTypes{MapSfixed64Sfixed64: map[int64]int64{1: 2, 3: 4}}, - y: &testpb.TestAllTypes{MapSfixed64Sfixed64: map[int64]int64{1: 2, 3: 5}}, - }, { - x: &testpb.TestAllTypes{MapInt32Float: map[int32]float32{1: 2, 3: 4}}, - y: &testpb.TestAllTypes{MapInt32Float: map[int32]float32{1: 2, 3: 5}}, - }, { - x: &testpb.TestAllTypes{MapInt32Double: map[int32]float64{1: 2, 3: 4}}, - y: &testpb.TestAllTypes{MapInt32Double: map[int32]float64{1: 2, 3: 5}}, - }, { - x: &testpb.TestAllTypes{MapBoolBool: map[bool]bool{true: false, false: true}}, - y: &testpb.TestAllTypes{MapBoolBool: map[bool]bool{true: false, false: false}}, - }, { - x: &testpb.TestAllTypes{MapStringString: map[string]string{"a": "b", "c": "d"}}, - y: &testpb.TestAllTypes{MapStringString: map[string]string{"a": "b", "c": "e"}}, - }, { - x: &testpb.TestAllTypes{MapStringBytes: map[string][]byte{"a": []byte("b"), "c": []byte("d")}}, - y: &testpb.TestAllTypes{MapStringBytes: map[string][]byte{"a": []byte("b"), "c": []byte("e")}}, - }, { - x: &testpb.TestAllTypes{MapStringNestedMessage: map[string]*testpb.TestAllTypes_NestedMessage{ - "a": {A: proto.Int32(1)}, - "b": {A: proto.Int32(2)}, - }}, - y: &testpb.TestAllTypes{MapStringNestedMessage: map[string]*testpb.TestAllTypes_NestedMessage{ - "a": {A: proto.Int32(1)}, - "b": {A: proto.Int32(3)}, - }}, - }, { - x: &testpb.TestAllTypes{MapStringNestedEnum: map[string]testpb.TestAllTypes_NestedEnum{ - "a": testpb.TestAllTypes_FOO, - "b": testpb.TestAllTypes_BAR, - }}, - y: &testpb.TestAllTypes{MapStringNestedEnum: map[string]testpb.TestAllTypes_NestedEnum{ - "a": testpb.TestAllTypes_FOO, - "b": testpb.TestAllTypes_BAZ, - }}, - }, { - x: &testeditionspb.TestAllTypes{MapInt32Int32: map[int32]int32{1: 2, 3: 4}}, - y: &testeditionspb.TestAllTypes{MapInt32Int32: map[int32]int32{1: 2, 3: 5}}, - }, { - x: &testeditionspb.TestAllTypes{MapInt64Int64: map[int64]int64{1: 2, 3: 4}}, - y: &testeditionspb.TestAllTypes{MapInt64Int64: map[int64]int64{1: 2, 3: 5}}, - }, { - x: &testeditionspb.TestAllTypes{MapUint32Uint32: map[uint32]uint32{1: 2, 3: 4}}, - y: &testeditionspb.TestAllTypes{MapUint32Uint32: map[uint32]uint32{1: 2, 3: 5}}, - }, { - x: &testeditionspb.TestAllTypes{MapUint64Uint64: map[uint64]uint64{1: 2, 3: 4}}, - y: &testeditionspb.TestAllTypes{MapUint64Uint64: map[uint64]uint64{1: 2, 3: 5}}, - }, { - x: &testeditionspb.TestAllTypes{MapSint32Sint32: map[int32]int32{1: 2, 3: 4}}, - y: &testeditionspb.TestAllTypes{MapSint32Sint32: map[int32]int32{1: 2, 3: 5}}, - }, { - x: &testeditionspb.TestAllTypes{MapSint64Sint64: map[int64]int64{1: 2, 3: 4}}, - y: &testeditionspb.TestAllTypes{MapSint64Sint64: map[int64]int64{1: 2, 3: 5}}, - }, { - x: &testeditionspb.TestAllTypes{MapFixed32Fixed32: map[uint32]uint32{1: 2, 3: 4}}, - y: &testeditionspb.TestAllTypes{MapFixed32Fixed32: map[uint32]uint32{1: 2, 3: 5}}, - }, { - x: &testeditionspb.TestAllTypes{MapFixed64Fixed64: map[uint64]uint64{1: 2, 3: 4}}, - y: &testeditionspb.TestAllTypes{MapFixed64Fixed64: map[uint64]uint64{1: 2, 3: 5}}, - }, { - x: &testeditionspb.TestAllTypes{MapSfixed32Sfixed32: map[int32]int32{1: 2, 3: 4}}, - y: &testeditionspb.TestAllTypes{MapSfixed32Sfixed32: map[int32]int32{1: 2, 3: 5}}, - }, { - x: &testeditionspb.TestAllTypes{MapSfixed64Sfixed64: map[int64]int64{1: 2, 3: 4}}, - y: &testeditionspb.TestAllTypes{MapSfixed64Sfixed64: map[int64]int64{1: 2, 3: 5}}, - }, { - x: &testeditionspb.TestAllTypes{MapInt32Float: map[int32]float32{1: 2, 3: 4}}, - y: &testeditionspb.TestAllTypes{MapInt32Float: map[int32]float32{1: 2, 3: 5}}, - }, { - x: &testeditionspb.TestAllTypes{MapInt32Double: map[int32]float64{1: 2, 3: 4}}, - y: &testeditionspb.TestAllTypes{MapInt32Double: map[int32]float64{1: 2, 3: 5}}, - }, { - x: &testeditionspb.TestAllTypes{MapBoolBool: map[bool]bool{true: false, false: true}}, - y: &testeditionspb.TestAllTypes{MapBoolBool: map[bool]bool{true: false, false: false}}, - }, { - x: &testeditionspb.TestAllTypes{MapStringString: map[string]string{"a": "b", "c": "d"}}, - y: &testeditionspb.TestAllTypes{MapStringString: map[string]string{"a": "b", "c": "e"}}, - }, { - x: &testeditionspb.TestAllTypes{MapStringBytes: map[string][]byte{"a": []byte("b"), "c": []byte("d")}}, - y: &testeditionspb.TestAllTypes{MapStringBytes: map[string][]byte{"a": []byte("b"), "c": []byte("e")}}, - }, { - x: &testeditionspb.TestAllTypes{MapStringNestedMessage: map[string]*testeditionspb.TestAllTypes_NestedMessage{ - "a": {A: proto.Int32(1)}, - "b": {A: proto.Int32(2)}, - }}, - y: &testeditionspb.TestAllTypes{MapStringNestedMessage: map[string]*testeditionspb.TestAllTypes_NestedMessage{ - "a": {A: proto.Int32(1)}, - "b": {A: proto.Int32(3)}, - }}, - }, { - x: &testeditionspb.TestAllTypes{MapStringNestedEnum: map[string]testeditionspb.TestAllTypes_NestedEnum{ - "a": testeditionspb.TestAllTypes_FOO, - "b": testeditionspb.TestAllTypes_BAR, - }}, - y: &testeditionspb.TestAllTypes{MapStringNestedEnum: map[string]testeditionspb.TestAllTypes_NestedEnum{ - "a": testeditionspb.TestAllTypes_FOO, - "b": testeditionspb.TestAllTypes_BAZ, - }}, - }, - - // Extensions. - { - x: build(&testpb.TestAllExtensions{}, - extend(testpb.E_OptionalInt32, int32(1)), - ), - y: build(&testpb.TestAllExtensions{}, - extend(testpb.E_OptionalInt32, int32(2)), - ), - }, { - x: &testpb.TestAllExtensions{}, - y: build(&testpb.TestAllExtensions{}, - extend(testpb.E_OptionalInt32, int32(2)), - ), - }, - - // Unknown fields. - { - x: build(&testpb.TestAllTypes{}, unknown(protopack.Message{ - protopack.Tag{100000, protopack.VarintType}, protopack.Varint(1), - }.Marshal())), - y: build(&testpb.TestAllTypes{}, unknown(protopack.Message{ - protopack.Tag{100000, protopack.VarintType}, protopack.Varint(2), - }.Marshal())), - }, { - x: build(&testpb.TestAllTypes{}, unknown(protopack.Message{ - protopack.Tag{100000, protopack.VarintType}, protopack.Varint(1), - }.Marshal())), - y: &testpb.TestAllTypes{}, - }, { - x: build(&testeditionspb.TestAllTypes{}, unknown(protopack.Message{ - protopack.Tag{100000, protopack.VarintType}, protopack.Varint(1), - }.Marshal())), - y: build(&testeditionspb.TestAllTypes{}, unknown(protopack.Message{ - protopack.Tag{100000, protopack.VarintType}, protopack.Varint(2), - }.Marshal())), - }, { - x: build(&testeditionspb.TestAllTypes{}, unknown(protopack.Message{ - protopack.Tag{100000, protopack.VarintType}, protopack.Varint(1), - }.Marshal())), - y: &testeditionspb.TestAllTypes{}, - }, } + type xy struct { + X proto.Message + Y proto.Message + } + cloneAll := func(in []proto.Message) []proto.Message { + out := make([]proto.Message, len(in)) + for idx, msg := range in { + out[idx] = proto.Clone(msg) + } + return out + } + makeXY := func(x protobuild.Message, y protobuild.Message, messages ...proto.Message) []xy { + xs := makeMessages(x, cloneAll(messages)...) + ys := makeMessages(y, cloneAll(messages)...) + result := make([]xy, len(xs)) + for idx := range xs { + result[idx] = xy{ + X: xs[idx], + Y: ys[idx], + } + } + return result + } + makeTest := func(tmpl test, msgs []xy) []test { + result := make([]test, 0, len(msgs)) + for _, msg := range msgs { + tmpl.x = msg.X + tmpl.y = msg.Y + result = append(result, tmpl) + } + return result + } + + // Scalars. + + tests = append(tests, makeTest(test{desc: "Scalars"}, makeXY( + protobuild.Message{"optional_int32": 1}, + protobuild.Message{"optional_int32": 2}, + ))...) + + tests = append(tests, makeTest(test{desc: "Scalars"}, makeXY( + protobuild.Message{"optional_int64": 1}, + protobuild.Message{"optional_int64": 2}, + ))...) + + tests = append(tests, makeTest(test{desc: "Scalars"}, makeXY( + protobuild.Message{"optional_uint32": 1}, + protobuild.Message{"optional_uint32": 2}, + ))...) + + tests = append(tests, makeTest(test{desc: "Scalars"}, makeXY( + protobuild.Message{"optional_uint64": 1}, + protobuild.Message{"optional_uint64": 2}, + ))...) + + tests = append(tests, makeTest(test{desc: "Scalars"}, makeXY( + protobuild.Message{"optional_sint32": 1}, + protobuild.Message{"optional_sint32": 2}, + ))...) + + tests = append(tests, makeTest(test{desc: "Scalars"}, makeXY( + protobuild.Message{"optional_sint64": 1}, + protobuild.Message{"optional_sint64": 2}, + ))...) + + tests = append(tests, makeTest(test{desc: "Scalars"}, makeXY( + protobuild.Message{"optional_fixed32": 1}, + protobuild.Message{"optional_fixed32": 2}, + ))...) + + tests = append(tests, makeTest(test{desc: "Scalars"}, makeXY( + protobuild.Message{"optional_fixed64": 1}, + protobuild.Message{"optional_fixed64": 2}, + ))...) + + tests = append(tests, makeTest(test{desc: "Scalars"}, makeXY( + protobuild.Message{"optional_sfixed32": 1}, + protobuild.Message{"optional_sfixed32": 2}, + ))...) + + tests = append(tests, makeTest(test{desc: "Scalars"}, makeXY( + protobuild.Message{"optional_sfixed64": 1}, + protobuild.Message{"optional_sfixed64": 2}, + ))...) + + tests = append(tests, makeTest(test{desc: "Scalars"}, makeXY( + protobuild.Message{"optional_float": 1}, + protobuild.Message{"optional_float": 2}, + ))...) + + tests = append(tests, makeTest(test{desc: "Scalars"}, makeXY( + protobuild.Message{"optional_double": 1}, + protobuild.Message{"optional_double": 2}, + ))...) + + tests = append(tests, makeTest(test{desc: "Scalars"}, makeXY( + protobuild.Message{"optional_float": math.NaN()}, + protobuild.Message{"optional_float": 0}, + ))...) + + tests = append(tests, makeTest(test{desc: "Scalars"}, makeXY( + protobuild.Message{"optional_double": math.NaN()}, + protobuild.Message{"optional_double": 0}, + ))...) + + tests = append(tests, makeTest(test{desc: "Scalars"}, makeXY( + protobuild.Message{"optional_bool": true}, + protobuild.Message{"optional_bool": false}, + ))...) + + tests = append(tests, makeTest(test{desc: "Scalars"}, makeXY( + protobuild.Message{"optional_string": "a"}, + protobuild.Message{"optional_string": "b"}, + ))...) + + tests = append(tests, makeTest(test{desc: "Scalars"}, makeXY( + protobuild.Message{"optional_bytes": []byte("a")}, + protobuild.Message{"optional_bytes": []byte("b")}, + ))...) + + tests = append(tests, makeTest(test{desc: "Scalars"}, makeXY( + protobuild.Message{"optional_nested_enum": "FOO"}, + protobuild.Message{"optional_nested_enum": "BAR"}, + ))...) + + // Scalars (equal). + + tests = append(tests, makeTest(test{ + desc: "Scalars", + eq: true, + }, makeXY( + protobuild.Message{"optional_int32": 2}, + protobuild.Message{"optional_int32": 2}, + ))...) + + tests = append(tests, makeTest(test{ + desc: "Scalars", + eq: true, + }, makeXY( + protobuild.Message{"optional_int64": 2}, + protobuild.Message{"optional_int64": 2}, + ))...) + + tests = append(tests, makeTest(test{ + desc: "Scalars", + eq: true, + }, makeXY( + protobuild.Message{"optional_uint32": 2}, + protobuild.Message{"optional_uint32": 2}, + ))...) + + tests = append(tests, makeTest(test{ + desc: "Scalars", + eq: true, + }, makeXY( + protobuild.Message{"optional_uint64": 2}, + protobuild.Message{"optional_uint64": 2}, + ))...) + + tests = append(tests, makeTest(test{ + desc: "Scalars", + eq: true, + }, makeXY( + protobuild.Message{"optional_sint32": 2}, + protobuild.Message{"optional_sint32": 2}, + ))...) + + tests = append(tests, makeTest(test{ + desc: "Scalars", + eq: true, + }, makeXY( + protobuild.Message{"optional_sint64": 2}, + protobuild.Message{"optional_sint64": 2}, + ))...) + + tests = append(tests, makeTest(test{ + desc: "Scalars", + eq: true, + }, makeXY( + protobuild.Message{"optional_fixed32": 2}, + protobuild.Message{"optional_fixed32": 2}, + ))...) + + tests = append(tests, makeTest(test{ + desc: "Scalars", + eq: true, + }, makeXY( + protobuild.Message{"optional_fixed64": 2}, + protobuild.Message{"optional_fixed64": 2}, + ))...) + + tests = append(tests, makeTest(test{ + desc: "Scalars", + eq: true, + }, makeXY( + protobuild.Message{"optional_sfixed32": 2}, + protobuild.Message{"optional_sfixed32": 2}, + ))...) + + tests = append(tests, makeTest(test{ + desc: "Scalars", + eq: true, + }, makeXY( + protobuild.Message{"optional_sfixed64": 2}, + protobuild.Message{"optional_sfixed64": 2}, + ))...) + + tests = append(tests, makeTest(test{ + desc: "Scalars", + eq: true, + }, makeXY( + protobuild.Message{"optional_float": 2}, + protobuild.Message{"optional_float": 2}, + ))...) + + tests = append(tests, makeTest(test{ + desc: "Scalars", + eq: true, + }, makeXY( + protobuild.Message{"optional_double": 2}, + protobuild.Message{"optional_double": 2}, + ))...) + + tests = append(tests, makeTest(test{ + desc: "Scalars", + eq: true, + }, makeXY( + protobuild.Message{"optional_float": math.NaN()}, + protobuild.Message{"optional_float": math.NaN()}, + ))...) + + tests = append(tests, makeTest(test{ + desc: "Scalars", + eq: true, + }, makeXY( + protobuild.Message{"optional_double": math.NaN()}, + protobuild.Message{"optional_double": math.NaN()}, + ))...) + + tests = append(tests, makeTest(test{ + desc: "Scalars", + eq: true, + }, makeXY( + protobuild.Message{"optional_bool": true}, + protobuild.Message{"optional_bool": true}, + ))...) + + tests = append(tests, makeTest(test{ + desc: "Scalars", + eq: true, + }, makeXY( + protobuild.Message{"optional_string": "abc"}, + protobuild.Message{"optional_string": "abc"}, + ))...) + + tests = append(tests, makeTest(test{ + desc: "Scalars", + eq: true, + }, makeXY( + protobuild.Message{"optional_bytes": []byte("abc")}, + protobuild.Message{"optional_bytes": []byte("abc")}, + ))...) + + tests = append(tests, makeTest(test{ + desc: "Scalars", + eq: true, + }, makeXY( + protobuild.Message{"optional_nested_enum": "FOO"}, + protobuild.Message{"optional_nested_enum": "FOO"}, + ))...) + + // Presence. + + tests = append(tests, makeTest(test{desc: "Presence"}, makeXY( + protobuild.Message{}, + protobuild.Message{"optional_int32": 0}, + ))...) + + tests = append(tests, makeTest(test{desc: "Presence"}, makeXY( + protobuild.Message{}, + protobuild.Message{"optional_int64": 0}, + ))...) + + tests = append(tests, makeTest(test{desc: "Presence"}, makeXY( + protobuild.Message{}, + protobuild.Message{"optional_uint32": 0}, + ))...) + + tests = append(tests, makeTest(test{desc: "Presence"}, makeXY( + protobuild.Message{}, + protobuild.Message{"optional_uint64": 0}, + ))...) + + tests = append(tests, makeTest(test{desc: "Presence"}, makeXY( + protobuild.Message{}, + protobuild.Message{"optional_sint32": 0}, + ))...) + + tests = append(tests, makeTest(test{desc: "Presence"}, makeXY( + protobuild.Message{}, + protobuild.Message{"optional_sint64": 0}, + ))...) + + tests = append(tests, makeTest(test{desc: "Presence"}, makeXY( + protobuild.Message{}, + protobuild.Message{"optional_fixed32": 0}, + ))...) + + tests = append(tests, makeTest(test{desc: "Presence"}, makeXY( + protobuild.Message{}, + protobuild.Message{"optional_fixed64": 0}, + ))...) + + tests = append(tests, makeTest(test{desc: "Presence"}, makeXY( + protobuild.Message{}, + protobuild.Message{"optional_sfixed32": 0}, + ))...) + + tests = append(tests, makeTest(test{desc: "Presence"}, makeXY( + protobuild.Message{}, + protobuild.Message{"optional_sfixed64": 0}, + ))...) + + tests = append(tests, makeTest(test{desc: "Presence"}, makeXY( + protobuild.Message{}, + protobuild.Message{"optional_float": 0}, + ))...) + + tests = append(tests, makeTest(test{desc: "Presence"}, makeXY( + protobuild.Message{}, + protobuild.Message{"optional_double": 0}, + ))...) + + tests = append(tests, makeTest(test{desc: "Presence"}, makeXY( + protobuild.Message{}, + protobuild.Message{"optional_bool": false}, + ))...) + + tests = append(tests, makeTest(test{desc: "Presence"}, makeXY( + protobuild.Message{}, + protobuild.Message{"optional_string": ""}, + ))...) + + tests = append(tests, makeTest(test{desc: "Presence"}, makeXY( + protobuild.Message{}, + protobuild.Message{"optional_bytes": []byte{}}, + ))...) + + tests = append(tests, makeTest(test{desc: "Presence"}, makeXY( + protobuild.Message{}, + protobuild.Message{"optional_nested_enum": "FOO"}, + ))...) + + // Proto2 default values are not considered by Equal, so the following are still unequal. + + allTypesNoProto3 := []proto.Message{ + &testpb.TestAllTypes{}, + // test3pb.TestAllTypes is intentionally missing: + // proto3 does not support default values. + // proto3 does not support groups. + &testpb.TestAllExtensions{}, + &testeditionspb.TestAllTypes{}, + } + + tests = append(tests, makeTest(test{desc: "Default"}, makeXY( + protobuild.Message{"default_int32": 81}, + protobuild.Message{}, + allTypesNoProto3..., + ))...) + + tests = append(tests, makeTest(test{desc: "Default"}, makeXY( + protobuild.Message{}, + protobuild.Message{"default_int32": 81}, + allTypesNoProto3..., + ))...) + + tests = append(tests, makeTest(test{desc: "Default"}, makeXY( + protobuild.Message{}, + protobuild.Message{"default_int64": 82}, + allTypesNoProto3..., + ))...) + + tests = append(tests, makeTest(test{desc: "Default"}, makeXY( + protobuild.Message{}, + protobuild.Message{"default_uint32": 83}, + allTypesNoProto3..., + ))...) + + tests = append(tests, makeTest(test{desc: "Default"}, makeXY( + protobuild.Message{}, + protobuild.Message{"default_uint64": 84}, + allTypesNoProto3..., + ))...) + + tests = append(tests, makeTest(test{desc: "Default"}, makeXY( + protobuild.Message{}, + protobuild.Message{"default_sint32": -85}, + allTypesNoProto3..., + ))...) + + tests = append(tests, makeTest(test{desc: "Default"}, makeXY( + protobuild.Message{}, + protobuild.Message{"default_sint64": 86}, + allTypesNoProto3..., + ))...) + + tests = append(tests, makeTest(test{desc: "Default"}, makeXY( + protobuild.Message{}, + protobuild.Message{"default_fixed32": 87}, + allTypesNoProto3..., + ))...) + + tests = append(tests, makeTest(test{desc: "Default"}, makeXY( + protobuild.Message{}, + protobuild.Message{"default_fixed64": 87}, + allTypesNoProto3..., + ))...) + + tests = append(tests, makeTest(test{desc: "Default"}, makeXY( + protobuild.Message{}, + protobuild.Message{"default_sfixed32": 89}, + allTypesNoProto3..., + ))...) + + tests = append(tests, makeTest(test{desc: "Default"}, makeXY( + protobuild.Message{}, + protobuild.Message{"default_sfixed64": -90}, + allTypesNoProto3..., + ))...) + + tests = append(tests, makeTest(test{desc: "Default"}, makeXY( + protobuild.Message{}, + protobuild.Message{"default_float": 91.5}, + allTypesNoProto3..., + ))...) + + tests = append(tests, makeTest(test{desc: "Default"}, makeXY( + protobuild.Message{}, + protobuild.Message{"default_double": 92e3}, + allTypesNoProto3..., + ))...) + + tests = append(tests, makeTest(test{desc: "Default"}, makeXY( + protobuild.Message{}, + protobuild.Message{"default_bool": true}, + allTypesNoProto3..., + ))...) + + tests = append(tests, makeTest(test{desc: "Default"}, makeXY( + protobuild.Message{}, + protobuild.Message{"default_string": "hello"}, + allTypesNoProto3..., + ))...) + + tests = append(tests, makeTest(test{desc: "Default"}, makeXY( + protobuild.Message{}, + protobuild.Message{"default_bytes": []byte("world")}, + allTypesNoProto3..., + ))...) + + tests = append(tests, makeTest(test{desc: "Default"}, makeXY( + protobuild.Message{}, + protobuild.Message{"default_nested_enum": "BAR"}, + &testpb.TestAllTypes{}, + // test3pb.TestAllTypes is intentionally missing: + // proto3 does not support default values. + // testpb.TestAllExtensions is intentionally missing: + // extensions cannot declare nested enums. + &testeditionspb.TestAllTypes{}, + ))...) + + // Groups. + + tests = append(tests, makeTest(test{desc: "Groups"}, makeXY( + protobuild.Message{"optionalgroup": protobuild.Message{ + "a": 1, + }}, + protobuild.Message{"optionalgroup": protobuild.Message{ + "a": 2, + }}, + allTypesNoProto3..., + ))...) + + tests = append(tests, makeTest(test{desc: "Groups"}, makeXY( + protobuild.Message{}, + protobuild.Message{"optionalgroup": protobuild.Message{}}, + allTypesNoProto3..., + ))...) + + // Messages. + + tests = append(tests, makeTest(test{desc: "Messages"}, makeXY( + protobuild.Message{"optional_nested_message": protobuild.Message{ + "a": 1, + }}, + protobuild.Message{"optional_nested_message": protobuild.Message{ + "a": 2, + }}, + ))...) + + tests = append(tests, makeTest(test{desc: "Messages"}, makeXY( + protobuild.Message{}, + protobuild.Message{"optional_nested_message": protobuild.Message{}}, + ))...) + + // Lists. + + tests = append(tests, makeTest(test{desc: "Lists"}, makeXY( + protobuild.Message{"repeated_int32": []int32{1}}, + protobuild.Message{"repeated_int32": []int32{1, 2}}, + ))...) + + tests = append(tests, makeTest(test{desc: "Lists"}, makeXY( + protobuild.Message{"repeated_int32": []int32{1, 2}}, + protobuild.Message{"repeated_int32": []int32{1, 3}}, + ))...) + + tests = append(tests, makeTest(test{desc: "Lists"}, makeXY( + protobuild.Message{"repeated_int64": []int64{1, 2}}, + protobuild.Message{"repeated_int64": []int64{1, 3}}, + ))...) + + tests = append(tests, makeTest(test{desc: "Lists"}, makeXY( + protobuild.Message{"repeated_uint32": []uint32{1, 2}}, + protobuild.Message{"repeated_uint32": []uint32{1, 3}}, + ))...) + + tests = append(tests, makeTest(test{desc: "Lists"}, makeXY( + protobuild.Message{"repeated_uint64": []uint64{1, 2}}, + protobuild.Message{"repeated_uint64": []uint64{1, 3}}, + ))...) + + tests = append(tests, makeTest(test{desc: "Lists"}, makeXY( + protobuild.Message{"repeated_sint32": []int32{1, 2}}, + protobuild.Message{"repeated_sint32": []int32{1, 3}}, + ))...) + + tests = append(tests, makeTest(test{desc: "Lists"}, makeXY( + protobuild.Message{"repeated_sint64": []int64{1, 2}}, + protobuild.Message{"repeated_sint64": []int64{1, 3}}, + ))...) + + tests = append(tests, makeTest(test{desc: "Lists"}, makeXY( + protobuild.Message{"repeated_fixed32": []uint32{1, 2}}, + protobuild.Message{"repeated_fixed32": []uint32{1, 3}}, + ))...) + + tests = append(tests, makeTest(test{desc: "Lists"}, makeXY( + protobuild.Message{"repeated_fixed64": []uint64{1, 2}}, + protobuild.Message{"repeated_fixed64": []uint64{1, 3}}, + ))...) + + tests = append(tests, makeTest(test{desc: "Lists"}, makeXY( + protobuild.Message{"repeated_sfixed32": []int32{1, 2}}, + protobuild.Message{"repeated_sfixed32": []int32{1, 3}}, + ))...) + + tests = append(tests, makeTest(test{desc: "Lists"}, makeXY( + protobuild.Message{"repeated_sfixed64": []int32{1, 2}}, + protobuild.Message{"repeated_sfixed64": []int32{1, 3}}, + ))...) + + tests = append(tests, makeTest(test{desc: "Lists"}, makeXY( + protobuild.Message{"repeated_float": []float32{1, 2}}, + protobuild.Message{"repeated_float": []float32{1, 3}}, + ))...) + + tests = append(tests, makeTest(test{desc: "Lists"}, makeXY( + protobuild.Message{"repeated_double": []float64{1, 2}}, + protobuild.Message{"repeated_double": []float64{1, 3}}, + ))...) + + tests = append(tests, makeTest(test{desc: "Lists"}, makeXY( + protobuild.Message{"repeated_bool": []bool{true, false}}, + protobuild.Message{"repeated_bool": []bool{true, true}}, + ))...) + + tests = append(tests, makeTest(test{desc: "Lists"}, makeXY( + protobuild.Message{"repeated_string": []string{"a", "b"}}, + protobuild.Message{"repeated_string": []string{"a", "c"}}, + ))...) + + tests = append(tests, makeTest(test{desc: "Lists"}, makeXY( + protobuild.Message{"repeated_bytes": [][]byte{[]byte("a"), []byte("b")}}, + protobuild.Message{"repeated_bytes": [][]byte{[]byte("a"), []byte("c")}}, + ))...) + + tests = append(tests, makeTest(test{desc: "Lists"}, makeXY( + protobuild.Message{"repeated_nested_enum": []string{"FOO"}}, + protobuild.Message{"repeated_nested_enum": []string{"BAR"}}, + ))...) + + tests = append(tests, makeTest(test{desc: "Lists"}, makeXY( + protobuild.Message{"repeatedgroup": []protobuild.Message{ + {"a": 1}, + {"a": 2}, + }}, + protobuild.Message{"repeatedgroup": []protobuild.Message{ + {"a": 1}, + {"a": 3}, + }}, + allTypesNoProto3..., + ))...) + + tests = append(tests, makeTest(test{desc: "Lists"}, makeXY( + protobuild.Message{"repeated_nested_message": []protobuild.Message{ + {"a": 1}, + {"a": 2}, + }}, + protobuild.Message{"repeated_nested_message": []protobuild.Message{ + {"a": 1}, + {"a": 3}, + }}, + ))...) + + // Maps: various configurations. + + allTypesNoExt := []proto.Message{ + &testpb.TestAllTypes{}, + &test3pb.TestAllTypes{}, + // TestAllExtensions is intentionally missing: + // protoc prevents adding a map field to an extension: + // Map fields are not allowed to be extensions. + &testeditionspb.TestAllTypes{}, + } + + tests = append(tests, makeTest(test{desc: "MapsDifferent"}, makeXY( + protobuild.Message{"map_int32_int32": map[int32]int32{1: 2}}, + protobuild.Message{"map_int32_int32": map[int32]int32{3: 4}}, + allTypesNoExt..., + ))...) + + tests = append(tests, makeTest(test{desc: "MapsAdditionalY"}, makeXY( + protobuild.Message{"map_int32_int32": map[int32]int32{1: 2}}, + protobuild.Message{"map_int32_int32": map[int32]int32{1: 2, 3: 4}}, + allTypesNoExt..., + ))...) + + tests = append(tests, makeTest(test{desc: "MapsAdditionalX"}, makeXY( + protobuild.Message{"map_int32_int32": map[int32]int32{1: 2, 3: 4}}, + protobuild.Message{"map_int32_int32": map[int32]int32{1: 2}}, + allTypesNoExt..., + ))...) + + // Maps: various types. + tests = append(tests, makeTest(test{desc: "MapsTypes"}, makeXY( + protobuild.Message{"map_int32_int32": map[int32]int32{1: 2, 3: 4}}, + protobuild.Message{"map_int32_int32": map[int32]int32{1: 2, 3: 5}}, + allTypesNoExt..., + ))...) + + tests = append(tests, makeTest(test{desc: "MapsTypes"}, makeXY( + protobuild.Message{"map_int64_int64": map[int64]int64{1: 2, 3: 4}}, + protobuild.Message{"map_int64_int64": map[int64]int64{1: 2, 3: 5}}, + allTypesNoExt..., + ))...) + + tests = append(tests, makeTest(test{desc: "MapsTypes"}, makeXY( + protobuild.Message{"map_uint32_uint32": map[uint32]uint32{1: 2, 3: 4}}, + protobuild.Message{"map_uint32_uint32": map[uint32]uint32{1: 2, 3: 5}}, + allTypesNoExt..., + ))...) + + tests = append(tests, makeTest(test{desc: "MapsTypes"}, makeXY( + protobuild.Message{"map_uint64_uint64": map[uint64]uint64{1: 2, 3: 4}}, + protobuild.Message{"map_uint64_uint64": map[uint64]uint64{1: 2, 3: 5}}, + allTypesNoExt..., + ))...) + + tests = append(tests, makeTest(test{desc: "MapsTypes"}, makeXY( + protobuild.Message{"map_sint32_sint32": map[int32]int32{1: 2, 3: 4}}, + protobuild.Message{"map_sint32_sint32": map[int32]int32{1: 2, 3: 5}}, + allTypesNoExt..., + ))...) + + tests = append(tests, makeTest(test{desc: "MapsTypes"}, makeXY( + protobuild.Message{"map_sint64_sint64": map[int64]int64{1: 2, 3: 4}}, + protobuild.Message{"map_sint64_sint64": map[int64]int64{1: 2, 3: 5}}, + allTypesNoExt..., + ))...) + + tests = append(tests, makeTest(test{desc: "MapsTypes"}, makeXY( + protobuild.Message{"map_fixed32_fixed32": map[uint32]uint32{1: 2, 3: 4}}, + protobuild.Message{"map_fixed32_fixed32": map[uint32]uint32{1: 2, 3: 5}}, + allTypesNoExt..., + ))...) + + tests = append(tests, makeTest(test{desc: "MapsTypes"}, makeXY( + protobuild.Message{"map_fixed64_fixed64": map[uint64]uint64{1: 2, 3: 4}}, + protobuild.Message{"map_fixed64_fixed64": map[uint64]uint64{1: 2, 3: 5}}, + allTypesNoExt..., + ))...) + + tests = append(tests, makeTest(test{desc: "MapsTypes"}, makeXY( + protobuild.Message{"map_sfixed32_sfixed32": map[int32]int32{1: 2, 3: 4}}, + protobuild.Message{"map_sfixed32_sfixed32": map[int32]int32{1: 2, 3: 5}}, + allTypesNoExt..., + ))...) + + tests = append(tests, makeTest(test{desc: "MapsTypes"}, makeXY( + protobuild.Message{"map_sfixed64_sfixed64": map[int64]int64{1: 2, 3: 4}}, + protobuild.Message{"map_sfixed64_sfixed64": map[int64]int64{1: 2, 3: 5}}, + allTypesNoExt..., + ))...) + + tests = append(tests, makeTest(test{desc: "MapsTypes"}, makeXY( + protobuild.Message{"map_int32_float": map[int32]float32{1: 2, 3: 4}}, + protobuild.Message{"map_int32_float": map[int32]float32{1: 2, 3: 5}}, + allTypesNoExt..., + ))...) + + tests = append(tests, makeTest(test{desc: "MapsTypes"}, makeXY( + protobuild.Message{"map_int32_double": map[int32]float64{1: 2, 3: 4}}, + protobuild.Message{"map_int32_double": map[int32]float64{1: 2, 3: 5}}, + allTypesNoExt..., + ))...) + + tests = append(tests, makeTest(test{desc: "MapsTypes"}, makeXY( + protobuild.Message{"map_bool_bool": map[bool]bool{true: false, false: true}}, + protobuild.Message{"map_bool_bool": map[bool]bool{true: false, false: false}}, + allTypesNoExt..., + ))...) + + tests = append(tests, makeTest(test{desc: "MapsTypes"}, makeXY( + protobuild.Message{"map_string_string": map[string]string{"a": "b", "c": "d"}}, + protobuild.Message{"map_string_string": map[string]string{"a": "b", "c": "e"}}, + allTypesNoExt..., + ))...) + + tests = append(tests, makeTest(test{desc: "MapsTypes"}, makeXY( + protobuild.Message{"map_string_bytes": map[string][]byte{"a": []byte("b"), "c": []byte("d")}}, + protobuild.Message{"map_string_bytes": map[string][]byte{"a": []byte("b"), "c": []byte("e")}}, + allTypesNoExt..., + ))...) + + tests = append(tests, makeTest(test{desc: "MapsTypes"}, makeXY( + protobuild.Message{"map_string_nested_message": map[string]protobuild.Message{ + "a": {"a": int32(1)}, + "b": {"a": int32(2)}, + }}, + protobuild.Message{"map_string_nested_message": map[string]protobuild.Message{ + "a": {"a": int32(1)}, + "b": {"a": int32(3)}, + }}, + allTypesNoExt..., + ))...) + + tests = append(tests, makeTest(test{desc: "MapsTypes"}, makeXY( + protobuild.Message{"map_string_nested_enum": map[string]string{ + "a": "FOO", + "b": "BAR", + }}, + protobuild.Message{"map_string_nested_enum": map[string]string{ + "a": "FOO", + "b": "BAZ", + }}, + allTypesNoExt..., + ))...) + + // Unknown fields. + + tests = append(tests, makeTest(test{desc: "Unknown"}, makeXY( + protobuild.Message{protobuild.Unknown: protopack.Message{ + protopack.Tag{100000, protopack.VarintType}, protopack.Varint(1), + }.Marshal()}, + protobuild.Message{protobuild.Unknown: protopack.Message{ + protopack.Tag{100000, protopack.VarintType}, protopack.Varint(2), + }.Marshal()}, + ))...) + + tests = append(tests, makeTest(test{desc: "Unknown"}, makeXY( + protobuild.Message{protobuild.Unknown: protopack.Message{ + protopack.Tag{100000, protopack.VarintType}, protopack.Varint(1), + }.Marshal()}, + protobuild.Message{}, + ))...) + + // Extensions. + onlyExts := []proto.Message{ + &testpb.TestAllExtensions{}, + &testeditionspb.TestAllExtensions{}, + } + + tests = append(tests, makeTest(test{desc: "Extensions"}, makeXY( + protobuild.Message{"optional_int32": 1}, + protobuild.Message{"optional_int32": 2}, + onlyExts..., + ))...) + + tests = append(tests, makeTest(test{desc: "Extensions"}, makeXY( + protobuild.Message{}, + protobuild.Message{"optional_int32": 2}, + onlyExts..., + ))...) + for _, tt := range tests { - if !tt.eq && !proto.Equal(tt.x, tt.x) { - t.Errorf("Equal(x, x) = false, want true\n==== x ====\n%v", prototext.Format(tt.x)) - } - if !tt.eq && !proto.Equal(tt.y, tt.y) { - t.Errorf("Equal(y, y) = false, want true\n==== y ====\n%v", prototext.Format(tt.y)) - } - if eq := proto.Equal(tt.x, tt.y); eq != tt.eq { - t.Errorf("Equal(x, y) = %v, want %v\n==== x ====\n%v==== y ====\n%v", eq, tt.eq, prototext.Format(tt.x), prototext.Format(tt.y)) + desc := tt.desc + if desc == "" { + desc = "Untitled" } + desc += fmt.Sprintf("/x=%T y=%T", tt.x, tt.y) + t.Run(desc, func(t *testing.T) { + if !tt.eq && !proto.Equal(tt.x, tt.x) { + t.Errorf("Equal(x, x) = false, want true\n==== x ====\n%v", prototext.Format(tt.x)) + } + if !tt.eq && !proto.Equal(tt.y, tt.y) { + t.Errorf("Equal(y, y) = false, want true\n==== y ====\n%v", prototext.Format(tt.y)) + } + if eq := proto.Equal(tt.x, tt.y); eq != tt.eq { + t.Errorf("Equal(x, y) = %v, want %v\n==== x ====\n%v==== y ====\n%v", eq, tt.eq, prototext.Format(tt.x), prototext.Format(tt.y)) + } + }) } }