Skip to content

Commit

Permalink
rewrite library version tests from LiveScript to JavaScript
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Nov 2, 2017
1 parent 2bd2a12 commit 48aa845
Show file tree
Hide file tree
Showing 375 changed files with 7,718 additions and 5,449 deletions.
5 changes: 4 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ module.exports = grunt => {
src: {
files: {
'./tests/tests.js': './tests/tests/*',
'./tests/library.js': './tests/library/*',
},
},
},
Expand Down Expand Up @@ -102,6 +101,10 @@ module.exports = grunt => {
entry: './tests/helpers/index.js',
output: { filename: 'helpers.js' },
},
library: {
entry: './tests/library/index.js',
output: { filename: 'library.js' },
},
},
});
grunt.registerTask('build', function (options) {
Expand Down
4 changes: 4 additions & 0 deletions tests/helpers/includes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
global.includes = function (target, element) {
for (var i = 0, length = target.length; i < length; ++i) if (target[i] === element) return true;
return false;
};
1 change: 1 addition & 0 deletions tests/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ require('./array-to-buffer');
require('./buffer-to-array');
require('./create-iterable');
require('./epsilon');
require('./includes');
require('./is-function');
require('./is-iterable');
require('./is-iterator');
Expand Down
16 changes: 16 additions & 0 deletions tests/library/core.get-iterator-method.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var test = QUnit.test;

test('core.getIteratorMethod', function (assert) {
var getIteratorMethod = core.getIteratorMethod;
assert.isFunction(getIteratorMethod);
var iterable = createIterable([]);
var iterFn = getIteratorMethod(iterable);
assert.isFunction(iterFn);
assert.isIterator(iterFn.call(iterable));
assert.isFunction(getIteratorMethod([]));
assert.isFunction(getIteratorMethod(function () {
return arguments;
}()));
assert.isFunction(getIteratorMethod(Array.prototype));
assert.strictEqual(getIteratorMethod({}), undefined);
});
14 changes: 0 additions & 14 deletions tests/library/core.get-iterator-method.ls

This file was deleted.

14 changes: 14 additions & 0 deletions tests/library/core.get-iterator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var test = QUnit.test;

test('core.getIterator', function (assert) {
var getIterator = core.getIterator;
assert.isFunction(getIterator);
assert.isIterator(getIterator([]));
assert.isIterator(getIterator(function () {
return arguments;
}()));
assert.isIterator(getIterator(createIterable([])));
assert['throws'](function () {
getIterator({});
}, TypeError);
});
10 changes: 0 additions & 10 deletions tests/library/core.get-iterator.ls

This file was deleted.

13 changes: 13 additions & 0 deletions tests/library/core.is-iterable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var test = QUnit.test;

test('core.isIterable', function (assert) {
var isIterable = core.isIterable;
assert.isFunction(isIterable);
assert.ok(isIterable(createIterable([])));
assert.ok(isIterable([]));
assert.ok(isIterable(function () {
return arguments;
}()));
assert.ok(isIterable(Array.prototype));
assert.ok(!isIterable({}));
});
11 changes: 0 additions & 11 deletions tests/library/core.is-iterable.ls

This file was deleted.

28 changes: 28 additions & 0 deletions tests/library/es.array.copy-within.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var test = QUnit.test;

test('Array#copyWithin', function (assert) {
var copyWithin = core.Array.copyWithin;
assert.isFunction(copyWithin);
var array = [1];
assert.strictEqual(copyWithin(array, 0), array);
assert.deepEqual(copyWithin([1, 2, 3, 4, 5], 0, 3), [4, 5, 3, 4, 5]);
assert.deepEqual(copyWithin([1, 2, 3, 4, 5], 1, 3), [1, 4, 5, 4, 5]);
assert.deepEqual(copyWithin([1, 2, 3, 4, 5], 1, 2), [1, 3, 4, 5, 5]);
assert.deepEqual(copyWithin([1, 2, 3, 4, 5], 2, 2), [1, 2, 3, 4, 5]);
assert.deepEqual(copyWithin([1, 2, 3, 4, 5], 0, 3, 4), [4, 2, 3, 4, 5]);
assert.deepEqual(copyWithin([1, 2, 3, 4, 5], 1, 3, 4), [1, 4, 3, 4, 5]);
assert.deepEqual(copyWithin([1, 2, 3, 4, 5], 1, 2, 4), [1, 3, 4, 4, 5]);
assert.deepEqual(copyWithin([1, 2, 3, 4, 5], 0, -2), [4, 5, 3, 4, 5]);
assert.deepEqual(copyWithin([1, 2, 3, 4, 5], 0, -2, -1), [4, 2, 3, 4, 5]);
assert.deepEqual(copyWithin([1, 2, 3, 4, 5], -4, -3, -2), [1, 3, 3, 4, 5]);
assert.deepEqual(copyWithin([1, 2, 3, 4, 5], -4, -3, -1), [1, 3, 4, 4, 5]);
assert.deepEqual(copyWithin([1, 2, 3, 4, 5], -4, -3), [1, 3, 4, 5, 5]);
if (STRICT) {
assert['throws'](function () {
copyWithin(null, 0);
}, TypeError);
assert['throws'](function () {
copyWithin(undefined, 0);
}, TypeError);
}
});
22 changes: 0 additions & 22 deletions tests/library/es.array.copy-within.ls

This file was deleted.

47 changes: 47 additions & 0 deletions tests/library/es.array.every.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var test = QUnit.test;

test('Array#every', function (assert) {
var every = core.Array.every;
assert.isFunction(every);
var array = [1];
var context = {};
every(array, function (value, key, that) {
assert.same(arguments.length, 3, 'correct number of callback arguments');
assert.same(value, 1, 'correct value in callback');
assert.same(key, 0, 'correct index in callback');
assert.same(that, array, 'correct link to array in callback');
assert.same(this, context, 'correct callback context');
}, context);
assert.ok(every([1, 2, 3], function (it) {
return typeof it === 'number';
}));
assert.ok(every([1, 2, 3], function (it) {
return it < 4;
}));
assert.ok(!every([1, 2, 3], function (it) {
return it < 3;
}));
assert.ok(!every([1, 2, 3], function (it) {
return typeof it === 'string';
}));
assert.ok(every([1, 2, 3], function () {
return +this === 1;
}, 1));
var rez = '';
every([1, 2, 3], function (value, key) {
return rez += key;
});
assert.ok(rez === '012');
var arr = [1, 2, 3];
assert.ok(every(arr, function (value, key, that) {
return that === arr;
}));
if (STRICT) {
assert['throws'](function () {
every(null, function () { /* empty */ });
}, TypeError);
assert['throws'](function () {
every(undefined, function () { /* empty */ });
}, TypeError);
}
});
25 changes: 0 additions & 25 deletions tests/library/es.array.every.ls

This file was deleted.

21 changes: 21 additions & 0 deletions tests/library/es.array.fill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var test = QUnit.test;

test('Array#fill', function (assert) {
var fill = core.Array.fill;
assert.isFunction(fill);
var array = fill(Array(5), 5);
assert.strictEqual(array, array);
assert.deepEqual(fill(Array(5), 5), [5, 5, 5, 5, 5]);
assert.deepEqual(fill(Array(5), 5, 1), [undefined, 5, 5, 5, 5]);
assert.deepEqual(fill(Array(5), 5, 1, 4), [undefined, 5, 5, 5, undefined]);
assert.deepEqual(fill(Array(5), 5, 6, 1), [undefined, undefined, undefined, undefined, undefined]);
assert.deepEqual(fill(Array(5), 5, -3, 4), [undefined, undefined, 5, 5, undefined]);
if (STRICT) {
assert['throws'](function () {
fill(null, 0);
}, TypeError);
assert['throws'](function () {
fill(undefined, 0);
}, TypeError);
}
});
15 changes: 0 additions & 15 deletions tests/library/es.array.fill.ls

This file was deleted.

26 changes: 26 additions & 0 deletions tests/library/es.array.filter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var test = QUnit.test;

test('Array#filter', function (assert) {
var filter = core.Array.filter;
assert.isFunction(filter);
var array = [1];
var context = {};
filter(array, function (value, key, that) {
assert.same(arguments.length, 3, 'correct number of callback arguments');
assert.same(value, 1, 'correct value in callback');
assert.same(key, 0, 'correct index in callback');
assert.same(that, array, 'correct link to array in callback');
assert.same(this, context, 'correct callback context');
}, context);
assert.deepEqual([1, 2, 3, 4, 5], filter([1, 2, 3, 'q', {}, 4, true, 5], function (it) {
return typeof it === 'number';
}));
if (STRICT) {
assert['throws'](function () {
filter(null, function () { /* empty */ });
}, TypeError);
assert['throws'](function () {
filter(undefined, function () { /* empty */ });
}, TypeError);
}
});
17 changes: 0 additions & 17 deletions tests/library/es.array.filter.ls

This file was deleted.

25 changes: 25 additions & 0 deletions tests/library/es.array.find-index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var test = QUnit.test;

test('Array#findIndex', function (assert) {
var findIndex = core.Array.findIndex;
assert.isFunction(findIndex);
var array = [1];
var context = {};
findIndex(array, function (value, key, that) {
assert.strictEqual(this, context);
assert.strictEqual(value, 1);
assert.strictEqual(key, 0);
assert.strictEqual(that, array);
}, context);
assert.strictEqual(findIndex([1, 3, NaN, 42, {}], function (it) {
return it === 42;
}), 3);
if (STRICT) {
assert['throws'](function () {
findIndex(null, 0);
}, TypeError);
assert['throws'](function () {
findIndex(undefined, 0);
}, TypeError);
}
});
16 changes: 0 additions & 16 deletions tests/library/es.array.find-index.ls

This file was deleted.

Loading

0 comments on commit 48aa845

Please sign in to comment.