Commit e259b515 authored by Bo Yang's avatar Bo Yang

Fix generated code when there is no namespace but there is enum definition.

parent 83fb8c7d
<?php <?php
require_once('generated/NoNameSpace.php'); require_once('generated/NoNameSpaceEnum.php');
require_once('generated/NoNameSpaceMessage.php');
require_once('test_util.php'); require_once('test_util.php');
use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\RepeatedField;
...@@ -601,10 +602,14 @@ class GeneratedClassTest extends PHPUnit_Framework_TestCase ...@@ -601,10 +602,14 @@ class GeneratedClassTest extends PHPUnit_Framework_TestCase
} }
######################################################### #########################################################
# Test oneof field. # Test message/enum without namespace.
######################################################### #########################################################
public function testMessageWithoutNamespace() { public function testMessageWithoutNamespace() {
$m = new NoNameSpace(); $m = new NoNameSpaceMessage();
}
public function testEnumWithoutNamespace() {
$m = new NoNameSpaceEnum();
} }
} }
syntax = "proto3"; syntax = "proto3";
message NoNameSpace { message NoNameSpaceMessage {
int32 a = 1; int32 a = 1;
} }
enum NoNameSpaceEnum {
VALUE_A = 0;
VALUE_B = 1;
}
...@@ -757,12 +757,15 @@ void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en, ...@@ -757,12 +757,15 @@ void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en,
std::string fullname = FilenameToClassname(filename); std::string fullname = FilenameToClassname(filename);
int lastindex = fullname.find_last_of("\\"); int lastindex = fullname.find_last_of("\\");
GenerateEnumDocComment(&printer, en); if (!file->package().empty()) {
if (lastindex != string::npos) {
printer.Print( printer.Print(
"namespace ^name^;\n\n", "namespace ^name^;\n\n",
"name", fullname.substr(0, lastindex)); "name", fullname.substr(0, lastindex));
}
GenerateEnumDocComment(&printer, en);
if (lastindex != string::npos) {
printer.Print( printer.Print(
"class ^name^\n" "class ^name^\n"
"{\n", "{\n",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment