Fixed a few bugs in CPArray and added many new tests for CPArray.

Reviewed by me.
This commit is contained in:
Francisco Ryan Tolmasky I
2011-01-11 10:12:26 -08:00
parent 2f86c0d9d2
commit 29301f440e
5 changed files with 736 additions and 350 deletions
+19 -1
View File
@@ -2,7 +2,8 @@
@import "CPMutableArray.j"
var indexOf = Array.prototype.indexOf,
var concat = Array.prototype.concat,
indexOf = Array.prototype.indexOf,
join = Array.prototype.join,
pop = Array.prototype.pop,
push = Array.prototype.push,
@@ -172,6 +173,23 @@ var indexOf = Array.prototype.indexOf,
objj_msgSend(self[index], aSelector);
}
- (CPArray)arrayByAddingObject:(id)anObject
{
// concat flattens arrays, so wrap it in an *additional* array if anObject is an array itself.
if ([anObject isKindOfClass:CPArray])
return concat.call(self, [anObject]);
return concat.call(self, anObject);
}
- (CPArray)arrayByAddingObjectsFromArray:(CPArray)anArray
{
if (!anArray)
return [self copy];
return concat.call(self, anArray.isa === _CPJavaScriptArray ? anArray : [anArray _javaScriptArrayCopy]);
}
- (CPArray)subarrayWithRange:(CPRange)aRange
{
if (aRange.location < 0 || CPMaxRange(aRange) > self.length)