Skip to content

Commit

Permalink
Revert "remove 'fasley' edge case tests"
Browse files Browse the repository at this point in the history
This reverts commit ef3164f.
  • Loading branch information
jridgewell committed Feb 20, 2015
1 parent 07d92c9 commit cd725e1
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion test/objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@
deepEqual(_.keys(1), []);
deepEqual(_.keys('a'), []);
deepEqual(_.keys(true), []);

// keys that may be missed if the implementation isn't careful
var trouble = {
'constructor': Object,
'valueOf': _.noop,
'hasOwnProperty': null,
'toString': 5,
'toLocaleString': undefined,
'propertyIsEnumerable': /a/,
'isPrototypeOf': this,
'__defineGetter__': Boolean,
'__defineSetter__': {},
'__lookupSetter__': false,
'__lookupGetter__': []
};
var troubleKeys = ['constructor', 'valueOf', 'hasOwnProperty', 'toString', 'toLocaleString', 'propertyIsEnumerable',
'isPrototypeOf', '__defineGetter__', '__defineSetter__', '__lookupSetter__', '__lookupGetter__'].sort();
deepEqual(_.keys(trouble).sort(), troubleKeys, 'matches non-enumerable properties');
});

test('allKeys', function() {
Expand All @@ -30,11 +48,25 @@
deepEqual(_.allKeys(val), []);
});

// allKeys that may be missed if the implementation isn't careful
var trouble = {
constructor: Object,
valueOf: _.noop,
hasOwnProperty: null,
toString: 5,
toLocaleString: undefined,
propertyIsEnumerable: /a/,
isPrototypeOf: this
};
var troubleKeys = ['constructor', 'valueOf', 'hasOwnProperty', 'toString', 'toLocaleString', 'propertyIsEnumerable',
'isPrototypeOf'].sort();
deepEqual(_.allKeys(trouble).sort(), troubleKeys, 'matches non-enumerable properties');

function A() {}
A.prototype.foo = 'foo';
var b = new A();
b.bar = 'bar';
deepEqual(_.allKeys(b).sort(), ['bar', 'foo'], 'should include inherited keys');
deepEqual(_.allKeys(b), ['bar', 'foo'], 'should include inherited keys');

function y() {}
y.x = 'z';
Expand Down Expand Up @@ -511,6 +543,10 @@
var args = function(){ return arguments; };
ok(_.isEmpty(args()), 'empty arguments object is empty');
ok(!_.isEmpty(args('')), 'non-empty arguments object is not empty');

// covers collecting non-enumerable properties in IE < 9
var nonEnumProp = {'toString': 5};
ok(!_.isEmpty(nonEnumProp), 'non-enumerable property is not empty');
});

if (typeof document === 'object') {
Expand Down Expand Up @@ -736,6 +772,10 @@

Prototest.x = 5;
ok(_.isMatch({x: 5, y: 1}, Prototest), 'spec can be a function');

//null edge cases
var oCon = {'constructor': Object};
deepEqual(_.map([null, undefined, 5, {}], _.partial(_.isMatch, _, oCon)), [false, false, false, true], 'doesnt fasley match constructor on undefined/null');
});

test('matcher', function() {
Expand Down Expand Up @@ -788,6 +828,11 @@
o.b = 2;
o.a = 1;
equal(m({'b': 1}), true, 'changing spec object doesnt change matches result');


//null edge cases
var oCon = _.matcher({'constructor': Object});
deepEqual(_.map([null, undefined, 5, {}], oCon), [false, false, false, true], 'doesnt fasley match constructor on undefined/null');
});

test('matcher', function() {
Expand Down Expand Up @@ -840,6 +885,11 @@
o.b = 2;
o.a = 1;
equal(m({'b': 1}), true, 'changing spec object doesnt change matches result');


//null edge cases
var oCon = _.matcher({'constructor': Object});
deepEqual(_.map([null, undefined, 5, {}], oCon), [false, false, false, true], 'doesnt fasley match constructor on undefined/null');
});

test('findKey', function() {
Expand Down

0 comments on commit cd725e1

Please sign in to comment.