-
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.
Merge pull request #558 from DataDog/fix-repeated-default
Fix asJSON defaults option, make it work for repeated fields.
- Loading branch information
Showing
3 changed files
with
36 additions
and
5 deletions.
There are no files selected for viewing
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"; | ||
|
||
package test; | ||
|
||
message TestRepeatedDefaults { | ||
required string aString = 1; | ||
repeated string repeatString = 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,25 @@ | ||
var tape = require("tape"); | ||
var protobuf = require(".."); | ||
|
||
tape.test("test asJSON repeated defaults", function(test) { | ||
|
||
protobuf.load("tests/data/message.proto", function(err, root) { | ||
if (err) | ||
return test.fail(err.message); | ||
test.ok(true, "should parse without errors"); | ||
|
||
var TestMessage = root.lookup("test.TestRepeatedDefaults"); | ||
var msg1 = TestMessage.create({ aString: 'foo' }); | ||
|
||
var defaultsOn = msg1.asJSON({ defaults: true }); | ||
test.equal(defaultsOn.aString, 'foo', "should set aString value"); | ||
test.same(defaultsOn.repeatString, [], "should set repeated default"); | ||
|
||
var defaultsOff = msg1.asJSON({ defaults: false }); | ||
test.equal(defaultsOff.aString, 'foo', "should set aString value"); | ||
test.same(defaultsOff.repeatString, undefined, "should not set repeated default"); | ||
|
||
test.end(); | ||
}); | ||
|
||
}); |