Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export Enum Definitions as ALL_CAPS #22

Merged
merged 1 commit into from
Aug 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ts/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function printEnum(enumDescriptor: EnumDescriptorProto, indentLevel: numb
printer.printEmptyLn();
printer.printLn(`export enum ${enumDescriptor.getName()} {`);
enumDescriptor.getValueList().forEach(value => {
printer.printIndentedLn(`${value.getName()} = ${value.getNumber()},`);
printer.printIndentedLn(`${value.getName().toUpperCase()} = ${value.getNumber()},`);
});
printer.printLn(`}`);
return printer.getOutput();
Expand Down
1 change: 1 addition & 0 deletions test/proto/examplecom/enum_message.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ message EnumMessage {
DEFAULT = 0;
FIRST = 1;
SECOND = 2;
Third = 3; // protoc will convert to ALL_CAPS.
}

InternalEnum internal_enum = 1;
Expand Down
8 changes: 8 additions & 0 deletions test/ts_test/src/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,11 @@ describe("external enums", () => {
assert.deepEqual(parentMsg.getExternalEnumsList(), [ExternalEnum.FIRST, ExternalEnum.SECOND]);
});
});

describe("enum casing", () => {
it("should export enums as ALL_CAPS in proto definitions (#21)", () => {
const parentMsg = new EnumMessage();
parentMsg.setInternalEnum(InternalEnum.THIRD); // should compile.
assert.ok(true, ".d.ts file should export the enum definition in ALL_CAPS");
});
});