2015-04-22 17:12:45 +02:00
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var ID = 'core/util';
|
|
|
|
var DEPS = [];
|
|
|
|
|
2015-04-22 23:21:48 +02:00
|
|
|
describe('module \'' + ID + '\'', function () {
|
2015-04-22 17:12:45 +02:00
|
|
|
|
|
|
|
before(function () {
|
|
|
|
|
|
|
|
this.definition = modulejs._private.definitions[ID];
|
|
|
|
|
|
|
|
this.applyFn = function () {
|
|
|
|
|
|
|
|
return this.definition.fn();
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('definition', function () {
|
|
|
|
|
|
|
|
it('is defined', function () {
|
|
|
|
|
|
|
|
assert.isPlainObject(this.definition);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has correct id', function () {
|
|
|
|
|
|
|
|
assert.strictEqual(this.definition.id, ID);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('requires correct', function () {
|
|
|
|
|
|
|
|
assert.deepEqual(this.definition.deps, DEPS);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('args for each request', function () {
|
|
|
|
|
|
|
|
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has no instance', function () {
|
|
|
|
|
|
|
|
assert.notProperty(modulejs._private.instances, ID);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('inits without errors', function () {
|
|
|
|
|
|
|
|
this.applyFn();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('application', function () {
|
|
|
|
|
|
|
|
it('returns plain object with 2 properties', function () {
|
|
|
|
|
|
|
|
var instance = this.applyFn();
|
|
|
|
assert.isPlainObject(instance);
|
|
|
|
assert.lengthOfKeys(instance, 2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-04-22 19:34:35 +02:00
|
|
|
describe('.regularCmpFn()', function () {
|
2015-04-22 17:12:45 +02:00
|
|
|
|
2015-04-22 19:34:35 +02:00
|
|
|
it('is function', function () {
|
2015-04-22 17:12:45 +02:00
|
|
|
|
|
|
|
var instance = this.applyFn();
|
|
|
|
assert.isFunction(instance.regularCmpFn);
|
|
|
|
});
|
|
|
|
|
|
|
|
_.each([
|
|
|
|
[0, 0, 0],
|
|
|
|
[1, 0, 1],
|
|
|
|
[1, 2, -1],
|
|
|
|
['a', 'a', 0],
|
|
|
|
['b', 'a', 1],
|
|
|
|
['a', 'b', -1],
|
|
|
|
['a 2', 'a 10', 1]
|
|
|
|
], function (data) {
|
|
|
|
|
|
|
|
var arg1 = data[0];
|
|
|
|
var arg2 = data[1];
|
|
|
|
var exp = data[2];
|
|
|
|
|
2015-04-22 23:45:23 +02:00
|
|
|
it(arg1 + ', ' + arg2 + ' => ' + exp, function () {
|
2015-04-22 17:12:45 +02:00
|
|
|
|
|
|
|
var instance = this.applyFn();
|
|
|
|
assert.strictEqual(instance.regularCmpFn(arg1, arg2), exp);
|
|
|
|
});
|
|
|
|
});
|
2015-04-22 19:34:35 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('.naturalCmpFn()', function () {
|
|
|
|
|
|
|
|
it('is function', function () {
|
|
|
|
|
|
|
|
var instance = this.applyFn();
|
|
|
|
assert.isFunction(instance.naturalCmpFn);
|
|
|
|
});
|
2015-04-22 17:12:45 +02:00
|
|
|
|
|
|
|
_.each([
|
|
|
|
[0, 0, 0],
|
|
|
|
[1, 0, 1],
|
|
|
|
[1, 2, -1],
|
|
|
|
['a', 'a', 0],
|
|
|
|
['b', 'a', 1],
|
|
|
|
['a', 'b', -1],
|
|
|
|
['a 2', 'a 10', -1]
|
|
|
|
], function (data) {
|
|
|
|
|
|
|
|
var arg1 = data[0];
|
|
|
|
var arg2 = data[1];
|
|
|
|
var exp = data[2];
|
|
|
|
|
2015-04-22 23:45:23 +02:00
|
|
|
it(arg1 + ', ' + arg2 + ' => ' + exp, function () {
|
2015-04-22 17:12:45 +02:00
|
|
|
|
|
|
|
var instance = this.applyFn();
|
|
|
|
assert.strictEqual(instance.naturalCmpFn(arg1, arg2), exp);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}());
|