Skip to content

Commit

Permalink
chore: add grammar tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sofisl committed Sep 24, 2024
1 parent 1ca7586 commit e73bb3c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ function parse(source, root, options) {

case "optional":
/* istanbul ignore if */
// console.log('in optional?')
// console.log('')
if (isProto3) {
parseField(type, "proto3_optional");
} else if (edition) {
Expand Down
33 changes: 33 additions & 0 deletions tests/feature_grammar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
var tape = require("tape");

var protobuf = require("..");

var protoEditionsRequired = `edition = "2023";
message A {\
required uint32 a = 1;\
}`;
var protoEditionsOptional = `edition = "2023";
message A {\
optional uint32 a = 1;\
}`;

var protoEditionsGroup = `edition = "2023";
message A {\
group uint32 a = 1;\
}`;

tape.test("editions grammar", function(test) {
test.throws(function() {
protobuf.parse(protoEditionsRequired);
}, Error, "Error: illegal token 'required'");

test.throws(function() {
protobuf.parse(protoEditionsOptional);
}, Error, "Error: illegal token 'optional'");

test.throws(function() {
protobuf.parse(protoEditionsGroup);
}, Error, "Error: illegal token 'group'");

test.end();
});

0 comments on commit e73bb3c

Please sign in to comment.