mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 01:47:48 +00:00
Improve test coverage.
This commit is contained in:
@@ -3,7 +3,8 @@ node_js:
|
|||||||
- "0.12"
|
- "0.12"
|
||||||
env:
|
env:
|
||||||
global:
|
global:
|
||||||
- PATTERN1="s|\s*else\s*\{\s*iteratee\(index\);\s*\}||"
|
- PATTERN1="s|\s*if\s*\(isHostObject\b[\s\S]+?\}(?=\n)||"
|
||||||
|
- PATTERN2="s|\s*else\s*\{\s*iteratee\(index\);\s*\}||"
|
||||||
- BIN="node" ISTANBUL=false OPTION=""
|
- BIN="node" ISTANBUL=false OPTION=""
|
||||||
- NPM_VERSION="^2.0.0" SAUCE_LABS=false SAUCE_USERNAME="lodash"
|
- NPM_VERSION="^2.0.0" SAUCE_LABS=false SAUCE_USERNAME="lodash"
|
||||||
- secure: "tg1JFsIFnxzLaTboFPOnm+aJCuMm5+JdhLlESlqg9x3fwro++7KCnwHKLNovhchaPe4otC43ZMB/nfWhDnDm11dKbm/V6HlTkED+dadTsaLxVDg6J+7yK41QhokBPJOxLV78iDaNaAQVYEirAgZ0yn8kFubxmNKV+bpCGQNc9yU="
|
- secure: "tg1JFsIFnxzLaTboFPOnm+aJCuMm5+JdhLlESlqg9x3fwro++7KCnwHKLNovhchaPe4otC43ZMB/nfWhDnDm11dKbm/V6HlTkED+dadTsaLxVDg6J+7yK41QhokBPJOxLV78iDaNaAQVYEirAgZ0yn8kFubxmNKV+bpCGQNc9yU="
|
||||||
@@ -47,8 +48,8 @@ before_install:
|
|||||||
# - "[ $BIN != 'ringo' ] || (sudo ln -s /opt/ringojs-0.11/bin/ringo /usr/local/bin/ringo && sudo chmod +x $_)"
|
# - "[ $BIN != 'ringo' ] || (sudo ln -s /opt/ringojs-0.11/bin/ringo /usr/local/bin/ringo && sudo chmod +x $_)"
|
||||||
- "git clone --depth=10 --branch=master git://github.com/lodash/lodash-cli ./node_modules/lodash-cli && mkdir $_/node_modules && cd $_ && ln -s ../../../ ./lodash && cd ../ && npm i && cd ../../"
|
- "git clone --depth=10 --branch=master git://github.com/lodash/lodash-cli ./node_modules/lodash-cli && mkdir $_/node_modules && cd $_ && ln -s ../../../ ./lodash && cd ../ && npm i && cd ../../"
|
||||||
- "node ./node_modules/lodash-cli/bin/lodash -o ./lodash.js"
|
- "node ./node_modules/lodash-cli/bin/lodash -o ./lodash.js"
|
||||||
|
- "[ $ISTANBUL == false ] || (perl -0pi -e \"$PATTERN1\" ./lodash.js && perl -0pi -e \"$PATTERN2\" ./lodash.js)"
|
||||||
script:
|
script:
|
||||||
- "[ $ISTANBUL == false ] || perl -0pi -e \"$PATTERN\" ./lodash.js"
|
|
||||||
- "[ $ISTANBUL == false ] || node ./node_modules/istanbul/lib/cli.js cover -x \"**/vendor/**\" --report lcovonly ./test/test.js -- ./lodash.js"
|
- "[ $ISTANBUL == false ] || node ./node_modules/istanbul/lib/cli.js cover -x \"**/vendor/**\" --report lcovonly ./test/test.js -- ./lodash.js"
|
||||||
- "[ $ISTANBUL == false ] || [ $TRAVIS_SECURE_ENV_VARS == false ] || (cat ./coverage/lcov.info | coveralls) || true"
|
- "[ $ISTANBUL == false ] || [ $TRAVIS_SECURE_ENV_VARS == false ] || (cat ./coverage/lcov.info | coveralls) || true"
|
||||||
- "[ $SAUCE_LABS == true ] || [ $ISTANBUL == true ] || cd ./test"
|
- "[ $SAUCE_LABS == true ] || [ $ISTANBUL == true ] || cd ./test"
|
||||||
|
|||||||
71
test/test.js
71
test/test.js
@@ -1027,14 +1027,6 @@
|
|||||||
var args = arguments,
|
var args = arguments,
|
||||||
array = ['a', 'b', 'c'];
|
array = ['a', 'b', 'c'];
|
||||||
|
|
||||||
_.each(empties, function(value) {
|
|
||||||
if (value !== 0) {
|
|
||||||
array[value] = 1;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
array['1.1'] = array['-1'] = 1;
|
|
||||||
|
|
||||||
test('should return the elements corresponding to the specified keys', 1, function() {
|
test('should return the elements corresponding to the specified keys', 1, function() {
|
||||||
var actual = _.at(array, [0, 2]);
|
var actual = _.at(array, [0, 2]);
|
||||||
deepEqual(actual, ['a', 'c']);
|
deepEqual(actual, ['a', 'c']);
|
||||||
@@ -1045,11 +1037,15 @@
|
|||||||
deepEqual(actual, ['c', undefined, 'a']);
|
deepEqual(actual, ['c', undefined, 'a']);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should work with non-index keys on array-like values', 1, function() {
|
test('should work with non-index keys on array values', 1, function() {
|
||||||
var values = _.reject(empties, function(value) {
|
var values = _.reject(empties, function(value) {
|
||||||
return value === 0 || _.isArray(value);
|
return value === 0 || _.isArray(value);
|
||||||
}).concat(-1, 1.1);
|
}).concat(-1, 1.1);
|
||||||
|
|
||||||
|
var array = _.transform(values, function(result, value) {
|
||||||
|
result[value] = 1;
|
||||||
|
}, []);
|
||||||
|
|
||||||
var expected = _.map(values, _.constant(1)),
|
var expected = _.map(values, _.constant(1)),
|
||||||
actual = _.at(array, values);
|
actual = _.at(array, values);
|
||||||
|
|
||||||
@@ -7941,11 +7937,16 @@
|
|||||||
strictEqual(_.isPlainObject(new Foo(1)), false);
|
strictEqual(_.isPlainObject(new Foo(1)), false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should return `true` for objects with a `[[Prototype]]` of `null`', 1, function() {
|
test('should return `true` for objects with a `[[Prototype]]` of `null`', 2, function() {
|
||||||
if (create) {
|
if (create) {
|
||||||
strictEqual(_.isPlainObject(create(null)), true);
|
var object = create(null);
|
||||||
} else {
|
strictEqual(_.isPlainObject(object), true);
|
||||||
skipTest();
|
|
||||||
|
object.constructor = objectProto.constructor;
|
||||||
|
strictEqual(_.isPlainObject(object), true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
skipTest(2);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -12342,6 +12343,16 @@
|
|||||||
deepEqual(actual, ['c', undefined, 'a']);
|
deepEqual(actual, ['c', undefined, 'a']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should flatten `indexes`', 4, function() {
|
||||||
|
var array = ['a', 'b', 'c'];
|
||||||
|
deepEqual(_.pullAt(array, 2, 0), ['c', 'a']);
|
||||||
|
deepEqual(array, ['b']);
|
||||||
|
|
||||||
|
array = ['a', 'b', 'c', 'd'];
|
||||||
|
deepEqual(_.pullAt(array, [3, 0], 2), ['d', 'a', 'c']);
|
||||||
|
deepEqual(array, ['b']);
|
||||||
|
});
|
||||||
|
|
||||||
test('should return an empty array when no indexes are provided', 4, function() {
|
test('should return an empty array when no indexes are provided', 4, function() {
|
||||||
var array = ['a', 'b', 'c'],
|
var array = ['a', 'b', 'c'],
|
||||||
actual = _.pullAt(array);
|
actual = _.pullAt(array);
|
||||||
@@ -12355,20 +12366,34 @@
|
|||||||
deepEqual(actual, []);
|
deepEqual(actual, []);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should accept multiple index arguments', 2, function() {
|
test('should work with non-index paths', 2, function() {
|
||||||
var array = ['a', 'b', 'c', 'd'],
|
var values = _.reject(empties, function(value) {
|
||||||
actual = _.pullAt(array, 3, 0, 2);
|
return value === 0 || _.isArray(value);
|
||||||
|
}).concat(-1, 1.1);
|
||||||
|
|
||||||
deepEqual(array, ['b']);
|
var array = _.transform(values, function(result, value) {
|
||||||
deepEqual(actual, ['d', 'a', 'c']);
|
result[value] = 1;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
var expected = _.map(values, _.constant(1)),
|
||||||
|
actual = _.pullAt(array, values);
|
||||||
|
|
||||||
|
deepEqual(actual, expected);
|
||||||
|
|
||||||
|
expected = _.map(values, _.constant(undefined)),
|
||||||
|
actual = _.at(array, values);
|
||||||
|
|
||||||
|
deepEqual(actual, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should accept multiple arrays of indexes', 2, function() {
|
test('should work with deep paths', 2, function() {
|
||||||
var array = ['a', 'b', 'c', 'd'],
|
var array = [];
|
||||||
actual = _.pullAt(array, [3], [0, 2]);
|
array.a = { 'b': { 'c': 3 } };
|
||||||
|
|
||||||
deepEqual(array, ['b']);
|
var actual = _.pullAt(array, 'a.b.c');
|
||||||
deepEqual(actual, ['d', 'a', 'c']);
|
|
||||||
|
deepEqual(actual, [3]);
|
||||||
|
deepEqual(array.a, { 'b': {} });
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should work with a falsey `array` argument when keys are provided', 1, function() {
|
test('should work with a falsey `array` argument when keys are provided', 1, function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user