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

Fixes #10 - Messages without packages #13

Merged
merged 1 commit into from
Jun 25, 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
8 changes: 5 additions & 3 deletions src/ExportMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@ export class ExportMap {
} : undefined,
};

const entryName = `${scope ? scope + "." : ""}${message.getName()}`;
const packagePrefix = scope ? scope + "." : "";

const entryName = `${packagePrefix}${message.getName()}`;
this.messageMap[entryName] = messageEntry;

message.getNestedTypeList().forEach(nested => {
this.exportNested(scope + "." + message.getName(), fileDescriptor, nested);
this.exportNested(`${packagePrefix}${message.getName()}`, fileDescriptor, nested);
});

message.getEnumTypeList().forEach(enumType => {
const identifier = scope + "." + message.getName() + "." + enumType.getName();
const identifier = `${packagePrefix}${message.getName()}.${enumType.getName()}`;
this.enumMap[identifier] = {
pkg: fileDescriptor.getPackage(),
fileName: fileDescriptor.getName(),
Expand Down
4 changes: 4 additions & 0 deletions test/proto/orphan.proto
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
syntax = "proto3";

message OrphanMapMessage {
map<string, int64> primitive_ints = 1;
}

message OrphanMessage {
string my_string = 1;
bool my_bool = 2;
Expand Down
25 changes: 25 additions & 0 deletions test/ts_test/src/maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {ExternalEnum} from "../generated/othercom/external_enum_pb";
import {ExternalChildMessage} from "../generated/othercom/external_child_message_pb";
import InternalEnum = MapMessage.InternalEnum;
import InternalChildMessage = MapMessage.InternalChildMessage;
import {OrphanMapMessage} from "../generated/orphan_pb";

describe("maps", () => {
describe("message maps", () => {
Expand Down Expand Up @@ -155,6 +156,30 @@ describe("maps", () => {
});
});

describe("orphan message maps", () => {
it("should allow setting and getting map fields of messages without a package", () => {
const parentMsg = new OrphanMapMessage();
const myMap = parentMsg.getPrimitiveIntsMap();
myMap.set("first", 123).set("second", 456);

assert.strictEqual(parentMsg.getPrimitiveIntsMap().getLength() as number, 2);
const firstKey = parentMsg.getPrimitiveIntsMap().keys().next().value;
assert.strictEqual(firstKey as string, "first");

const firstEntry = parentMsg.getPrimitiveIntsMap().entries().next().value;
assert.strictEqual(firstEntry[0] as string, "first");
assert.strictEqual(firstEntry[1] as number, 123);

assert.deepEqual(parentMsg.getPrimitiveIntsMap().toObject() as Array<[string, number]>, [
["first", 123],
["second", 456],
]);

assert.strictEqual(myMap.del("first") as boolean, true);
assert.strictEqual(myMap.getLength() as number, 1);
});
});

describe("toObject", () => {
it("should have types", () => {
const parentMsg = new MapMessage();
Expand Down