Fix generated code when there is no namespace but there is enum definition.
This commit is contained in:
parent
83fb8c7d29
commit
e259b515a5
3 changed files with 19 additions and 6 deletions
|
@ -1,6 +1,7 @@
|
|||
<?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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
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",
|
||||
|
|
Loading…
Add table
Reference in a new issue