mirror of
https://github.com/protobufjs/protobuf.js.git
synced 2025-12-08 20:58:55 +00:00
45 lines
1.5 KiB
JavaScript
45 lines
1.5 KiB
JavaScript
var tape = require("tape");
|
|
|
|
var protobuf = require(".."),
|
|
pkg = require("../package.json");
|
|
|
|
tape.test("package.json", function(test) {
|
|
|
|
protobuf.load("tests/data/package.proto", function(err, root) {
|
|
if (err)
|
|
return test.fail(err.message);
|
|
|
|
var Package = root.lookup("Package"),
|
|
Repository = root.lookup("Package.Repository");
|
|
|
|
var myPackage = Package.create(pkg);
|
|
|
|
test.test("runtime message", function(test) {
|
|
|
|
test.ok(myPackage instanceof protobuf.Message, "should extend Message");
|
|
test.equal(myPackage.$type, Package, "should reference Package as its reflected type");
|
|
test.deepEqual(myPackage, pkg, "should have equal contents");
|
|
|
|
test.end();
|
|
});
|
|
|
|
test.test("decoded message", function(test) {
|
|
|
|
var writer = Package.encode(myPackage);
|
|
var buf = writer.finish();
|
|
var decoded = Package.decode(buf);
|
|
|
|
test.ok(decoded instanceof protobuf.Message, "should extend Message");
|
|
test.equal(decoded.$type, Package, "should reference Package as its reflected type");
|
|
test.ok(decoded.repository instanceof protobuf.Message, "submessages should also extend Message");
|
|
test.equal(decoded.repository.$type, Repository, "repository submessage should reference Repository as its reflected type");
|
|
test.deepEqual(decoded, pkg, "should have equal contents");
|
|
|
|
test.end();
|
|
});
|
|
|
|
test.end();
|
|
});
|
|
|
|
});
|