From e73bb3c29840ff40004d668a6cc31ca0b45499a2 Mon Sep 17 00:00:00 2001 From: Sofia Leon Date: Tue, 24 Sep 2024 13:22:46 -0700 Subject: [PATCH] chore: add grammar tests --- src/parse.js | 2 ++ tests/feature_grammar.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 tests/feature_grammar.js diff --git a/src/parse.js b/src/parse.js index 403e447e8..c999aa3ba 100644 --- a/src/parse.js +++ b/src/parse.js @@ -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) { diff --git a/tests/feature_grammar.js b/tests/feature_grammar.js new file mode 100644 index 000000000..6199fcb81 --- /dev/null +++ b/tests/feature_grammar.js @@ -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(); +});