From notifications-return-981-archive-asf-public=cust-asf.ponee.io@thrift.apache.org Wed Feb 3 18:18:03 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 343ED18062B for ; Wed, 3 Feb 2021 19:18:03 +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 A335163F55 for ; Wed, 3 Feb 2021 18:18:02 +0000 (UTC) Received: (qmail 97129 invoked by uid 500); 3 Feb 2021 18:18:01 -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 97096 invoked by uid 99); 3 Feb 2021 18:18:01 -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; Wed, 03 Feb 2021 18:18:01 +0000 From: =?utf-8?q?GitBox?= To: notifications@thrift.apache.org Subject: =?utf-8?q?=5BGitHub=5D_=5Bthrift=5D_fishy_commented_on_a_change_in_pull_requ?= =?utf-8?q?est_=232307=3A_THRIFT-5337_Go_set_fields_write_improvement?= Message-ID: <161237628118.15632.2609381473268431066.asfpy@gitbox.apache.org> Date: Wed, 03 Feb 2021 18:18:01 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit References: In-Reply-To: fishy commented on a change in pull request #2307: URL: https://github.com/apache/thrift/pull/2307#discussion_r569640611 ########## 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: Oh I think you just misses another level of `&()` around the whole thing. But this is getting really hard to read so please just use some local variables instead. ---------------------------------------------------------------- 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