blob: f0a5e50f60c27d2c1ca9ce689fb3caf5d6b94e93 [file] [log] [blame]
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();
});