Skip to content

Commit e73bb3c

Browse files
committed
chore: add grammar tests
1 parent 1ca7586 commit e73bb3c

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/parse.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ function parse(source, root, options) {
378378

379379
case "optional":
380380
/* istanbul ignore if */
381+
// console.log('in optional?')
382+
// console.log('')
381383
if (isProto3) {
382384
parseField(type, "proto3_optional");
383385
} else if (edition) {

tests/feature_grammar.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
var tape = require("tape");
2+
3+
var protobuf = require("..");
4+
5+
var protoEditionsRequired = `edition = "2023";
6+
message A {\
7+
required uint32 a = 1;\
8+
}`;
9+
var protoEditionsOptional = `edition = "2023";
10+
message A {\
11+
optional uint32 a = 1;\
12+
}`;
13+
14+
var protoEditionsGroup = `edition = "2023";
15+
message A {\
16+
group uint32 a = 1;\
17+
}`;
18+
19+
tape.test("editions grammar", function(test) {
20+
test.throws(function() {
21+
protobuf.parse(protoEditionsRequired);
22+
}, Error, "Error: illegal token 'required'");
23+
24+
test.throws(function() {
25+
protobuf.parse(protoEditionsOptional);
26+
}, Error, "Error: illegal token 'optional'");
27+
28+
test.throws(function() {
29+
protobuf.parse(protoEditionsGroup);
30+
}, Error, "Error: illegal token 'group'");
31+
32+
test.end();
33+
});

0 commit comments

Comments
 (0)