From notifications-return-996-archive-asf-public=cust-asf.ponee.io@thrift.apache.org Thu Feb 4 03:17:01 2021 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mxout1-he-de.apache.org (mxout1-he-de.apache.org [95.216.194.37]) by mx-eu-01.ponee.io (Postfix) with ESMTPS id 5CFA218062B for ; Thu, 4 Feb 2021 04:17:01 +0100 (CET) Received: from mail.apache.org (mailroute1-lw-us.apache.org [207.244.88.153]) by mxout1-he-de.apache.org (ASF Mail Server at mxout1-he-de.apache.org) with SMTP id D2D4E64311 for ; Thu, 4 Feb 2021 03:17:00 +0000 (UTC) Received: (qmail 68800 invoked by uid 500); 4 Feb 2021 03:17:00 -0000 Mailing-List: contact notifications-help@thrift.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@thrift.apache.org Delivered-To: mailing list notifications@thrift.apache.org Received: (qmail 68790 invoked by uid 99); 4 Feb 2021 03:17:00 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Feb 2021 03:16:59 +0000 From: =?utf-8?q?GitBox?= To: notifications@thrift.apache.org Subject: =?utf-8?q?=5BGitHub=5D_=5Bthrift=5D_BytedanceRPC_commented_on_a_change_in_pu?= =?utf-8?q?ll_request_=232307=3A_THRIFT-5337_Go_set_fields_write_improvement?= Message-ID: <161240861990.15632.7252278258790018794.asfpy@gitbox.apache.org> Date: Thu, 04 Feb 2021 03:16:59 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit References: In-Reply-To: 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