Before this change if a field type was defined in a imported .proto file then our codegen would not generate the field. After this change such fields are correctly generated (see tests). This change is rather trivial as all the supporting infra has been implemented as part of the .proto -> crate mapping CLs. PiperOrigin-RevId: 601443383pull/15450/head
parent
5f51020f5d
commit
90015d3145
10 changed files with 221 additions and 36 deletions
@ -0,0 +1,22 @@ |
||||
// Protocol Buffers - Google's data interchange format |
||||
// Copyright 2024 Google LLC. All rights reserved. |
||||
// |
||||
// Use of this source code is governed by a BSD-style |
||||
// license that can be found in the LICENSE file or at |
||||
// https://developers.google.com/open-source/licenses/bsd |
||||
|
||||
syntax = "proto2"; |
||||
|
||||
package main; |
||||
|
||||
import "google/protobuf/rust/test/imported_types.proto"; |
||||
|
||||
message MsgWithFieldsWithImportedTypes { |
||||
optional imported_types.ImportedMessage imported_message_field = 1; |
||||
optional imported_types.ImportedEnum imported_enum_field = 2; |
||||
|
||||
oneof imported_types_oneof { |
||||
imported_types.ImportedMessage imported_message_oneof = 3; |
||||
imported_types.ImportedEnum imported_enum_oneof = 4; |
||||
} |
||||
} |
@ -0,0 +1,19 @@ |
||||
// Protocol Buffers - Google's data interchange format |
||||
// Copyright 2024 Google LLC. All rights reserved. |
||||
// |
||||
// Use of this source code is governed by a BSD-style |
||||
// license that can be found in the LICENSE file or at |
||||
// https://developers.google.com/open-source/licenses/bsd |
||||
|
||||
syntax = "proto2"; |
||||
|
||||
package imported_types; |
||||
|
||||
message ImportedMessage { |
||||
optional int32 num = 1; |
||||
} |
||||
|
||||
enum ImportedEnum { |
||||
IMPORTED_ENUM_UNKNOWN = 0; |
||||
IMPORTED_ENUM_BAR = 1; |
||||
} |
@ -0,0 +1,42 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2024 Google LLC. All rights reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://developers.google.com/open-source/licenses/bsd
|
||||
|
||||
/// Tests covering that fields with types that are defined in imported .proto
|
||||
/// files are generated. In particular where the imported .proto file is part of
|
||||
/// a separate proto_library target.
|
||||
use googletest::prelude::*; |
||||
|
||||
#[test] |
||||
fn test_message_field_generated() { |
||||
use fields_with_imported_types_proto::MsgWithFieldsWithImportedTypes; |
||||
use imported_types_proto::ImportedMessageView; |
||||
|
||||
let msg = MsgWithFieldsWithImportedTypes::new(); |
||||
assert_that!(msg.imported_message_field(), matches_pattern!(ImportedMessageView { .. })); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_enum_field_generated() { |
||||
use fields_with_imported_types_proto::MsgWithFieldsWithImportedTypes; |
||||
use imported_types_proto::ImportedEnum; |
||||
|
||||
let msg = MsgWithFieldsWithImportedTypes::new(); |
||||
assert_that!(msg.imported_enum_field(), eq(ImportedEnum::Unknown)); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_oneof_message_field_generated() { |
||||
use fields_with_imported_types_proto::MsgWithFieldsWithImportedTypes; |
||||
use fields_with_imported_types_proto::MsgWithFieldsWithImportedTypes_::ImportedTypesOneof::not_set; |
||||
use imported_types_proto::ImportedEnum; |
||||
use imported_types_proto::ImportedMessageView; |
||||
|
||||
let msg = MsgWithFieldsWithImportedTypes::new(); |
||||
assert_that!(msg.imported_message_oneof(), matches_pattern!(ImportedMessageView { .. })); |
||||
assert_that!(msg.imported_enum_oneof(), eq(ImportedEnum::Unknown)); |
||||
assert_that!(msg.imported_types_oneof(), matches_pattern!(not_set(_))); |
||||
} |
@ -0,0 +1,27 @@ |
||||
proto3_implicit_proto |
||||
1 |
||||
third_party/protobuf/editions/codegen_tests/proto3_implicit.proto |
||||
proto2_optional_proto |
||||
1 |
||||
third_party/protobuf/editions/codegen_tests/proto2_optional.proto |
||||
proto3_enum_proto |
||||
1 |
||||
third_party/protobuf/editions/codegen_tests/proto3_enum.proto |
||||
struct |
||||
1 |
||||
google/protobuf/struct.proto |
||||
wrappers |
||||
1 |
||||
google/protobuf/wrappers.proto |
||||
duration |
||||
1 |
||||
google/protobuf/duration.proto |
||||
timestamp |
||||
1 |
||||
google/protobuf/timestamp.proto |
||||
field_mask |
||||
1 |
||||
google/protobuf/field_mask.proto |
||||
any |
||||
1 |
||||
google/protobuf/any.proto |
Loading…
Reference in new issue