Permalink
Browse files

allow_alias enum option was not being honored. This case is now handl…

…ed and a test case was added
  • Loading branch information...
sschwiet
sschwiet committed Feb 13, 2017
1 parent 2ddb76b commit d65c22936183d04014d6a8eb880ae0ec33aeba6d
Showing with 12 additions and 3 deletions.
  1. +1 −1 src/enum.js
  2. +11 −2 tests/api_enum.js
@@ -91,7 +91,7 @@ Enum.prototype.add = function(name, id, comment) {
if (this.values[name] !== undefined)
throw Error("duplicate name");
if (this.valuesById[id] !== undefined)
if (this.valuesById[id] !== undefined && !(this.options && this.options.allow_alias))
throw Error("duplicate id");
this.valuesById[this.values[name] = id] = name;
@@ -9,6 +9,9 @@ tape.test("reflected enums", function(test) {
b: 2
});
var enm_allow_alias = new protobuf.Enum( 'AliasTest',
{ a: 0 }, { allow_alias: true } );
test.throws(function() {
new protobuf.Enum("Test", true);
}, TypeError, "should throw if values is specified but not an object");
@@ -32,7 +35,7 @@ tape.test("reflected enums", function(test) {
test.throws(function() {
enm.add("c", 2);
}, Error, "should throw if id is a duplicate");
}, Error, "should throw if id is a duplicate, without allow_alias option");
enm.add("c", 3);
test.same(enm.values, {
@@ -72,5 +75,11 @@ tape.test("reflected enums", function(test) {
}
}, "should export options and values to JSON");
enm_allow_alias.add( 'b', 0 );
test.same( enm_allow_alias.values, {
a: 0,
b: 0
});
test.end();
});
});

0 comments on commit d65c229

Please sign in to comment.