mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 16:47:49 +00:00
Fix tests for rhino -require.
This commit is contained in:
@@ -12,6 +12,9 @@
|
|||||||
/** Used as a reference to the global object */
|
/** Used as a reference to the global object */
|
||||||
var root = (objectTypes[typeof window] && window) || this;
|
var root = (objectTypes[typeof window] && window) || this;
|
||||||
|
|
||||||
|
/** Detect free variable `exports` */
|
||||||
|
var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
|
||||||
|
|
||||||
/** Detect free variable `global` from Node.js or Browserified code and use it as `root` */
|
/** Detect free variable `global` from Node.js or Browserified code and use it as `root` */
|
||||||
var freeGlobal = objectTypes[typeof global] && global;
|
var freeGlobal = objectTypes[typeof global] && global;
|
||||||
if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || freeGlobal.self === freeGlobal)) {
|
if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || freeGlobal.self === freeGlobal)) {
|
||||||
@@ -21,113 +24,123 @@
|
|||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a `Set` object.
|
* Installs `Set` on the given `context` object.
|
||||||
*/
|
|
||||||
function Set() {
|
|
||||||
this.__cache__ = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the index at which the first occurrence of `value` is found using
|
|
||||||
* strict equality for comparisons, i.e. `===`.
|
|
||||||
*
|
*
|
||||||
* @private
|
* @memberOf exports
|
||||||
* @param {Array} array The array to search.
|
* @param {Object} context The context object.
|
||||||
* @param {*} value The value to search for.
|
|
||||||
* @returns {number} Returns the index of the matched value or `-1`.
|
|
||||||
*/
|
*/
|
||||||
function indexOf(array, value) {
|
function runInContext(context) {
|
||||||
var index = -1,
|
|
||||||
length = array.length;
|
|
||||||
|
|
||||||
while (++index < length) {
|
/**
|
||||||
if (array[index] === value) {
|
* Creates a `Set` object.
|
||||||
return index;
|
*/
|
||||||
|
function Set() {
|
||||||
|
this.__cache__ = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the index at which the first occurrence of `value` is found using
|
||||||
|
* strict equality for comparisons, i.e. `===`.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {Array} array The array to search.
|
||||||
|
* @param {*} value The value to search for.
|
||||||
|
* @returns {number} Returns the index of the matched value or `-1`.
|
||||||
|
*/
|
||||||
|
function indexOf(array, value) {
|
||||||
|
var index = -1,
|
||||||
|
length = array.length;
|
||||||
|
|
||||||
|
while (++index < length) {
|
||||||
|
if (array[index] === value) {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/**
|
||||||
|
* Checks if `value` is in the set.
|
||||||
|
*
|
||||||
|
* @memberOf Set
|
||||||
|
* @param {*} value The value to search for.
|
||||||
|
* @returns {boolean} Returns `true` if `value` is found, else `false`.
|
||||||
|
*/
|
||||||
|
function has(value) {
|
||||||
|
var type = typeof value,
|
||||||
|
cache = this.__cache__;
|
||||||
|
|
||||||
/**
|
if (type == 'boolean' || value == null) {
|
||||||
* Checks if `value` is in the set.
|
return cache[value] || false;
|
||||||
*
|
}
|
||||||
* @memberOf Set
|
|
||||||
* @param {*} value The value to search for.
|
|
||||||
* @returns {boolean} Returns `true` if `value` is found, else `false`.
|
|
||||||
*/
|
|
||||||
function has(value) {
|
|
||||||
var type = typeof value,
|
|
||||||
cache = this.__cache__;
|
|
||||||
|
|
||||||
if (type == 'boolean' || value == null) {
|
|
||||||
return cache[value] || false;
|
|
||||||
}
|
|
||||||
if (type != 'number' && type != 'string') {
|
|
||||||
type = 'object';
|
|
||||||
}
|
|
||||||
var key = type == 'number' ? value : '_' + value;
|
|
||||||
cache = (cache = cache[type]) && cache[key];
|
|
||||||
|
|
||||||
return type == 'object'
|
|
||||||
? (cache && indexOf(cache, value) > -1 ? true : false)
|
|
||||||
: (cache || false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds `value` to the set.
|
|
||||||
*
|
|
||||||
* @memberOf Set
|
|
||||||
* @param {*} value The value to add.
|
|
||||||
*/
|
|
||||||
function add(value) {
|
|
||||||
var cache = this.__cache__,
|
|
||||||
type = typeof value;
|
|
||||||
|
|
||||||
if (type == 'boolean' || value == null) {
|
|
||||||
cache[value] = true;
|
|
||||||
} else {
|
|
||||||
if (type != 'number' && type != 'string') {
|
if (type != 'number' && type != 'string') {
|
||||||
type = 'object';
|
type = 'object';
|
||||||
}
|
}
|
||||||
var key = type == 'number' ? value : '_' + value,
|
var key = type == 'number' ? value : '_' + value;
|
||||||
typeCache = cache[type] || (cache[type] = {});
|
cache = (cache = cache[type]) && cache[key];
|
||||||
|
|
||||||
if (type == 'object') {
|
return type == 'object'
|
||||||
var array = typeCache[key];
|
? (cache && indexOf(cache, value) > -1 ? true : false)
|
||||||
if (array) {
|
: (cache || false);
|
||||||
array.push(value);
|
}
|
||||||
} else {
|
|
||||||
typeCache[key] = [value];
|
/**
|
||||||
}
|
* Adds `value` to the set.
|
||||||
|
*
|
||||||
|
* @memberOf Set
|
||||||
|
* @param {*} value The value to add.
|
||||||
|
*/
|
||||||
|
function add(value) {
|
||||||
|
var cache = this.__cache__,
|
||||||
|
type = typeof value;
|
||||||
|
|
||||||
|
if (type == 'boolean' || value == null) {
|
||||||
|
cache[value] = true;
|
||||||
} else {
|
} else {
|
||||||
typeCache[key] = true;
|
if (type != 'number' && type != 'string') {
|
||||||
|
type = 'object';
|
||||||
|
}
|
||||||
|
var key = type == 'number' ? value : '_' + value,
|
||||||
|
typeCache = cache[type] || (cache[type] = {});
|
||||||
|
|
||||||
|
if (type == 'object') {
|
||||||
|
var array = typeCache[key];
|
||||||
|
if (array) {
|
||||||
|
array.push(value);
|
||||||
|
} else {
|
||||||
|
typeCache[key] = [value];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
typeCache[key] = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Produces the `toString` result of `Set`.
|
* Produces the `toString` result of `Set`.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf Set
|
* @memberOf Set
|
||||||
* @returns {string} Returns the string result.
|
* @returns {string} Returns the string result.
|
||||||
*/
|
*/
|
||||||
function toString() {
|
function toString() {
|
||||||
return nativeString;
|
return nativeString;
|
||||||
|
}
|
||||||
|
|
||||||
|
Set.toString = toString;
|
||||||
|
Set.prototype.add = add;
|
||||||
|
Set.prototype.has = has;
|
||||||
|
|
||||||
|
if (!root.Set) {
|
||||||
|
context.Set = Set;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
Set.toString = toString;
|
if (freeExports) {
|
||||||
Set.prototype.add = add;
|
freeExports.runInContext = runInContext;
|
||||||
Set.prototype.has = has;
|
} else {
|
||||||
|
runInContext(root);
|
||||||
// expose `Set`
|
|
||||||
if (!root.Set) {
|
|
||||||
root.Set = Set;
|
|
||||||
}
|
}
|
||||||
}.call(this));
|
}.call(this));
|
||||||
|
|||||||
@@ -12,6 +12,9 @@
|
|||||||
/** Used as a reference to the global object */
|
/** Used as a reference to the global object */
|
||||||
var root = (objectTypes[typeof window] && window) || this;
|
var root = (objectTypes[typeof window] && window) || this;
|
||||||
|
|
||||||
|
/** Detect free variable `exports` */
|
||||||
|
var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
|
||||||
|
|
||||||
/** Detect free variable `global` from Node.js or Browserified code and use it as `root` */
|
/** Detect free variable `global` from Node.js or Browserified code and use it as `root` */
|
||||||
var freeGlobal = objectTypes[typeof global] && global;
|
var freeGlobal = objectTypes[typeof global] && global;
|
||||||
if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || freeGlobal.self === freeGlobal)) {
|
if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || freeGlobal.self === freeGlobal)) {
|
||||||
@@ -21,56 +24,68 @@
|
|||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a `WeakMap` object.
|
* Installs `WeakMap` on the given `context` object.
|
||||||
|
*
|
||||||
|
* @memberOf exports
|
||||||
|
* @param {Object} context The context object.
|
||||||
*/
|
*/
|
||||||
function WeakMap() {
|
function runInContext(context) {
|
||||||
// no-op
|
|
||||||
|
/**
|
||||||
|
* Creates a `WeakMap` object.
|
||||||
|
*/
|
||||||
|
function WeakMap() {
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value associated with the given key.
|
||||||
|
*
|
||||||
|
* @memberOf WeakMap
|
||||||
|
* @param {Object} key The key object.
|
||||||
|
* @returns {*} Returns the associated value, else `undefined`.
|
||||||
|
*/
|
||||||
|
function get(key) {
|
||||||
|
return key.__weakmap__;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a value for the given key.
|
||||||
|
*
|
||||||
|
* @memberOf WeakMap
|
||||||
|
* @param {Object} key The key object.
|
||||||
|
* @param {*} value The value to set.
|
||||||
|
*/
|
||||||
|
function set(key, value) {
|
||||||
|
key.__weakmap__ = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Produces the `toString` result of `WeakMap`.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @memberOf WeakMap
|
||||||
|
* @returns {string} Returns the string result.
|
||||||
|
*/
|
||||||
|
function toString() {
|
||||||
|
return nativeString;
|
||||||
|
}
|
||||||
|
|
||||||
|
WeakMap.toString = toString;
|
||||||
|
WeakMap.prototype.get = get;
|
||||||
|
WeakMap.prototype.set = set;
|
||||||
|
|
||||||
|
if (!root.WeakMap) {
|
||||||
|
context.WeakMap = WeakMap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
if (freeExports) {
|
||||||
* Gets the value associated with the given key.
|
freeExports.runInContext = runInContext;
|
||||||
*
|
} else {
|
||||||
* @memberOf WeakMap
|
runInContext(root);
|
||||||
* @param {Object} key The key object.
|
|
||||||
* @returns {*} Returns the associated value, else `undefined`.
|
|
||||||
*/
|
|
||||||
function get(key) {
|
|
||||||
return key.__weakmap__;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets a value for the given key.
|
|
||||||
*
|
|
||||||
* @memberOf WeakMap
|
|
||||||
* @param {Object} key The key object.
|
|
||||||
* @param {*} value The value to set.
|
|
||||||
*/
|
|
||||||
function set(key, value) {
|
|
||||||
key.__weakmap__ = value;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Produces the `toString` result of `WeakMap`.
|
|
||||||
*
|
|
||||||
* @static
|
|
||||||
* @memberOf WeakMap
|
|
||||||
* @returns {string} Returns the string result.
|
|
||||||
*/
|
|
||||||
function toString() {
|
|
||||||
return nativeString;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
WeakMap.toString = toString;
|
|
||||||
WeakMap.prototype.get = get;
|
|
||||||
WeakMap.prototype.set = set;
|
|
||||||
|
|
||||||
// expose `WeakMap`
|
|
||||||
if (!root.WeakMap) {
|
|
||||||
root.WeakMap = WeakMap;
|
|
||||||
}
|
}
|
||||||
}.call(this));
|
}.call(this));
|
||||||
|
|||||||
54
test/test.js
54
test/test.js
@@ -117,10 +117,6 @@
|
|||||||
? require
|
? require
|
||||||
: (isJava && root.load) || noop;
|
: (isJava && root.load) || noop;
|
||||||
|
|
||||||
/** Load ES6 Set and WeakMap shims */
|
|
||||||
load('./asset/set.js');
|
|
||||||
load('./asset/weakmap.js');
|
|
||||||
|
|
||||||
/** The unit testing framework */
|
/** The unit testing framework */
|
||||||
var QUnit = (function() {
|
var QUnit = (function() {
|
||||||
return root.QUnit || (
|
return root.QUnit || (
|
||||||
@@ -132,11 +128,24 @@
|
|||||||
);
|
);
|
||||||
}());
|
}());
|
||||||
|
|
||||||
/** Load and install QUnit Extras */
|
/** Load and install QUnit Extras and ES6 Set/WeakMap shims */
|
||||||
var qe = load('../vendor/qunit-extras/qunit-extras.js');
|
(function() {
|
||||||
if (qe) {
|
var paths = [
|
||||||
qe.runInContext(root);
|
'./asset/set.js',
|
||||||
}
|
'./asset/weakmap.js',
|
||||||
|
'../vendor/qunit-extras/qunit-extras.js'
|
||||||
|
];
|
||||||
|
|
||||||
|
var index = -1,
|
||||||
|
length = paths.length;
|
||||||
|
|
||||||
|
while (++index < length) {
|
||||||
|
var object = load(paths[index]);
|
||||||
|
if (object) {
|
||||||
|
object.runInContext(root);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@@ -613,7 +622,7 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should avoid overwritten native methods', 15, function() {
|
test('should avoid overwritten native methods', 14, function() {
|
||||||
function Foo() {}
|
function Foo() {}
|
||||||
|
|
||||||
function message(lodashMethod, nativeMethod) {
|
function message(lodashMethod, nativeMethod) {
|
||||||
@@ -647,13 +656,6 @@
|
|||||||
ok(actual[0] instanceof Foo, message('_.create', 'Object.create'));
|
ok(actual[0] instanceof Foo, message('_.create', 'Object.create'));
|
||||||
deepEqual(actual[1], {}, message('_.create', 'Object.create'));
|
deepEqual(actual[1], {}, message('_.create', 'Object.create'));
|
||||||
|
|
||||||
try {
|
|
||||||
actual = lodashBizarro.curry(function(a, b) { return [a, b]; })(1)(2);
|
|
||||||
} catch(e) {
|
|
||||||
actual = null;
|
|
||||||
}
|
|
||||||
deepEqual(actual, [1, 2], message('_.curry', 'Object.defineProperty'));
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
actual = [lodashBizarro.isPlainObject({}), lodashBizarro.isPlainObject([])];
|
actual = [lodashBizarro.isPlainObject({}), lodashBizarro.isPlainObject([])];
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
@@ -722,7 +724,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
skipTest(15);
|
skipTest(14);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}());
|
}());
|
||||||
@@ -2210,19 +2212,19 @@
|
|||||||
|
|
||||||
var object = {};
|
var object = {};
|
||||||
|
|
||||||
if ((defineProperty && !WeakMap) && _.support.funcDecomp) {
|
if (lodashBizarro && lodashBizarro.support.funcDecomp) {
|
||||||
_.callback(a, object);
|
lodashBizarro.callback(a, object);
|
||||||
ok(EXPANDO in a);
|
ok(EXPANDO in a);
|
||||||
|
|
||||||
_.callback(b, object);
|
lodashBizarro.callback(b, object);
|
||||||
ok(!(EXPANDO in b));
|
ok(!(EXPANDO in b));
|
||||||
|
|
||||||
if (_.support.funcNames) {
|
if (lodashBizarro.support.funcNames) {
|
||||||
_.support.funcNames = false;
|
lodashBizarro.support.funcNames = false;
|
||||||
_.callback(c, object);
|
lodashBizarro.callback(c, object);
|
||||||
|
|
||||||
ok(EXPANDO in c);
|
ok(EXPANDO in c);
|
||||||
_.support.funcNames = true;
|
lodashBizarro.support.funcNames = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
skipTest();
|
skipTest();
|
||||||
@@ -2236,7 +2238,7 @@
|
|||||||
test('should not write metadata when `_.support.funcDecomp` is `false`', 1, function() {
|
test('should not write metadata when `_.support.funcDecomp` is `false`', 1, function() {
|
||||||
function a() {};
|
function a() {};
|
||||||
|
|
||||||
if ((defineProperty && !WeakMap) && lodashBizarro) {
|
if (lodashBizarro) {
|
||||||
lodashBizarro.callback(a, {});
|
lodashBizarro.callback(a, {});
|
||||||
ok(!(EXPANDO in a));
|
ok(!(EXPANDO in a));
|
||||||
}
|
}
|
||||||
|
|||||||
4
vendor/qunit-extras/qunit-extras.js
vendored
4
vendor/qunit-extras/qunit-extras.js
vendored
@@ -177,10 +177,6 @@
|
|||||||
* @param {Object} context The context object.
|
* @param {Object} context The context object.
|
||||||
*/
|
*/
|
||||||
function runInContext(context) {
|
function runInContext(context) {
|
||||||
// exit early if no `context` is provided or if `QUnit` does not exist
|
|
||||||
if (!context || !context.QUnit) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Used to report the test module for failing tests */
|
/** Used to report the test module for failing tests */
|
||||||
var moduleName,
|
var moduleName,
|
||||||
|
|||||||
Reference in New Issue
Block a user