<NME> test_reflect_clear.rs
<BEF> use std::collections::HashMap;

use protobuf::{reflect::ReflectValueBox, MessageFull};

use super::test_reflect_clear_pb::*;

#[test]
fn test_generated() {
    let mut map = HashMap::new();
    map.insert("key".to_string(), "value".to_string());

    let mut msg = TestMessage::default();
    msg.set_a(1);
    msg.set_b("b".to_string());
    msg.set_c(test_message::Nested::default());
    msg.set_d(vec![1, 2, 3]);
    msg.set_e(map);

    let msg_desc = TestMessage::descriptor();

    let a_field = msg_desc.field_by_name("a").unwrap();
    let b_field = msg_desc.field_by_name("b").unwrap();
    let c_field = msg_desc.field_by_name("c").unwrap();
    let d_field = msg_desc.field_by_name("d").unwrap();
    let e_field = msg_desc.field_by_name("e").unwrap();

    a_field.clear_field(&mut msg);
    b_field.clear_field(&mut msg);
    c_field.clear_field(&mut msg);
    d_field.clear_field(&mut msg);
    e_field.clear_field(&mut msg);

    assert_eq!(TestMessage::default(), msg);
}

#[test]
fn test_dynamic() {
    let msg_desc = TestMessage::descriptor();
    let a_field = msg_desc.field_by_name("a").unwrap();
    let b_field = msg_desc.field_by_name("b").unwrap();
    let c_field = msg_desc.field_by_name("c").unwrap();
    let d_field = msg_desc.field_by_name("d").unwrap();
    let e_field = msg_desc.field_by_name("e").unwrap();

    let mut msg = msg_desc.new_instance();

    let mut map = HashMap::new();
    map.insert("key".to_string(), "value".to_string());

    a_field.set_singular_field(msg.as_mut(), 1.into());
    b_field.set_singular_field(msg.as_mut(), "b".to_string().into());
    c_field.set_singular_field(
        msg.as_mut(),
        ReflectValueBox::Message(Box::new(test_message::Nested::default())),
    );
    let mut d_repeated = d_field.mut_repeated(msg.as_mut());
    d_repeated.push(1.into());

    let mut e_map = e_field.mut_map(msg.as_mut());
    e_map.insert("key".to_string().into(), "value".to_string().into());

    a_field.clear_field(msg.as_mut());
    b_field.clear_field(msg.as_mut());
    c_field.clear_field(msg.as_mut());
    d_field.clear_field(msg.as_mut());
    e_field.clear_field(msg.as_mut());

    let msg_empty = msg_desc.new_instance();
    assert_eq!(msg.to_string(), msg_empty.to_string());
}

<MSG> cargo fmt

<DFF> @@ -1,6 +1,7 @@
 use std::collections::HashMap;
 
-use protobuf::{reflect::ReflectValueBox, MessageFull};
+use protobuf::reflect::ReflectValueBox;
+use protobuf::MessageFull;
 
 use super::test_reflect_clear_pb::*;
 

