Skip to content

Commit

Permalink
Other: Coverage for encoder compat. / protocolerror
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Mar 10, 2017
1 parent 948a4ca commit db1030e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h1><p align="center"><img alt="protobuf.js" src="https://github.com/dcodeIO/protobuf.js/raw/master/pbjs.png" width="120" height="104" /></p></h1>
<p align="center"><a href="https://travis-ci.org/dcodeIO/protobuf.js"><img src="https://travis-ci.org/dcodeIO/protobuf.js.svg?branch=master" alt=""></a> <a href="https://codeclimate.com/github/dcodeIO/protobuf.js/coverage"><img src="https://codeclimate.com/github/dcodeIO/protobuf.js/badges/coverage.svg" /></a> <a href="https://codeclimate.com/github/dcodeIO/protobuf.js"><img src="https://codeclimate.com/github/dcodeIO/protobuf.js/badges/gpa.svg" /></a> <a href="https://npmjs.org/package/protobufjs"><img src="https://img.shields.io/npm/dm/protobufjs.svg" alt=""></a> <a href="https://npmjs.org/package/protobufjs"><img src="https://img.shields.io/npm/v/protobufjs.svg" alt=""></a> <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=dcode%40dcode.io&item_name=Open%20Source%20Software%20Donation&item_number=dcodeIO%2Fprotobuf.js"><img alt="donate ❤" src="https://img.shields.io/badge/donate-❤-ff2244.svg"></a></p>
<p align="center"><a href="https://npmjs.org/package/protobufjs"><img src="https://img.shields.io/npm/v/protobufjs.svg" alt=""></a> <a href="https://travis-ci.org/dcodeIO/protobuf.js"><img src="https://travis-ci.org/dcodeIO/protobuf.js.svg?branch=master" alt=""></a> <a href="https://codeclimate.com/github/dcodeIO/protobuf.js/coverage"><img src="https://codeclimate.com/github/dcodeIO/protobuf.js/badges/coverage.svg" /></a> <a href="https://codeclimate.com/github/dcodeIO/protobuf.js"><img src="https://codeclimate.com/github/dcodeIO/protobuf.js/badges/gpa.svg" /></a> <a href="https://npmjs.org/package/protobufjs"><img src="https://img.shields.io/npm/dm/protobufjs.svg" alt=""></a> <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=dcode%40dcode.io&item_name=Open%20Source%20Software%20Donation&item_number=dcodeIO%2Fprotobuf.js"><img alt="donate ❤" src="https://img.shields.io/badge/donate-❤-ff2244.svg"></a></p>

**Protocol Buffers** are a language-neutral, platform-neutral, extensible way of serializing structured data for use in communications protocols, data storage, and more, originally designed at Google ([see](https://developers.google.com/protocol-buffers/)).

Expand Down Expand Up @@ -346,7 +346,7 @@ Documentation
* [Frequently asked questions](https://github.com/dcodeIO/protobuf.js/wiki) on our wiki

#### Community
* [Questions and answers](http://stackoverflow.com/search?q=protobuf.js) on StackOverflow
* [Questions and answers](http://stackoverflow.com/search?tab=newest&q=protobuf.js) on StackOverflow

Command line
------------
Expand Down
3 changes: 2 additions & 1 deletion src/encoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ function encoder(mtype) {

// "when a message is serialized its known fields should be written sequentially by field number"
var fields = /* initializes */ mtype.fieldsArray;
/* istanbul ignore else */
if (encoder.compat)
fields = fields.slice().sort(compareFieldsById);

for (var i = 0; i < fields.length; ++i) {
var field = fields[i].resolve(),
index = encoder.compat ? mtype._fieldsArray.indexOf(field) : i;
index = encoder.compat ? mtype._fieldsArray.indexOf(field) : /* istanbul ignore next */ i;
if (field.partOf) // see below for oneofs
continue;
var type = field.resolvedType instanceof Enum ? "uint32" : field.type,
Expand Down
2 changes: 2 additions & 0 deletions tests/other_protocolerror.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ tape.test("a protocol error", function(test) {
test.fail("should be thrown if a message is missing required fields");
} catch (e) {
test.ok(e instanceof ProtocolError, "should be thrown if a message is missing required fields");
test.ok(e.message, "should have an error message");
test.ok(e.stack, "should have a stack trace");
test.equal(e.name, "ProtocolError", "should have the correct name");
test.same(e.instance, {
foo: 2
Expand Down

0 comments on commit db1030e

Please sign in to comment.