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
require_once('generated/NoNameSpace.php');
require_once('generated/NoNameSpaceEnum.php');
require_once('generated/NoNameSpaceMessage.php');
require_once('test_util.php');
use Google\Protobuf\Internal\RepeatedField;
......@@ -601,10 +602,14 @@ class GeneratedClassTest extends PHPUnit_Framework_TestCase
}
#########################################################
# Test oneof field.
# Test message/enum without namespace.
#########################################################
public function testMessageWithoutNamespace() {
$m = new NoNameSpace();
$m = new NoNameSpaceMessage();
}
public function testEnumWithoutNamespace() {
$m = new NoNameSpaceEnum();
}
}
syntax = "proto3";
message NoNameSpace {
message NoNameSpaceMessage {
int32 a = 1;
}
enum NoNameSpaceEnum {
VALUE_A = 0;
VALUE_B = 1;
}
......@@ -757,12 +757,15 @@ void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en,
std::string fullname = FilenameToClassname(filename);
int lastindex = fullname.find_last_of("\\");
GenerateEnumDocComment(&printer, en);
if (lastindex != string::npos) {
if (!file->package().empty()) {
printer.Print(
"namespace ^name^;\n\n",
"name", fullname.substr(0, lastindex));
}
GenerateEnumDocComment(&printer, en);
if (lastindex != string::npos) {
printer.Print(
"class ^name^\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