mirror of
https://github.com/protobufjs/protobuf.js.git
synced 2025-12-08 20:58:55 +00:00
47 lines
1.5 KiB
JavaScript
47 lines
1.5 KiB
JavaScript
var tape = require("tape");
|
|
|
|
var protobuf = require("..");
|
|
|
|
tape.test("uncommon statements", function(test) {
|
|
test.plan(3);
|
|
protobuf.load("tests/data/uncommon.proto", function(err, root) {
|
|
if (err || !root)
|
|
test.fail(err && err.message || "should parse without errors");
|
|
new protobuf.Root().load("tests/data/uncommon.proto", { keepCase: true }, function(err, root) {
|
|
if (err || !root) {
|
|
test.fail(err && err.message || "should parse without errors");
|
|
return;
|
|
}
|
|
test.pass("should parse without errors");
|
|
test.doesNotThrow(function() {
|
|
root.resolveAll();
|
|
}, "should resolve without errors");
|
|
test.doesNotThrow(function() {
|
|
traverseTypes(root, function(type) {
|
|
type.setup();
|
|
});
|
|
}, "should setup all types without errors");
|
|
test.end();
|
|
});
|
|
});
|
|
});
|
|
|
|
function traverseTypes(current, fn) {
|
|
if (current instanceof protobuf.Type) // and/or protobuf.Enum, protobuf.Service etc.
|
|
fn(current);
|
|
if (current.nestedArray)
|
|
current.nestedArray.forEach(function(nested) {
|
|
traverseTypes(nested, fn);
|
|
});
|
|
}
|
|
|
|
tape.test("invalid lookup", async function(test) {
|
|
try {
|
|
await protobuf.load("tests/data/invalid-lookup.proto");
|
|
test.fail("should have thrown");
|
|
} catch(err) {
|
|
test.match(err.message, /illegal token 'required'/, "failed to parse");
|
|
}
|
|
});
|
|
|