Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Commit

Permalink
100% test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
kesla committed Mar 24, 2016
1 parent 9c885cd commit badf851
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 4 additions & 4 deletions snappy.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ exports.isValidCompressedSync = binding.isValidCompressedSync;
* A parser can be attached. If no parser is attached, return buffer.
*/
exports.uncompress = function (compressed, opts, callback) {
if (!Buffer.isBuffer(compressed)) {
return callback(new Error('input must be a Buffer'));
}

if (!callback) {
callback = opts;
opts = {};
}

if (!Buffer.isBuffer(compressed)) {
return callback(new Error('input must be a Buffer'));
}

if (typeof (opts.asBuffer) !== 'boolean') {
opts.asBuffer = true;
}
Expand Down
14 changes: 14 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ test('compress() buffer', function (t) {
});
});

test('compress() bad input', function (t) {
snappy.compress(123, function (err) {
t.equal(err && err.message, 'input must be a String or a Buffer');
t.end();
});
})

test('compressSync() buffer', function (t) {
var buffer = snappy.compressSync(inputBuffer);
t.ok(Buffer.isBuffer(buffer), 'should return a Buffer');
Expand Down Expand Up @@ -98,6 +105,13 @@ test('uncompress() on bad input', function (t) {
});
});

test('uncompress() on not a Buffer', function (t) {
snappy.uncompress('beep boop OMG OMG OMG', function (err) {
t.equal(err.message, 'input must be a Buffer');
t.end();
})
});

test('uncompressSync() defaults to Buffer', function (t) {
var results = snappy.uncompressSync(compressed);
t.deepEqual(results, inputBuffer);
Expand Down

0 comments on commit badf851

Please sign in to comment.