thrift-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [thrift] BytedanceRPC commented on a change in pull request #2307: THRIFT-5337 Go set fields write improvement
Date Thu, 04 Feb 2021 03:16:59 GMT

BytedanceRPC commented on a change in pull request #2307:
URL: https://github.com/apache/thrift/pull/2307#discussion_r569917128



##########
File path: lib/go/test/tests/equals_test.go
##########
@@ -0,0 +1,243 @@
+package tests
+
+import (
+	"equalstest"
+	"strconv"
+	"testing"
+)
+
+func TestEquals(t *testing.T) {
+	// test basic field
+	basicTgt, basicSrc := genBasicFoo(), genBasicFoo()
+	if !basicTgt.Equals(basicSrc) {
+		t.Error("BasicEqualsFoo.Equals() test failed")
+	}
+	basicSrc.EnumFoo = equalstest.EnumFoo_e2
+	if basicTgt.Equals(basicSrc) {
+		t.Error("BasicEqualsFoo.Equals() test failed")
+	}
+	basicSrc = genBasicFoo()
+	basicSrc.OptBoolFoo = nil
+	if basicTgt.Equals(basicSrc) || basicSrc.Equals(basicTgt) {
+		t.Error("BasicEqualsFoo.Equals() test failed")
+	}
+	if !(&equalstest.BasicEqualsFoo{}).Equals(&equalstest.BasicEqualsFoo{}) {
+		t.Error("BasicEqualsFoo.Equals() test failed")
+	}
+	// test struct field
+	structTgt, structSrc := genStructFoo(), genStructFoo()
+	if !structTgt.Equals(structSrc) {
+		t.Error("StructEqualsFoo.Equals() test failed")
+	}
+	structSrc.OptStructFoo.EnumFoo = equalstest.EnumFoo_e2
+	if structTgt.Equals(structSrc) {
+		t.Error("StructEqualsFoo.Equals() test failed")
+	}
+	structSrc = genStructFoo()
+	structSrc.OptStructFoo = nil
+	if structTgt.Equals(structSrc) || structSrc.Equals(structTgt) {
+		t.Error("StructEqualsFoo.Equals() test failed")
+	}
+	if !(&equalstest.StructEqualsFoo{}).Equals(&equalstest.StructEqualsFoo{}) {
+		t.Error("StructEqualsFoo.Equals() test failed")
+	}
+	// test list field
+	listTgt, listSrc := genListFoo(), genListFoo()
+	if !listTgt.Equals(listSrc) {
+		t.Error("ListEqualsFoo.Equals() test failed")
+	}
+	listSrc.OptI64StringMapListFoo[0][1] = "0"
+	if listTgt.Equals(listSrc) {
+		t.Error("ListEqualsFoo.Equals() test failed")
+	}
+	listSrc = genListFoo()
+	listSrc.OptI64StringMapListFoo = nil
+	if listTgt.Equals(listSrc) || listSrc.Equals(listTgt) {
+		t.Error("ListEqualsFoo.Equals() test failed")
+	}
+	if !(&equalstest.ListEqualsFoo{}).Equals(&equalstest.ListEqualsFoo{}) {
+		t.Error("ListEqualsFoo.Equals() test failed")
+	}
+	// test set field
+	setTgt, setSrc := genSetFoo(), genSetFoo()
+	if !setTgt.Equals(setSrc) {
+		t.Error("SetEqualsFoo.Equals() test failed")
+	}
+	setSrc.OptI64StringMapSetFoo[0][1] = "0"
+	if setTgt.Equals(setSrc) {
+		t.Error("SetEqualsFoo.Equals() test failed")
+	}
+	setSrc = genSetFoo()
+	setSrc.OptI64StringMapSetFoo = nil
+	if setTgt.Equals(setSrc) || setSrc.Equals(setTgt) {
+		t.Error("SetEqualsFoo.Equals() test failed")
+	}
+	if !(&equalstest.SetEqualsFoo{}).Equals(&equalstest.SetEqualsFoo{}) {
+		t.Error("SetEqualsFoo.Equals() test failed")
+	}
+	// test map field
+	mapTgt, mapSrc := genMapFoo(), genMapFoo()
+	if !mapTgt.Equals(mapSrc) {
+		t.Error("MapEqualsFoo.Equals() test failed")
+	}
+	mapSrc.OptI64I64StringMapMapFoo[1][1] = "0"
+	if mapTgt.Equals(mapSrc) {
+		t.Error("MapEqualsFoo.Equals() test failed")
+	}
+	mapSrc = genMapFoo()
+	mapSrc.OptI64I64StringMapMapFoo = nil
+	if mapTgt.Equals(mapSrc) || mapSrc.Equals(mapTgt) {
+		t.Error("MapEqualsFoo.Equals() test failed")
+	}
+	if !(&equalstest.MapEqualsFoo{}).Equals(&equalstest.MapEqualsFoo{}) {
+		t.Error("MapEqualsFoo.Equals() test failed")
+	}
+}
+
+func genBasicFoo() *equalstest.BasicEqualsFoo {
+	return &equalstest.BasicEqualsFoo{
+		BoolFoo:      true,
+		OptBoolFoo:   &(&struct{ x bool }{true}).x,
+		I8Foo:        1,
+		OptI8Foo:     &(&struct{ x int8 }{1}).x,
+		I16Foo:       2,
+		OptI16Foo:    &(&struct{ x int16 }{2}).x,
+		I32Foo:       3,
+		OptI32Foo:    &(&struct{ x int32 }{3}).x,
+		I64Foo:       4,
+		OptI64Foo:    &(&struct{ x int64 }{4}).x,
+		DoubleFoo:    5,
+		OptDoubleFoo: &(&struct{ x float64 }{5}).x,
+		StrFoo:       "6",
+		OptStrFoo:    &(&struct{ x string }{"6"}).x,
+		BinFoo:       []byte("7"),
+		OptBinFoo:    []byte("7"),
+		EnumFoo:      equalstest.EnumFoo_e1,
+		OptEnumFoo:   &(&struct{ x equalstest.EnumFoo }{equalstest.EnumFoo_e1}).x,
+		MyByteFoo:    equalstest.Mybyte(8),
+		OptMyByteFoo: &(&struct{ x equalstest.Mybyte }{8}).x,
+		MyStrFoo:     equalstest.Mystr("9"),
+		OptMyStrFoo:  &(&struct{ x equalstest.Mystr }{"9"}).x,
+		MyBinFoo:     equalstest.Mybin("10"),
+		OptMyBinFoo:  &(&struct{ x equalstest.Mybin }{equalstest.Mybin("10")}).x,

Review comment:
       I think it shoud be just `OptMyBinFoo:  equalstest.Mybin("10"),`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



Mime
View raw message