Skip to content

Commit

Permalink
Factorizo más y mejoro coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoefe committed Nov 14, 2016
1 parent 1c30c9e commit 45cf462
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions lib/discrepances.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,21 @@ function isNotContainerType(classType) {
return ! classType.match(/^(array|object)$/i);
}

function compare(typeOfObjects, keyA, keyB, valA, valB) {
var r={};
r[typeOfObjects] = [keyA,keyB];
if(isNotContainerType(keyA) && isNotContainerType(keyB)) {
r.values = [valA,valB];
}
return r;
}
discrepances = function discrepances(a, b, opts){
opts = changing(defaultOpts, opts||{});
if(a === b){ return null; }
/*eslint-disable eqeqeq */
if(opts.autoTypeCast && a == b){ return null; }
/*eslint-enable eqeqeq */
if(b instanceof DiscrepancesTester){
return b.test(a)?null:{fail: b.message};
}
if(b instanceof DiscrepancesTester){ return b.test(a)?null:{fail: b.message}; }
var typeA = getType(a);
var typeB = getType(b);
if(typeA === typeB) {
Expand All @@ -225,22 +231,14 @@ discrepances = function discrepances(a, b, opts){
var nameA = getName(typeA,a,classA);
var nameB = getName(typeB,b,classB);
if(classA !== classB) {
var r = {classes:[nameA,nameB]};
if(isNotContainerType(classA) && isNotContainerType(classB)) {
r.values=[a,b];
}
return r;
return compare('classes',nameA,nameB,a,b);
} else if(!opts.duckTyping && a.constructor !== b.constructor) {
return {classes:[nameA,nameB]};
} else {
return compareClasses(classA, a, b, opts);
}
} else {
var r2={types:[typeA,typeB]};
if(isNotContainerType(typeA) && isNotContainerType(typeB)) {
r2.values = [a,b];
}
return r2;
return compare('types',typeA,typeB,a,b);
}
};

Expand Down

0 comments on commit 45cf462

Please sign in to comment.