Add V0 support for signed ints

PiperOrigin-RevId: 547200059
pull/13267/head
Hong Shin 2 years ago committed by Copybara-Service
parent 6c4ab101ce
commit fcab1a4371
  1. 34
      rust/test/shared/accessors_test.rs
  2. 2
      src/google/protobuf/compiler/rust/accessors/accessors.cc
  3. 6
      src/google/protobuf/compiler/rust/naming.cc

@ -33,11 +33,11 @@ use unittest_proto::proto2_unittest::TestAllTypes;
#[test]
fn test_default_accessors() {
// defaults are from here:
// http://google3/third_party/protobuf/unittest.proto section default_*
let msg = TestAllTypes::new();
assert_eq!(msg.default_int32(), 41);
assert_eq!(msg.default_int64(), 42);
assert_eq!(msg.default_sint32(), -45);
assert_eq!(msg.default_sint64(), 46);
assert_eq!(msg.default_uint32(), 43);
assert_eq!(msg.default_uint64(), 44);
assert_eq!(msg.default_bool(), true);
@ -74,6 +74,36 @@ fn test_optional_int64_accessors() {
assert_eq!(msg.optional_int64(), 0);
}
#[test]
fn test_optional_sint32_accessors() {
let mut msg = TestAllTypes::new();
assert_eq!(msg.optional_sint32_opt(), None);
assert_eq!(msg.optional_sint32(), 0);
msg.optional_sint32_set(Some(-22));
assert_eq!(msg.optional_sint32_opt(), Some(-22));
assert_eq!(msg.optional_sint32(), -22);
msg.optional_sint32_set(None);
assert_eq!(msg.optional_sint32_opt(), None);
assert_eq!(msg.optional_sint32(), 0);
}
#[test]
fn test_optional_sint64_accessors() {
let mut msg = TestAllTypes::new();
assert_eq!(msg.optional_sint64_opt(), None);
assert_eq!(msg.optional_sint64(), 0);
msg.optional_sint64_set(Some(7000));
assert_eq!(msg.optional_sint64_opt(), Some(7000));
assert_eq!(msg.optional_sint64(), 7000);
msg.optional_sint64_set(None);
assert_eq!(msg.optional_sint64_opt(), None);
assert_eq!(msg.optional_sint64(), 0);
}
#[test]
fn test_optional_uint32_accessors() {
let mut msg = TestAllTypes::new();

@ -51,6 +51,8 @@ std::unique_ptr<AccessorGenerator> AccessorGenerator::For(
switch (field.desc().type()) {
case FieldDescriptor::TYPE_INT32:
case FieldDescriptor::TYPE_INT64:
case FieldDescriptor::TYPE_SINT32:
case FieldDescriptor::TYPE_SINT64:
case FieldDescriptor::TYPE_UINT32:
case FieldDescriptor::TYPE_UINT64:
case FieldDescriptor::TYPE_BOOL:

@ -114,6 +114,10 @@ absl::string_view PrimitiveRsTypeName(Context<FieldDescriptor> field) {
return "i32";
case FieldDescriptor::TYPE_INT64:
return "i64";
case FieldDescriptor::TYPE_SINT32:
return "i32";
case FieldDescriptor::TYPE_SINT64:
return "i64";
case FieldDescriptor::TYPE_UINT32:
return "u32";
case FieldDescriptor::TYPE_UINT64:
@ -135,6 +139,8 @@ bool IsSupportedFieldType(Context<FieldDescriptor> field) {
(field.desc().type() == FieldDescriptor::TYPE_BOOL ||
field.desc().type() == FieldDescriptor::TYPE_INT32 ||
field.desc().type() == FieldDescriptor::TYPE_INT64 ||
field.desc().type() == FieldDescriptor::TYPE_SINT32 ||
field.desc().type() == FieldDescriptor::TYPE_SINT64 ||
field.desc().type() == FieldDescriptor::TYPE_UINT32 ||
field.desc().type() == FieldDescriptor::TYPE_UINT64 ||
field.desc().type() == FieldDescriptor::TYPE_BYTES);

Loading…
Cancel
Save