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 Wed, 03 Feb 2021 01:09:50 GMT

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



##########
File path: compiler/cpp/src/thrift/generate/t_go_generator.cc
##########
@@ -1851,6 +1864,65 @@ void t_go_generator::generate_go_struct_writer(ostream& out,
   }
 }
 
+void t_go_generator::generate_go_struct_equals(ostream& out,
+                                               t_struct* tstruct,
+                                               const string& tstruct_name,
+                                               bool is_args_or_result) {
+  if (is_args_or_result) {
+    return;
+  }

Review comment:
       looks reasonable, thanks for suggestion.

##########
File path: compiler/cpp/src/thrift/generate/t_go_generator.cc
##########
@@ -3463,6 +3550,112 @@ void t_go_generator::generate_serialize_list_element(ostream&
out, t_list* tlist
   generate_serialize_field(out, &efield, prefix);
 }
 
+/**
+ * Compares any type
+ */
+void t_go_generator::generate_go_equals(std::ostream& out,
+                                           t_type* ori_type,

Review comment:
       not sure is the `std::` making indentation looks weird. Indentations looks proper after
I remove `std::` and apply `clang-format`.
   To avoid unnecessary change, I only apply the output of clang-format on my changes in `compiler/cpp/src/thrift/generate/t_go_generator.cc`.

##########
File path: lib/go/test/EqualsTest.thrift
##########
@@ -0,0 +1,81 @@
+enum EnumFoo {
+  e1
+  e2
+}
+
+struct BasicEqualsFoo {
+  1: bool BoolFoo,
+  2: optional bool OptBoolFoo,
+  3: i8 I8Foo,
+  4: optional i8 OptI8Foo,
+  5: i16 I16Foo,
+  6: optional i16 OptI16Foo,
+  7: i32 I32Foo,
+  8: optional i32 OptI32Foo,
+  9: i64 I64Foo,
+  10: optional i64 OptI64Foo,
+  11: double DoubleFoo,
+  12: optional double OptDoubleFoo,
+  13: string StrFoo,
+  14: optional string OptStrFoo,
+  15: binary BinFoo,
+  16: optional binary OptBinFoo,
+  17: EnumFoo EnumFoo,
+  18: optional EnumFoo OptEnumFoo,
+}

Review comment:
       good suggestion

##########
File path: lib/go/test/tests/equals_test.go
##########
@@ -0,0 +1,174 @@
+package tests
+
+import (
+	"equalstest"
+	"strconv"
+	"testing"
+)
+
+func TestEquals(t *testing.T) {
+	basicTgt, basicSrc := genBasicFoo(), genBasicFoo()
+	if !basicTgt.Equals(basicSrc) {
+		t.Fatal("BasicEqualsFoo.Equals() test failed")

Review comment:
       Thanks for suggestion

##########
File path: lib/go/test/tests/equals_test.go
##########
@@ -0,0 +1,174 @@
+package tests
+
+import (
+	"equalstest"
+	"strconv"
+	"testing"
+)
+
+func TestEquals(t *testing.T) {
+	basicTgt, basicSrc := genBasicFoo(), genBasicFoo()
+	if !basicTgt.Equals(basicSrc) {
+		t.Fatal("BasicEqualsFoo.Equals() test failed")
+	}
+	basicSrc.EnumFoo = equalstest.EnumFoo_e2
+	if basicTgt.Equals(basicSrc) {
+		t.Fatal("BasicEqualsFoo.Equals() test failed")
+	}
+	structTgt, structSrc := genStructFoo(), genStructFoo()
+	if !structTgt.Equals(structSrc) {
+		t.Fatal("StructEqualsFoo.Equals() test failed")
+	}
+	structSrc.OptStructFoo.EnumFoo = equalstest.EnumFoo_e2
+	if structTgt.Equals(structSrc) {
+		t.Fatal("StructEqualsFoo.Equals() test failed")
+	}
+	listTgt, listSrc := genListFoo(), genListFoo()
+	if !listTgt.Equals(listSrc) {
+		t.Fatal("ListEqualsFoo.Equals() test failed")
+	}
+	listSrc.OptI64StringMapListFoo[0][1] = "0"
+	if listTgt.Equals(listSrc) {
+		t.Fatal("ListEqualsFoo.Equals() test failed")
+	}
+	setTgt, setSrc := genSetFoo(), genSetFoo()
+	if !setTgt.Equals(setSrc) {
+		t.Fatal("SetEqualsFoo.Equals() test failed")
+	}
+	setSrc.OptI64StringMapSetFoo[0][1] = "0"
+	if setTgt.Equals(setSrc) {
+		t.Fatal("SetEqualsFoo.Equals() test failed")
+	}
+	mapTgt, mapSrc := genMapFoo(), genMapFoo()
+	if !mapTgt.Equals(mapSrc) {
+		t.Fatal("MapEqualsFoo.Equals() test failed")
+	}
+	mapSrc.OptI64I64StringMapMapFoo[1][1] = "0"
+	if mapTgt.Equals(mapSrc) {
+		t.Fatal("MapEqualsFoo.Equals() test failed")
+	}
+}

Review comment:
       Yes, I missed `optional field`'s pointer check test.




----------------------------------------------------------------
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