-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle oneofs in prototype ctor, add non-ES5 fallbacks, test case
- Loading branch information
Showing
10 changed files
with
76 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
syntax = "proto3"; | ||
|
||
message Message { | ||
oneof kind { | ||
string str = 1; | ||
int32 num = 2; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
var tape = require("tape"); | ||
|
||
var protobuf = require(".."); | ||
|
||
tape.test("oneofs", function(test) { | ||
|
||
protobuf.load("tests/data/oneof.proto", function(err, root) { | ||
if (err) | ||
return test.fail(err.message); | ||
|
||
var Message = root.lookup("Message"); | ||
var message = Message.create({ | ||
str: "a", | ||
num: 1 | ||
}); | ||
test.equal(message.num, 1, "should initialize the last value"); | ||
test.equal(message.kind, "num", "should reference the last value"); | ||
test.notOk(message.hasOwnProperty('str'), "should not initialize other values"); | ||
|
||
message.str = "a"; | ||
message.setKind('str'); // message.kind = 'str' if IE8 support isn't required | ||
|
||
test.notOk(message.hasOwnProperty('num'), "should delete the previous value"); | ||
test.equal(message.str, "a", "should set the new value"); | ||
test.equal(message.kind, "str", "should reference the new value"); | ||
|
||
test.end(); | ||
}); | ||
|
||
}); |