Merge pull request #5492 from haon4/master

Add conformance test for allow_alias with lower_case enums
pull/5500/head
Hao Nguyen 6 years ago committed by GitHub
commit 043b99c74a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      conformance/binary_json_conformance_suite.cc
  2. 1
      conformance/conformance_php.php
  3. 3
      ruby/ext/google/protobuf_c/message.c
  4. 12
      src/google/protobuf/test_messages_proto3.proto

@ -1386,6 +1386,23 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() {
"EnumField", REQUIRED, "EnumField", REQUIRED,
R"({"optionalNestedEnum": "FOO"})", R"({"optionalNestedEnum": "FOO"})",
"optional_nested_enum: FOO"); "optional_nested_enum: FOO");
// Enum fields with alias
RunValidJsonTest(
"EnumFieldWithAlias", REQUIRED,
R"({"optionalAliasedEnum": "ALIAS_BAZ"})",
"optional_aliased_enum: ALIAS_BAZ");
RunValidJsonTest(
"EnumFieldWithAliasUseAlias", REQUIRED,
R"({"optionalAliasedEnum": "QUX"})",
"optional_aliased_enum: ALIAS_BAZ");
RunValidJsonTest(
"EnumFieldWithAliasLowerCase", REQUIRED,
R"({"optionalAliasedEnum": "qux"})",
"optional_aliased_enum: ALIAS_BAZ");
RunValidJsonTest(
"EnumFieldWithAliasDifferentCase", REQUIRED,
R"({"optionalAliasedEnum": "bAz"})",
"optional_aliased_enum: ALIAS_BAZ");
// Enum values must be represented as strings. // Enum values must be represented as strings.
ExpectParseFailureForJson( ExpectParseFailureForJson(
"EnumFieldNotQuoted", REQUIRED, "EnumFieldNotQuoted", REQUIRED,

@ -8,6 +8,7 @@ require_once("Conformance/TestCategory.php");
require_once("Protobuf_test_messages/Proto3/ForeignMessage.php"); require_once("Protobuf_test_messages/Proto3/ForeignMessage.php");
require_once("Protobuf_test_messages/Proto3/ForeignEnum.php"); require_once("Protobuf_test_messages/Proto3/ForeignEnum.php");
require_once("Protobuf_test_messages/Proto3/TestAllTypesProto3.php"); require_once("Protobuf_test_messages/Proto3/TestAllTypesProto3.php");
require_once("Protobuf_test_messages/Proto3/TestAllTypesProto3/AliasedEnum.php");
require_once("Protobuf_test_messages/Proto3/TestAllTypesProto3/NestedMessage.php"); require_once("Protobuf_test_messages/Proto3/TestAllTypesProto3/NestedMessage.php");
require_once("Protobuf_test_messages/Proto3/TestAllTypesProto3/NestedEnum.php"); require_once("Protobuf_test_messages/Proto3/TestAllTypesProto3/NestedEnum.php");

@ -698,8 +698,7 @@ VALUE build_module_from_enumdesc(EnumDescriptor* enumdesc) {
const char* name = upb_enum_iter_name(&it); const char* name = upb_enum_iter_name(&it);
int32_t value = upb_enum_iter_number(&it); int32_t value = upb_enum_iter_number(&it);
if (name[0] < 'A' || name[0] > 'Z') { if (name[0] < 'A' || name[0] > 'Z') {
rb_raise(cTypeError, rb_warn("Enum value '%s' does not start with an uppercase letter "
"Enum value '%s' does not start with an uppercase letter "
"as is required for Ruby constants.", "as is required for Ruby constants.",
name); name);
} }

@ -73,6 +73,17 @@ message TestAllTypesProto3 {
NEG = -1; // Intentionally negative. NEG = -1; // Intentionally negative.
} }
enum AliasedEnum {
option allow_alias = true;
ALIAS_FOO = 0;
ALIAS_BAR = 1;
ALIAS_BAZ = 2;
QUX = 2;
qux = 2;
bAz = 2;
}
// Singular // Singular
int32 optional_int32 = 1; int32 optional_int32 = 1;
int64 optional_int64 = 2; int64 optional_int64 = 2;
@ -95,6 +106,7 @@ message TestAllTypesProto3 {
NestedEnum optional_nested_enum = 21; NestedEnum optional_nested_enum = 21;
ForeignEnum optional_foreign_enum = 22; ForeignEnum optional_foreign_enum = 22;
AliasedEnum optional_aliased_enum = 23;
string optional_string_piece = 24 [ctype=STRING_PIECE]; string optional_string_piece = 24 [ctype=STRING_PIECE];
string optional_cord = 25 [ctype=CORD]; string optional_cord = 25 [ctype=CORD];

Loading…
Cancel
Save