internal/impl: verify lazy unmarshal on Deterministic encoding
I noticed we did not have an explicit test for this entry point.
Change-Id: Ifdcd2454cd6ace2a039bdbabf8411e1f57644683
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/703276
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Florian Zenker <floriank@google.com>
diff --git a/internal/impl/lazy_test.go b/internal/impl/lazy_test.go
index e0a91cc..a20ec18 100644
--- a/internal/impl/lazy_test.go
+++ b/internal/impl/lazy_test.go
@@ -198,6 +198,30 @@
}
}
+func TestExtensionLazyDeterministic(t *testing.T) {
+ if !flags.LazyUnmarshalExtensions {
+ t.Skip("lazy extension unmarshaling disabled; not built with the protolegacy tag")
+ }
+
+ tree := proto.Clone(treeTemplate)
+ proto.SetExtension(tree, lazytestpb.E_Bat, &lazytestpb.FlyingFox{Species: &spGH})
+ proto.SetExtension(tree, lazytestpb.E_BatPup, &lazytestpb.FlyingFox{Species: &spP})
+
+ nt := roundtrip(t, tree).(*lazytestpb.Tree)
+
+ if extensionIsInitialized(t, nt, lazytestpb.E_Bat) {
+ t.Errorf("Extension unexpectedly initialized after Unmarshal")
+ }
+ proto.Size(nt)
+ if extensionIsInitialized(t, nt, lazytestpb.E_Bat) {
+ t.Errorf("Extension unexpectedly initialized after Size")
+ }
+ proto.MarshalOptions{Deterministic: true}.Size(nt)
+ if !extensionIsInitialized(t, nt, lazytestpb.E_Bat) {
+ t.Errorf("Extension unexpectedly not initialized after deterministic Size")
+ }
+}
+
func TestExtensionNestedScopeLazy(t *testing.T) {
if !flags.LazyUnmarshalExtensions {
t.Skip("lazy extension unmarshaling disabled; not built with the protolegacy tag")