{'commit': 'diff --git a/protobuf/src/reflect/field/mod.rs b/protobuf/src/reflect/field/mod.rs\nindex 190833dd..3da38cad 100644\n--- a/protobuf/src/reflect/field/mod.rs\n+++ b/protobuf/src/reflect/field/mod.rs\n@@ -567,7 +567,8 @@ mod test {\n \n     use crate::descriptor::DescriptorProto;\n     use crate::reflect::ReflectValueBox;\n-    use crate::well_known_types::struct_::{Struct, Value};\n+    use crate::well_known_types::struct_::Struct;\n+    use crate::well_known_types::struct_::Value;\n     use crate::MessageFull;\n \n     #[test]\ndiff --git a/test-crates/protobuf-codegen-protoc-test/src/common/v2/test_reflect_clear.rs b/test-crates/protobuf-codegen-protoc-test/src/common/v2/test_reflect_clear.rs\nindex 1b4239ac..2e0affaf 100644\n--- a/test-crates/protobuf-codegen-protoc-test/src/common/v2/test_reflect_clear.rs\n+++ b/test-crates/protobuf-codegen-protoc-test/src/common/v2/test_reflect_clear.rs\n@@ -1,6 +1,7 @@\n use std::collections::HashMap;\n \n-use protobuf::{reflect::ReflectValueBox, MessageFull};\n+use protobuf::reflect::ReflectValueBox;\n+use protobuf::MessageFull;\n \n use super::test_reflect_clear_pb::*;\n \n', 'commit_subject': 'cargo fmt', 'repo_name': 'stepancheg/rust-protobuf', 'committer': {'name': 'Stiopa Koltsov', 'email': 'e150b500682c3c55bd53434656d52cd8d6051776@gmail.com', 'time_sec': '1664153833', 'tz_offset': '60', 'date': {'seconds': '1664153833'}}, 'commit_tree': '951a1663b14cff4d9e6e840e31f6f8db43d00c20', 'commit_message': 'cargo fmt\n', 'language_name': 'Rust', 'license': 'mit', 'hunks': '@@ -1,6 +1,7 @@\n use std::collections::HashMap;\n \n-use protobuf::{reflect::ReflectValueBox, MessageFull};\n+use protobuf::reflect::ReflectValueBox;\n+use protobuf::MessageFull;\n \n use super::test_reflect_clear_pb::*;\n \n', 'addition_count': 2, 'deletion_count': 1, 'src_file': 'a/test-crates/protobuf-codegen-protoc-test/src/common/v2/test_reflect_clear.rs', 'tgt_file': 'b/test-crates/protobuf-codegen-protoc-test/src/common/v2/test_reflect_clear.rs', 'file_extension': '.rs', 'before_file': 'use std::collections::HashMap;\n\nuse protobuf::{reflect::ReflectValueBox, MessageFull};\n\nuse super::test_reflect_clear_pb::*;\n\n#[test]\nfn test_generated() {\n    let mut map = HashMap::new();\n    map.insert("key".to_string(), "value".to_string());\n\n    let mut msg = TestMessage::default();\n    msg.set_a(1);\n    msg.set_b("b".to_string());\n    msg.set_c(test_message::Nested::default());\n    msg.set_d(vec![1, 2, 3]);\n    msg.set_e(map);\n\n    let msg_desc = TestMessage::descriptor();\n\n    let a_field = msg_desc.field_by_name("a").unwrap();\n    let b_field = msg_desc.field_by_name("b").unwrap();\n    let c_field = msg_desc.field_by_name("c").unwrap();\n    let d_field = msg_desc.field_by_name("d").unwrap();\n    let e_field = msg_desc.field_by_name("e").unwrap();\n\n    a_field.clear_field(&mut msg);\n    b_field.clear_field(&mut msg);\n    c_field.clear_field(&mut msg);\n    d_field.clear_field(&mut msg);\n    e_field.clear_field(&mut msg);\n\n    assert_eq!(TestMessage::default(), msg);\n}\n\n#[test]\nfn test_dynamic() {\n    let msg_desc = TestMessage::descriptor();\n    let a_field = msg_desc.field_by_name("a").unwrap();\n    let b_field = msg_desc.field_by_name("b").unwrap();\n    let c_field = msg_desc.field_by_name("c").unwrap();\n    let d_field = msg_desc.field_by_name("d").unwrap();\n    let e_field = msg_desc.field_by_name("e").unwrap();\n\n    let mut msg = msg_desc.new_instance();\n\n    let mut map = HashMap::new();\n    map.insert("key".to_string(), "value".to_string());\n\n    a_field.set_singular_field(msg.as_mut(), 1.into());\n    b_field.set_singular_field(msg.as_mut(), "b".to_string().into());\n    c_field.set_singular_field(\n        msg.as_mut(),\n        ReflectValueBox::Message(Box::new(test_message::Nested::default())),\n    );\n    let mut d_repeated = d_field.mut_repeated(msg.as_mut());\n    d_repeated.push(1.into());\n\n    let mut e_map = e_field.mut_map(msg.as_mut());\n    e_map.insert("key".to_string().into(), "value".to_string().into());\n\n    a_field.clear_field(msg.as_mut());\n    b_field.clear_field(msg.as_mut());\n    c_field.clear_field(msg.as_mut());\n    d_field.clear_field(msg.as_mut());\n    e_field.clear_field(msg.as_mut());\n\n    let msg_empty = msg_desc.new_instance();\n    assert_eq!(msg.to_string(), msg_empty.to_string());\n}\n', 'message': 'cargo fmt\n', 'author_name': 'Stiopa Koltsov', 'lang': 'rs'}