node_modules

This commit is contained in:
saeid
2019-07-15 13:07:31 +04:30
parent d3735c6d30
commit ce1a3ebf9c
35713 changed files with 3639219 additions and 1 deletions
+89
View File
@@ -0,0 +1,89 @@
'use strict';
var overload = require('../');
module.exports = {
'required, good': function (test) {
var items = [
{ fn: overload.func, param: function () {} },
{ fn: overload.funcOptional, param: function () {} },
{ fn: overload.funcOptionalWithDefault(function () {}), param: function () {} },
{ fn: overload.callbackOptional, param: function () {} },
{ fn: overload.string, param: 'test' },
{ fn: overload.stringOptional, param: 'test' },
{ fn: overload.stringOptionalWithDefault('test'), param: 'test' },
{ fn: overload.number, param: 5 },
{ fn: overload.numberOptional, param: 5 },
{ fn: overload.numberOptionalWithDefault(5), param: 5 },
{ fn: overload.array, param: [1] },
{ fn: overload.arrayOptional, param: [1] },
{ fn: overload.arrayOptionalWithDefault([1]), param: [1] },
{ fn: overload.object, param: {} },
{ fn: overload.objectOptional, param: {} },
{ fn: overload.objectOptionalWithDefault({}), param: {} }
];
items.forEach(function (item) {
test.equals(item.fn(item.param), true);
});
test.done();
},
'required, bad': function (test) {
var items = [
{ fn: overload.func, param: 5 },
{ fn: overload.funcOptional, param: 5 },
{ fn: overload.funcOptionalWithDefault(function () {}), param: 5 },
{ fn: overload.callbackOptional, param: 5 },
{ fn: overload.string, param: 5 },
{ fn: overload.stringOptional, param: 5 },
{ fn: overload.stringOptionalWithDefault('test'), param: 5 },
{ fn: overload.number, param: 'test' },
{ fn: overload.numberOptional, param: 'test' },
{ fn: overload.numberOptionalWithDefault(5), param: 'test' },
{ fn: overload.array, param: 5 },
{ fn: overload.arrayOptional, param: 5 },
{ fn: overload.arrayOptionalWithDefault([]), param: 5 },
{ fn: overload.object, param: 5 },
{ fn: overload.objectOptional, param: 5 },
{ fn: overload.objectOptionalWithDefault({}), param: 5 }
];
items.forEach(function (item) {
test.equals(item.fn(item.param), false);
});
test.done();
},
'optional, null': function (test) {
var items = [
{ fn: overload.funcOptional },
{ fn: overload.stringOptional },
{ fn: overload.numberOptional },
{ fn: overload.arrayOptional },
{ fn: overload.objectOptional }
];
items.forEach(function (item) {
test.equals(item.fn(null), true, 'invalid results for function: ' + item.fn.name);
});
test.done();
},
'optional, callback': function (test) {
test.equals(typeof(overload.callbackOptional(null).defaultValue), 'function');
test.done();
},
'with defaults': function (test) {
var fn = function () {};
var items = [
{ fn: overload.funcOptionalWithDefault(fn), expected: fn },
{ fn: overload.stringOptionalWithDefault('test'), expected: 'test' },
{ fn: overload.numberOptionalWithDefault(5), expected: 5 },
{ fn: overload.arrayOptionalWithDefault([]), expected: [] },
{ fn: overload.objectOptionalWithDefault({}), expected: {} }
];
items.forEach(function (item) {
test.deepEqual(item.fn.defaultValue, item.expected);
});
test.done();
}
};
+295
View File
@@ -0,0 +1,295 @@
'use strict';
var overload = require('../');
module.exports = {
'no parameters, valid args': function (test) {
var called = 0;
var fn = overload([
[function () { called++; return 42; }]
]);
var ret = fn();
test.equals(called, 1);
test.equals(ret, 42);
test.done();
},
'no parameters, invalid args': function (test) {
var called = 0;
var fn = overload([
[function () { called++; }]
]);
try {
fn(1);
test.fail('should throw exception');
} catch (ex) {
}
test.done();
},
'default callback': function (test) {
var called = 0;
var args = null;
var fn = overload([
[overload.func, function (fn) { test.fail('should not be called.'); }],
function () {
called++;
args = Array.prototype.slice.call(arguments);
}
]);
fn('test');
test.equals(called, 1, 'overload not called');
test.deepEqual(args, ['test']);
test.done();
},
'one parameter, valid args': function (test) {
var called = 0;
var argFnCalled = 0;
var fn = overload([
[overload.func, function (fn) {
called++;
fn();
}]
]);
fn(function () { argFnCalled++; });
test.equals(called, 1, 'overload not called');
test.equals(argFnCalled, 1, 'arg function not called');
test.done();
},
'one parameter, invalid args': function (test) {
var called = 0;
var fn = overload([
[overload.func, function () { called++; }]
]);
try {
fn(1);
test.fail('should throw exception');
} catch (ex) {
}
test.done();
},
'optional parameter, valid args': function (test) {
var called = 0;
var argFnCalled = 0;
var fn = overload([
[overload.funcOptional, function (fn) {
called++;
fn();
}]
]);
fn(function () { argFnCalled++; });
test.equals(called, 1, 'overload not called');
test.equals(argFnCalled, 1, 'arg function not called');
test.done();
},
'optional parameter, no args': function (test) {
var called = 0;
var fn = overload([
[overload.funcOptional, function (fn) {
called++;
if (fn) {
test.fail('no function should be passed');
}
}]
]);
fn();
test.equals(called, 1, 'overload not called');
test.done();
},
'optional parameter, invalid args': function (test) {
var called = 0;
var fn = overload([
[overload.funcOptional, function () { called++; }]
]);
try {
fn(1);
test.fail('should throw exception');
} catch (ex) {
}
test.done();
},
'multiple overloads, valid args': function (test) {
var called = 0;
var val = null;
var fn = overload([
[overload.number, function (n) { test.fail('this function should not be called'); }],
[overload.string, function (s) {
val = s;
called++;
}]
]);
fn('test');
test.equals(called, 1, 'overload not called');
test.equals(val, 'test', 'overload called with wrong value');
test.done();
},
'multiple overloads, invalid args': function (test) {
var called = 0;
var fn = overload([
[overload.number, function (n) { test.fail('this function should not be called'); }],
[overload.string, function (s) { called++; }]
]);
try {
fn(function () {});
test.fail('should throw exception');
} catch (ex) {
}
test.done();
},
'optional parameter, with default value': function (test) {
var called = 0;
var val = null;
var fn = overload([
[overload.numberOptionalWithDefault(5), overload.func, function (n) {
called++;
val = n;
}]
]);
fn(function() {});
test.equals(called, 1, 'overload not called');
test.equals(val, 5);
test.done();
},
'number optional parameter, called with non-zero number': function (test) {
var called = 0;
var val = null;
var fn = overload([
[overload.numberOptionalWithDefault(5), overload.func, function (n) {
called++;
val = n;
}]
]);
fn(3, function() {});
test.equals(called, 1, 'overload not called');
test.equals(val, 3);
test.done();
},
'number optional parameter, called with zero': function (test) {
var called = 0;
var val = null;
var fn = overload([
[overload.numberOptionalWithDefault(5), overload.func, function (n) {
called++;
val = n;
}]
]);
fn(0, function() {});
test.equals(called, 1, 'overload not called');
test.equals(val, 0);
test.done();
},
'string optional parameter, called with empty string': function (test) {
var called = 0;
var val = null;
var fn = overload([
[overload.stringOptionalWithDefault("hello world"), overload.func, function (n) {
called++;
val = n;
}]
]);
fn("", function() {});
test.equals(called, 1, 'overload not called');
test.equals(val, "");
test.done();
},
'callback, with default value': function (test) {
var called = 0;
var fn = overload([
[overload.callbackOptional, function (callback) {
callback();
}]
]);
fn(function () { called++; });
test.equals(called, 1, 'overload not called');
test.done();
},
'multiple optionals': function (test) {
var called = 0;
var args;
var fn = overload([
[overload.string, overload.arrayOptionalWithDefault(null), overload.callbackOptional, function (str, arr, callback) {
args = arguments;
called++;
}]
]);
fn('test');
test.equals(called, 1, 'overload not called');
test.equals(args.length, 3);
test.equals(args[0], 'test');
test.ok(args[1] === null);
test.equals(typeof(args[2]), 'function');
test.done();
},
'multiple optionals, skipping middle one': function (test) {
var called = 0;
var args;
var fn = overload([
[overload.string, overload.arrayOptional, overload.callbackOptional, function (str, arr, callback) {
args = arguments;
called++;
}]
]);
var fnTest = function zzz() {};
fn('test', fnTest);
test.equals(called, 1, 'overload not called');
test.equals(args.length, 3);
test.equals(args[0], 'test');
test.ok(args[1] === undefined, 'invalid argument, expected undefined: ' + args[1]);
test.equals(args[2].name, 'zzz');
test.done();
},
'multiple optionals, null middle one': function (test) {
var called = 0;
var args;
var fn = overload([
[overload.string, overload.arrayOptional, overload.callbackOptional, function (str, arr, callback) {
args = arguments;
called++;
}]
]);
var fnTest = function zzz() {};
fn('test', null, fnTest);
test.equals(called, 1, 'overload not called');
test.equals(args.length, 3);
test.equals(args[0], 'test');
test.ok(args[1] === undefined, 'invalid argument, expected undefined: ' + args[1]);
test.equals(args[2].name, 'zzz');
test.done();
},
'complex': function (test) {
var called = 0;
var args = null;
var fn = overload([
[overload.string, function () { test.fail('this function should not be called'); }],
[overload.string, overload.number, overload.funcOptional, function () {
args = Array.prototype.slice.call(arguments, 0);
called++;
}]
]);
var argFn = function () {};
fn('test', 5, argFn);
test.equals(called, 1, 'overload not called');
test.deepEqual(args, ['test', 5, argFn], 'overload called with wrong args');
test.done();
}
};