Objective-J Test API 0.1.0
|
00001 var assert = require("assert"); 00002 00003 @implementation CPArray(DeepEqual) 00004 00005 - (BOOL)deepEqual:(id)anArray 00006 { 00007 if (self === anArray) 00008 return YES; 00009 00010 if (length != anArray.length) 00011 return NO; 00012 00013 var index = 0, 00014 count = [self count]; 00015 00016 for(; index < count; ++index) 00017 { 00018 var lhs = self[index], 00019 rhs = anArray[index]; 00020 00021 // If both objects are objective-j objects 00022 if (lhs && lhs.isa && rhs && rhs.isa) 00023 { 00024 if ([lhs respondsToSelector:@selector(deepEqual:)]) 00025 { 00026 if (![lhs deepEqual:rhs]) 00027 return NO; 00028 } 00029 else if (![lhs isEqual:rhs]) 00030 return NO; 00031 } 00032 00033 // If only one of the objects is an objective-j object 00034 else if ((lhs && lhs.isa && (!rhs || !rhs.isa) || 00035 rhs && rhs.isa && (!lhs || !lhs.isa))) 00036 return NO; 00037 00038 // Both are pure JS objects 00039 else if (!deepEqual(self[index], anArray[index])) 00040 return NO; 00041 } 00042 00043 return YES; 00044 } 00045 00046 @end 00047 00048 var deepEqual = function(obj1, obj2) 00049 { 00050 var isEqual; 00051 assert.pass = function() { 00052 isEqual = true; 00053 } 00054 assert.fail = function() { 00055 isEqual = false; 00056 } 00057 assert.deepEqual(obj1, obj2); 00058 return isEqual; 00059 }