aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc
diff options
context:
space:
mode:
authorGravatar Jon Skeet <jonskeet@google.com>2016-04-08 12:19:10 +0100
committerGravatar Jon Skeet <jonskeet@google.com>2016-04-20 03:45:59 +0100
commit75626ed79c726ed9fd96d9d143ce6b6c88413bf8 (patch)
treea64be68c42ea3abdd589df459fbf685724bfd82c /src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc
parent2a197b3eb0d74ac1f1d461ac958ebccaf968031c (diff)
Add C# codegen changes to enum value names (mostly C++)
Overview of changes: - A new C#-specific command-line option, legacy_enum_values to revert to the old behavior - When legacy_enum_values isn't specified, we strip the enum name as a prefix, and PascalCase the value name - A new attribute within the C# code so that we can always tell the original in-proto name Regenerating the C# code with legacy_enum_values leads to code which still compiles and works - but there's more still to do.
Diffstat (limited to 'src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc')
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc b/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc
index 7ef7df42..5755fee0 100644
--- a/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc
+++ b/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc
@@ -30,8 +30,8 @@
#include <memory>
-#include <google/protobuf/compiler/ruby/ruby_generator.h>
#include <google/protobuf/compiler/command_line_interface.h>
+#include <google/protobuf/compiler/csharp/csharp_helpers.h>
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/io/printer.h>
@@ -45,7 +45,23 @@ namespace compiler {
namespace csharp {
namespace {
-// TODO(jtattermusch): add some tests.
+TEST(CSharpEnumValue, PascalCasedPrefixStripping) {
+ EXPECT_EQ("Bar", GetEnumValueName("Foo", "BAR"));
+ EXPECT_EQ("BarBaz", GetEnumValueName("Foo", "BAR_BAZ"));
+ EXPECT_EQ("Bar", GetEnumValueName("Foo", "FOO_BAR"));
+ EXPECT_EQ("Bar", GetEnumValueName("Foo", "FOO__BAR"));
+ EXPECT_EQ("BarBaz", GetEnumValueName("Foo", "FOO_BAR_BAZ"));
+ EXPECT_EQ("BarBaz", GetEnumValueName("Foo", "Foo_BarBaz"));
+ EXPECT_EQ("Bar", GetEnumValueName("FO_O", "FOO_BAR"));
+ EXPECT_EQ("Bar", GetEnumValueName("FOO", "F_O_O_BAR"));
+ EXPECT_EQ("Bar", GetEnumValueName("Foo", "BAR"));
+ EXPECT_EQ("BarBaz", GetEnumValueName("Foo", "BAR_BAZ"));
+ EXPECT_EQ("Foo", GetEnumValueName("Foo", "FOO"));
+ EXPECT_EQ("Foo", GetEnumValueName("Foo", "FOO___"));
+ // Identifiers can't start with digits
+ EXPECT_EQ("_2Bar", GetEnumValueName("Foo", "FOO_2_BAR"));
+ EXPECT_EQ("_2", GetEnumValueName("Foo", "FOO___2"));
+}
} // namespace
} // namespace csharp