Adding tests suites for readAll and readStream

This commit is contained in:
Nicolas Dextraze
2016-03-14 17:55:35 -07:00
parent 19ef91030c
commit 77704a8786
15 changed files with 538 additions and 75 deletions

View File

@ -1,23 +1,38 @@
module.exports.notNullOrEmpty = function(value, name) {
if (value === null)
throw new Error(name + " is null.");
throw new TypeError(name + " should not be null.");
if (value === '')
throw new Error(name + " is empty.");
throw new Error(name + " should not be empty.");
};
module.exports.notNull = function(value, name) {
if (value === null)
throw new Error(name + " is null.");
throw new TypeError(name + " should not be null.");
};
module.exports.isInteger = function(value, name) {
if (typeof value !== 'number' || value % 1 !== 0)
throw new TypeError(name + " is not an integer.");
throw new TypeError(name + " should be an integer.");
};
module.exports.isArrayOf = function(expectedType, value, name) {
if (!Array.isArray(value))
throw new TypeError(name + " is not an array.");
throw new TypeError(name + " should be an array.");
if (!value.every(function(x) { return x instanceof expectedType; }))
throw new TypeError([name, " is not an array of ", expectedType, "."].join(""));
throw new TypeError([name, " should be an array of ", expectedType, "."].join(""));
};
module.exports.isTypeOf = function(expectedType, value, name) {
if (!(value instanceof expectedType))
throw new TypeError([name, " should be of type '", expectedType, "'."].join(""));
};
module.exports.positive = function(value, name) {
if (value <= 0)
throw new Error(name + " should be positive.");
};
module.exports.nonNegative = function(value, name) {
if (value < 0)
throw new Error(name + " should be non-negative.");
};