mirror of
https://github.com/protobufjs/protobuf.js.git
synced 2025-12-08 20:58:55 +00:00
https://github.com/protobufjs/protobuf.js/pull/1584 made proto3 optional scalars default to null when using static/static-module, but the old behaviour remained when using reflection (eg json-module).
31 lines
813 B
JavaScript
31 lines
813 B
JavaScript
var tape = require("tape");
|
|
|
|
var protobuf = require("..");
|
|
|
|
var proto = "syntax = \"proto3\";\
|
|
\
|
|
message Message {\
|
|
int32 regular_int32 = 1;\
|
|
optional int32 optional_int32 = 2;\
|
|
oneof _oneof_int32 {\
|
|
int32 oneof_int32 = 3;\
|
|
}\
|
|
}\
|
|
";
|
|
|
|
tape.test("proto3 optional", function(test) {
|
|
var root = protobuf.parse(proto).root;
|
|
|
|
var Message = root.lookup("Message");
|
|
test.equal(Message.fields.optionalInt32.optional, true);
|
|
test.equal(Message.fields.optionalInt32.options.proto3_optional, true);
|
|
test.equal(Message.oneofs._optionalInt32.name, '_optionalInt32');
|
|
test.deepEqual(Message.oneofs._optionalInt32.oneof, ['optionalInt32']);
|
|
|
|
var m = Message.create({});
|
|
test.strictEqual(m.regularInt32, 0);
|
|
test.strictEqual(m.optionalInt32, null);
|
|
|
|
test.end();
|
|
});
|