Skip to content

Commit

Permalink
Add test for map field reflection
Browse files Browse the repository at this point in the history
  • Loading branch information
stepancheg committed Jun 26, 2024
1 parent fd39b62 commit c0ebed2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use protobuf::reflect::ReflectValueBox;
use protobuf::MessageFull;

use super::test_reflect_map_pb::TestMap;

#[test]
fn test_map() {
let mut message = TestMap::new();
message
.map_string_string
.insert("foo".to_owned(), "bar".to_owned());
message.map_int32_bool.insert(1, true);

let map_string_string = TestMap::descriptor()
.field_by_name("map_string_string")
.unwrap();
let map_int32_bool = TestMap::descriptor()
.field_by_name("map_int32_bool")
.unwrap();

let mut reflect_message = TestMap::descriptor().new_instance();
map_string_string.mut_map(&mut *reflect_message).insert(
ReflectValueBox::String("foo".to_owned()),
ReflectValueBox::String("bar".to_owned()),
);
map_int32_bool
.mut_map(&mut *reflect_message)
.insert(ReflectValueBox::I32(1), ReflectValueBox::Bool(true));

assert!(TestMap::descriptor().eq(&message, &*reflect_message));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
syntax = "proto2";

import "rustproto.proto";
option (rustproto.generate_accessors_all) = true;

message TestMap {
map<string, string> map_string_string = 1;
map<int32, bool> map_int32_bool = 2;
}

0 comments on commit c0ebed2

Please sign in to comment.