<NME> test_reflect_issue_564_pb.proto
<BEF> ADDFILE
<MSG> Fix field enum reflective access

(The fix is in v2 branch, this commit only merges the test, no fix
needed.)

Issue #564

<DFF> @@ -0,0 +1,16 @@
+syntax = "proto2";
+
+import "rustproto.proto";
+option (rustproto.generate_accessors_all) = true;
+
+message Issue564 {
+  enum TestEnum {
+    TEST_ENUM_VALUE_A = 0;
+    TEST_ENUM_VALUE_B = 1;
+  }
+
+  message TestMessage {}
+
+  optional TestEnum ee = 1;
+  optional TestMessage mm = 2;
+}

{'commit': 'diff --git a/protobuf-test/src/common/v2/test_reflect_issue_564.rs b/protobuf-test/src/common/v2/test_reflect_issue_564.rs\nnew file mode 100644\nindex 00000000..1c28cf8b\n--- /dev/null\n+++ b/protobuf-test/src/common/v2/test_reflect_issue_564.rs\n@@ -0,0 +1,48 @@\n+use super::test_reflect_issue_564_pb::*;\n+\n+use protobuf::descriptor::field_descriptor_proto;\n+use protobuf::reflect::ReflectValueRef;\n+use protobuf::MessageDyn;\n+\n+fn visit_fields(mes: &dyn MessageDyn) {\n+    let mut seen_enum = false;\n+    let mut seen_message = false;\n+\n+    let descriptor = mes.descriptor_dyn();\n+    for field in descriptor.fields() {\n+        if field.has_field(mes) {\n+            match field.get_proto().get_field_type() {\n+                field_descriptor_proto::Type::TYPE_ENUM => {\n+                    match field.get_singular(mes) {\n+                        Some(ReflectValueRef::Enum(e, value)) => {\n+                            assert_eq!(\n+                                "TEST_ENUM_VALUE_B",\n+                                e.get_value_by_number(value).unwrap().get_name()\n+                            );\n+                            assert!(!seen_enum);\n+                            seen_enum = true;\n+                        }\n+                        Some(..) => panic!("not an enum"),\n+                        None => panic!("must be set"),\n+                    };\n+                }\n+                field_descriptor_proto::Type::TYPE_MESSAGE => {\n+                    let _ = field.get_message(mes);\n+                    assert!(!seen_message);\n+                    seen_message = true;\n+                }\n+                _ => {}\n+            }\n+        }\n+    }\n+    assert!(seen_enum);\n+    assert!(seen_message);\n+}\n+\n+#[test]\n+fn test() {\n+    let mut mes = Issue564::default();\n+    mes.set_ee(issue564::TestEnum::TEST_ENUM_VALUE_B);\n+    mes.set_mm(Default::default());\n+    visit_fields(&mes);\n+}\ndiff --git a/protobuf-test/src/common/v2/test_reflect_issue_564_pb.proto b/protobuf-test/src/common/v2/test_reflect_issue_564_pb.proto\nnew file mode 100644\nindex 00000000..c611f5fa\n--- /dev/null\n+++ b/protobuf-test/src/common/v2/test_reflect_issue_564_pb.proto\n@@ -0,0 +1,16 @@\n+syntax = "proto2";\n+\n+import "rustproto.proto";\n+option (rustproto.generate_accessors_all) = true;\n+\n+message Issue564 {\n+  enum TestEnum {\n+    TEST_ENUM_VALUE_A = 0;\n+    TEST_ENUM_VALUE_B = 1;\n+  }\n+\n+  message TestMessage {}\n+\n+  optional TestEnum ee = 1;\n+  optional TestMessage mm = 2;\n+}\n', 'commit_subject': 'Fix field enum reflective access', 'repo_name': 'stepancheg/rust-protobuf', 'committer': {'name': 'Stiopa Koltsov', 'email': 'e150b500682c3c55bd53434656d52cd8d6051776@gmail.com', 'time_sec': '1628447914', 'tz_offset': '60', 'date': {'seconds': '1628447914'}}, 'commit_tree': 'cda6e52a4ba0818c39583491d40daaf59c8ff23f', 'commit_message': 'Fix field enum reflective access\n\n(The fix is in v2 branch, this commit only merges the test, no fix\nneeded.)\n\nIssue #564\n', 'language_name': 'Rust', 'license': 'mit', 'hunks': '@@ -0,0 +1,16 @@\n+syntax = "proto2";\n+\n+import "rustproto.proto";\n+option (rustproto.generate_accessors_all) = true;\n+\n+message Issue564 {\n+  enum TestEnum {\n+    TEST_ENUM_VALUE_A = 0;\n+    TEST_ENUM_VALUE_B = 1;\n+  }\n+\n+  message TestMessage {}\n+\n+  optional TestEnum ee = 1;\n+  optional TestMessage mm = 2;\n+}\n', 'addition_count': 16, 'deletion_count': 0, 'src_file': '/dev/null', 'tgt_file': 'b/protobuf-test/src/common/v2/test_reflect_issue_564_pb.proto', 'file_extension': '.proto', 'before_file': 'ADDFILE', 'message': 'Fix field enum reflective access\n\n(The fix is in v2 branch, this commit only merges the test, no fix\nneeded.)\n\nIssue #564\n', 'author_name': 'Stiopa Koltsov', 'lang': 'proto'}