Permalink
Browse files

Removed checkObjects function

  • Loading branch information...
1 parent fc310a0 commit 1ed169167d67963404104775f2f042d53248a3f1 mde committed Aug 4, 2012
Showing with 30 additions and 101 deletions.
  1. +18 −40 test/object.js
  2. +2 −13 test/string.js
  3. +10 −48 test/uri.js
View
@@ -21,64 +21,42 @@ var object = require('../lib/object')
, tests = {}
, checkObjects;
-// Check if two objects are similar
-checkObjects = function(first, second) {
- var finished = [];
-
- for(var i in first) {
- if((typeof first[i] === 'object') && (typeof second[i] === 'object')) {
- finished.push(checkObjects(first[i], second[i]));
- } else {
- if(first[i] === second[i]) {
- return true;
- } else {
- return false;
- }
- }
- }
-
- if(array.included(false, finished)) {
- return false;
- }
- return true;
-};
-
tests = {
'test merge in object': function() {
- var data = object.merge({user: 'geddy'}, {key: 'key'})
- , actual = {user: 'geddy', key: 'key'};
- assert.equal(checkObjects(data, actual), true);
+ var expected = {user: 'geddy', key: 'key'}
+ , actual = object.merge({user: 'geddy'}, {key: 'key'});
+ assert.deepEqual(expected, actual);
}
, 'test merge with overwriting keys in object': function() {
- var data = object.merge({user: 'geddy', key: 'geddyKey'}, {key: 'key'})
- , actual = {user: 'geddy', key: 'key'};
- assert.equal(checkObjects(data, actual), true);
+ var expected = {user: 'geddy', key: 'key'}
+ , actual = object.merge({user: 'geddy', key: 'geddyKey'}, {key: 'key'});
+ assert.deepEqual(expected, actual);
}
, 'test reverseMerge in object': function() {
- var data = object.reverseMerge({user: 'geddy'}, {key: 'key'})
- , actual = {user: 'geddy', key: 'key'};
- assert.equal(checkObjects(data, actual), true);
+ var expected = {user: 'geddy', key: 'key'}
+ , actual = object.reverseMerge({user: 'geddy'}, {key: 'key'});
+ assert.deepEqual(expected, actual);
}
, 'test reverseMerge with keys overwriting default in object': function() {
- var data = object.reverseMerge({user: 'geddy', key: 'geddyKey'}, {key: 'key'})
- , actual = {user: 'geddy', key: 'geddyKey'};
- assert.equal(checkObjects(data, actual), true);
+ var expected = {user: 'geddy', key: 'geddyKey'}
+ , actual = object.reverseMerge({user: 'geddy', key: 'geddyKey'}, {key: 'key'});
+ assert.deepEqual(expected, actual);
}
, 'test isEmpty with non empty object in object': function() {
- var data = object.isEmpty({user: 'geddy'})
- , actual = false;
- assert.equal(data, actual);
+ var expected = false
+ , actual = object.isEmpty({user: 'geddy'});
+ assert.equal(expected, actual);
}
, 'test isEmpty with empty object in object': function() {
- var data = object.isEmpty({})
- , actual = true;
- assert.equal(data, actual);
+ var expected = true
+ , actual = object.isEmpty({});
+ assert.equal(expected, actual);
}
};
View
@@ -18,18 +18,7 @@
var assert = require('assert')
, string = require('../lib/string')
- , tests
- , checkObjects;
-
-checkObjects = function (expected, actual) {
- var item;
- for (var p in actual) {
- item = actual[p];
- for (var q in item) {
- assert.equal(expected[p][q], item[q]);
- }
- }
-};
+ , tests;
tests = {
@@ -233,7 +222,7 @@ tests = {
},
};
- checkObjects(expected, actual);
+ assert.deepEqual(expected, actual);
}
, 'test inflection with odd name for string': function() {
View
@@ -18,45 +18,7 @@
var uri = require('../lib/uri')
, array = require('../lib/array')
, assert = require('assert')
- , tests = {}
- , checkObjects;
-
-// Check if two objects are similar
-checkObjects = function(first, second) {
- var finished = [];
-
- for(var i in first) {
- if((typeof first[i] === 'object') && (typeof second[i] === 'object')) {
- finished.push(checkObjects(first[i], second[i]));
- } else {
- if(first[i] instanceof Array) {
- var arr = [];
-
- for(var p in first[i]) {
- if(first[i][p] === second[i][p]) {
- arr.push(true)
- } else {
- arr.push(false)
- }
- }
-
- if(array.included(false, finished)) {
- return false;
- }
- return true;
- } else if(first[i] === second[i]) {
- return true;
- } else {
- return false;
- }
- }
- }
-
- if(array.included(false, finished)) {
- return false;
- }
- return true;
-};
+ , tests = {};
tests = {
@@ -115,21 +77,21 @@ tests = {
}
, 'test objectify for uri': function() {
- var data = uri.objectify('name=user')
- , actual = {name: 'user'};
- assert.equal(checkObjects(data, actual), true);
+ var expected = {name: 'user'}
+ , actual = uri.objectify('name=user');
+ assert.deepEqual(expected, actual);
}
, 'test objectify with multiple matching keys for uri': function() {
- var data = uri.objectify('name=user&name=user2')
- , actual = {name: ['user', 'user2']};
- assert.equal(checkObjects(data, actual), true);
+ var expected = {name: ['user', 'user2']}
+ , actual = uri.objectify('name=user&name=user2');
+ assert.deepEqual(expected, actual);
}
, 'test objectify with no conslidation for uri': function() {
- var data = uri.objectify('name=user&name=user2', {conslidate: false})
- , actual = {name: 'user2'};
- assert.equal(checkObjects(data, actual), true);
+ var expected= {name: 'user2'}
+ , actual = uri.objectify('name=user&name=user2', {consolidate: false});
+ assert.deepEqual(expected, actual);
}
};

0 comments on commit 1ed1691

Please sign in to comment.