mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-14 02:33:50 +00:00
Merge branch 'master' of github.com:280north/cappuccino
This commit is contained in:
commit
28e660c295
16 files changed
+1171
-403
No files matched your search
@@ -85,6 +85,8 @@ var CPTabViewDidSelectTabViewItemSelector = 1,
|
||||
|
||||
[self _updateItems];
|
||||
[self _repositionTabs];
|
||||
|
||||
[aTabViewItem _setTabView:self];
|
||||
|
||||
if (_delegateSelectors & CPTabViewDidChangeNumberOfTabViewItemsSelector)
|
||||
[_delegate tabViewDidChangeNumberOfTabViewItems:self];
|
||||
@@ -108,6 +110,8 @@ var CPTabViewDidSelectTabViewItemSelector = 1,
|
||||
|
||||
[self _updateItems];
|
||||
[self _repositionTabs];
|
||||
|
||||
[aTabViewItem _setTabView:nil];
|
||||
|
||||
if (_delegateSelectors & CPTabViewDidChangeNumberOfTabViewItemsSelector)
|
||||
[_delegate tabViewDidChangeNumberOfTabViewItems:self];
|
||||
|
||||
@@ -449,14 +449,13 @@ var themedButtonValues = nil,
|
||||
[@"text-shadow-color", [CPColor colorWithCalibratedWhite:240.0 / 255.0 alpha:1.0], CPThemeStateBordered | CPThemeStateDisabled],
|
||||
[@"text-shadow-offset", CGSizeMake(0.0, 1.0), CPThemeStateBordered],
|
||||
[@"line-break-mode", CPLineBreakByTruncatingTail],
|
||||
[@"content-inset", CGInsetMake(0.0, 7.0, 0.0, 7.0), CPThemeStateBordered],
|
||||
[@"bezel-color", bezelColor, CPThemeStateBordered],
|
||||
[@"bezel-color", highlightedBezelColor, CPThemeStateBordered | CPThemeStateHighlighted],
|
||||
[@"bezel-color", disabledBezelColor, CPThemeStateBordered | CPThemeStateDisabled],
|
||||
[@"bezel-color", defaultBezelColor, CPThemeStateBordered | CPThemeStateDefault],
|
||||
[@"bezel-color", defaultHighlightedBezelColor, CPThemeStateBordered | CPThemeStateHighlighted | CPThemeStateDefault],
|
||||
[@"bezel-color", defaultDisabledBezelColor, CPThemeStateBordered | CPThemeStateDefault | CPThemeStateDisabled],
|
||||
[@"content-inset", CGInsetMake(0.0, 5.0, 0.0, 5.0), CPThemeStateBordered],
|
||||
[@"content-inset", CGInsetMake(0.0, 7.0, 0.0, 7.0), CPThemeStateBordered],
|
||||
|
||||
[@"bezel-color", roundedBezelColor, CPThemeStateBordered | CPButtonStateBezelStyleRounded],
|
||||
[@"bezel-color", roundedHighlightedBezelColor, CPThemeStateBordered | CPThemeStateHighlighted | CPButtonStateBezelStyleRounded],
|
||||
@@ -464,7 +463,7 @@ var themedButtonValues = nil,
|
||||
[@"bezel-color", defaultRoundedBezelColor, CPThemeStateBordered | CPThemeStateDefault | CPButtonStateBezelStyleRounded],
|
||||
[@"bezel-color", defaultRoundedHighlightedBezelColor, CPThemeStateBordered | CPThemeStateHighlighted | CPThemeStateDefault | CPButtonStateBezelStyleRounded],
|
||||
[@"bezel-color", defaultRoundedDisabledBezelColor, CPThemeStateBordered | CPThemeStateDefault | CPThemeStateDisabled | CPButtonStateBezelStyleRounded],
|
||||
[@"content-inset", CGInsetMake(0.0, 10.0, 0.0, 10.0), CPThemeStateBordered],
|
||||
[@"content-inset", CGInsetMake(0.0, 10.0, 0.0, 10.0), CPThemeStateBordered | CPButtonStateBezelStyleRounded],
|
||||
|
||||
[@"text-color", [CPColor colorWithCalibratedWhite:0.6 alpha:1.0], CPThemeStateDisabled],
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ ObjectiveJRuntimeAnalyzer.prototype.initializeGlobalRecorder = function()
|
||||
|
||||
if (before && currentFile) {
|
||||
self.files[currentFile] = self.files[currentFile] || {};
|
||||
self.files[currentFile].globals = self.files[currentFile].global || {};
|
||||
self.files[currentFile].globals = self.files[currentFile].globals || {};
|
||||
|
||||
diff({
|
||||
before : before,
|
||||
|
||||
@@ -35,6 +35,9 @@ CPBinarySearchingFirstEqual = 1 << 8;
|
||||
CPBinarySearchingLastEqual = 1 << 9;
|
||||
CPBinarySearchingInsertionIndex = 1 << 10;
|
||||
|
||||
var concat = Array.prototype.concat,
|
||||
join = Array.prototype.join,
|
||||
push = Array.prototype.push;
|
||||
|
||||
#define FORWARD_TO_CONCRETE_CLASS()\
|
||||
if (self === _CPSharedPlaceholderArray)\
|
||||
@@ -182,6 +185,11 @@ CPBinarySearchingInsertionIndex = 1 << 10;
|
||||
return [self indexOfObject:anObject] !== CPNotFound;
|
||||
}
|
||||
|
||||
- (BOOL)containsObjectIdenticalTo:(id)anObject
|
||||
{
|
||||
return [self indexOfObjectIdenticalTo:anObject] !== CPNotFound;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the number of elements in the array
|
||||
*/
|
||||
@@ -573,6 +581,18 @@ CPBinarySearchingInsertionIndex = 1 << 10;
|
||||
return (self === anObject) || [self isEqualToArray:anObject];
|
||||
}
|
||||
|
||||
- (Array)_javaScriptArrayCopy
|
||||
{
|
||||
var index = 0,
|
||||
count = [self count],
|
||||
copy = [];
|
||||
|
||||
for (; index < count; ++index)
|
||||
push.call(copy, [self objectAtIndex:index]);
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
// Deriving new arrays
|
||||
/*!
|
||||
Returns a copy of this array plus \c anObject inside the copy.
|
||||
@@ -582,7 +602,13 @@ CPBinarySearchingInsertionIndex = 1 << 10;
|
||||
*/
|
||||
- (CPArray)arrayByAddingObject:(id)anObject
|
||||
{
|
||||
return self.concat(anObject);
|
||||
var argumentArray = [self _javaScriptArrayCopy];
|
||||
|
||||
// We push instead of concat,because concat flattens arrays, so if the object
|
||||
// passed in is an array, we end up with its contents added instead of itself.
|
||||
push.call(argumentArray, anObject);
|
||||
|
||||
return objj_msgSend([self class], @selector(arrayWithArray:), argumentArray);
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -591,7 +617,13 @@ CPBinarySearchingInsertionIndex = 1 << 10;
|
||||
*/
|
||||
- (CPArray)arrayByAddingObjectsFromArray:(CPArray)anArray
|
||||
{
|
||||
return self.concat(anArray);
|
||||
if (!anArray)
|
||||
return [self copy];
|
||||
|
||||
var anArray = anArray.isa === _CPJavaScriptArray ? anArray : [anArray _javaScriptArrayCopy],
|
||||
argumentArray = concat.call([self _javaScriptArrayCopy], anArray);
|
||||
|
||||
return objj_msgSend([self class], @selector(arrayWithArray:), argumentArray);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -616,7 +648,20 @@ CPBinarySearchingInsertionIndex = 1 << 10;
|
||||
*/
|
||||
- (CPArray)subarrayWithRange:(CPRange)aRange
|
||||
{
|
||||
_CPRaiseInvalidAbstractInvocation(self, _cmd);
|
||||
if (!aRange)
|
||||
return [self copy];
|
||||
|
||||
if (aRange.location < 0 || CPMaxRange(aRange) > self.length)
|
||||
[CPException raise:CPRangeException reason:"subarrayWithRange: aRange out of bounds"];
|
||||
|
||||
var index = aRange.location,
|
||||
count = CPMaxRange(aRange),
|
||||
argumentArray = [];
|
||||
|
||||
for (; index < count; ++index)
|
||||
push.call(argumentArray, [self objectAtIndex:index]);
|
||||
|
||||
return objj_msgSend([self class], @selector(arrayWithArray:), argumentArray);
|
||||
}
|
||||
|
||||
// Sorting arrays
|
||||
@@ -682,19 +727,7 @@ CPBinarySearchingInsertionIndex = 1 << 10;
|
||||
*/
|
||||
- (CPString)componentsJoinedByString:(CPString)aString
|
||||
{
|
||||
var index = 0,
|
||||
count = [self count],
|
||||
components = [];
|
||||
|
||||
for (; index < count; ++index)
|
||||
{
|
||||
components.push([self objectAtIndex:index]);
|
||||
|
||||
if (index < count - 1)
|
||||
components.push(aString);
|
||||
}
|
||||
|
||||
return components.join("");
|
||||
return join.call([self _javaScriptArrayCopy], aString);
|
||||
}
|
||||
|
||||
// Creating a description of the array
|
||||
|
||||
@@ -50,7 +50,11 @@
|
||||
*/
|
||||
- (void)addObjectsFromArray:(CPArray)anArray
|
||||
{
|
||||
splice.apply(self, [length, 0].concat(anArray));
|
||||
var index = 0,
|
||||
count = [anArray count];
|
||||
|
||||
for (; index < count; ++index)
|
||||
[self addObject:[anArray objectAtIndex:index]];
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -85,7 +89,7 @@
|
||||
currentIndex = [indexes firstIndex];
|
||||
|
||||
for (; index < objectsCount; ++index, currentIndex = [indexes indexGreaterThanIndex:currentIndex])
|
||||
[self insertObject:objects[index] atIndex:currentIndex];
|
||||
[self insertObject:[objects objectAtIndex:index] atIndex:currentIndex];
|
||||
}
|
||||
|
||||
- (unsigned)insertObject:(id)anObject inArraySortedByDescriptors:(CPArray)descriptors
|
||||
@@ -137,7 +141,7 @@
|
||||
var i = 0,
|
||||
index = [anIndexSet firstIndex];
|
||||
|
||||
while (index != CPNotFound)
|
||||
while (index !== CPNotFound)
|
||||
{
|
||||
[self replaceObjectAtIndex:index withObject:objects[i++]];
|
||||
index = [anIndexSet indexGreaterThanIndex:index];
|
||||
@@ -154,10 +158,14 @@
|
||||
*/
|
||||
- (void)replaceObjectsInRange:(CPRange)aRange withObjectsFromArray:(CPArray)anArray range:(CPRange)otherRange
|
||||
{
|
||||
if (!otherRange.location && otherRange.length == [anArray count])
|
||||
[self replaceObjectsInRange:aRange withObjectsFromArray:anArray];
|
||||
else
|
||||
splice.apply(self, [aRange.location, aRange.length].concat([anArray subarrayWithRange:otherRange]));
|
||||
[self removeObjectsInRange:aRange];
|
||||
|
||||
if (otherRange && (otherRange.location !== 0 || otherRange.length !== [anArray count]))
|
||||
anArray = [anArray subarrayWithRange:otherRange];
|
||||
|
||||
var indexes = [CPIndexSet indexSetWithIndexesInRange:CPMakeRange(aRange.location, [anArray count])];
|
||||
|
||||
[self insertObjects:anArray atIndexes:indexes];
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -169,7 +177,7 @@
|
||||
*/
|
||||
- (void)replaceObjectsInRange:(CPRange)aRange withObjectsFromArray:(CPArray)anArray
|
||||
{
|
||||
splice.apply(self, [aRange.location, aRange.length].concat(anArray));
|
||||
[self replaceObjectsInRange:aRange withObjectsFromArray:anArray range:nil];
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -178,10 +186,11 @@
|
||||
*/
|
||||
- (void)setArray:(CPArray)anArray
|
||||
{
|
||||
if (self == anArray)
|
||||
if (self === anArray)
|
||||
return;
|
||||
|
||||
splice.apply(self, [0, length].concat(anArray));
|
||||
[self removeAllObjects];
|
||||
[self addObjectsFromArray:anArray];
|
||||
}
|
||||
|
||||
// Removing Objects
|
||||
@@ -190,7 +199,8 @@
|
||||
*/
|
||||
- (void)removeAllObjects
|
||||
{
|
||||
splice(0, length);
|
||||
while ([self count])
|
||||
[self removeLastObject];
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -243,7 +253,7 @@
|
||||
{
|
||||
var index = [anIndexSet lastIndex];
|
||||
|
||||
while (index != CPNotFound)
|
||||
while (index !== CPNotFound)
|
||||
{
|
||||
[self removeObjectAtIndex:index];
|
||||
index = [anIndexSet indexLessThanIndex:index];
|
||||
@@ -289,7 +299,7 @@
|
||||
count = [anArray count];
|
||||
|
||||
for (; index < count; ++index)
|
||||
[self removeObject:anArray[index]];
|
||||
[self removeObject:[anArray objectAtIndex:index]];
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -298,7 +308,11 @@
|
||||
*/
|
||||
- (void)removeObjectsInRange:(CPRange)aRange
|
||||
{
|
||||
splice(aRange.location, aRange.length);
|
||||
var index = aRange.location,
|
||||
count = CPMaxRange(aRange);
|
||||
|
||||
while (count-- > index)
|
||||
[self removeObjectAtIndex:index];
|
||||
}
|
||||
|
||||
// Rearranging objects
|
||||
@@ -309,9 +323,13 @@
|
||||
*/
|
||||
- (void)exchangeObjectAtIndex:(unsigned)anIndex withObjectAtIndex:(unsigned)otherIndex
|
||||
{
|
||||
var temporary = self[anIndex];
|
||||
self[anIndex] = self[otherIndex];
|
||||
self[otherIndex] = temporary;
|
||||
if (anIndex === otherIndex)
|
||||
return;
|
||||
|
||||
var temporary = [self objectAtIndex:anIndex];
|
||||
|
||||
[self replaceObjectAtIndex:anIndex withObject:[self objectAtIndex:otherIndex]];
|
||||
[self replaceObjectAtIndex:otherIndex withObject:temporary];
|
||||
}
|
||||
|
||||
- (CPArray)sortUsingDescriptors:(CPArray)descriptors
|
||||
|
||||
@@ -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,
|
||||
@@ -35,12 +36,12 @@ var indexOf = Array.prototype.indexOf,
|
||||
|
||||
- (id)initWithArray:(CPArray)anArray
|
||||
{
|
||||
return slice.call(anArray, 0);
|
||||
return [self initWithArray:anArray copyItems:NO];
|
||||
}
|
||||
|
||||
- (id)initWithArray:(CPArray)anArray copyItems:(BOOL)shouldCopyItems
|
||||
{
|
||||
if (!shouldCopyItems)
|
||||
if (!shouldCopyItems && anArray.isa === _CPJavaScriptArray)
|
||||
return slice.call(anArray, 0);
|
||||
|
||||
self = [super init];
|
||||
@@ -49,13 +50,14 @@ var indexOf = Array.prototype.indexOf,
|
||||
|
||||
if (anArray.isa === _CPJavaScriptArray)
|
||||
{
|
||||
// If we're this far, shouldCopyItems must be YES.
|
||||
var count = anArray.length;
|
||||
|
||||
for (; index < count; ++index)
|
||||
{
|
||||
var object = anArray[index];
|
||||
|
||||
self[index] = object.isa ? [object copy] : object;
|
||||
self[index] = (object && object.isa) ? [object copy] : object;
|
||||
}
|
||||
|
||||
return self;
|
||||
@@ -67,7 +69,7 @@ var indexOf = Array.prototype.indexOf,
|
||||
{
|
||||
var object = [anArray objectAtIndex:index];
|
||||
|
||||
self[index] = object.isa ? [object copy] : object;
|
||||
self[index] = (shouldCopyItems && object && object.isa) ? [object copy] : object;
|
||||
}
|
||||
|
||||
return self;
|
||||
@@ -171,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)
|
||||
@@ -199,16 +218,56 @@ var indexOf = Array.prototype.indexOf,
|
||||
push.call(self, anObject);
|
||||
}
|
||||
|
||||
- (void)removeAllObjects
|
||||
{
|
||||
splice.call(self, 0, self.length);
|
||||
}
|
||||
|
||||
- (void)removeLastObject
|
||||
{
|
||||
pop.call(self);
|
||||
}
|
||||
|
||||
- (void)removeObjectsInRange:(CPRange)aRange
|
||||
{
|
||||
splice.call(self, aRange.location, aRange.length);
|
||||
}
|
||||
|
||||
- (void)replaceObjectAtIndex:(int)anIndex withObject:(id)anObject
|
||||
{
|
||||
self[anIndex] = anObject;
|
||||
}
|
||||
|
||||
- (void)replaceObjectsInRange:(CPRange)aRange withObjectsFromArray:(CPArray)anArray range:(CPRange)otherRange
|
||||
{
|
||||
if (otherRange && (otherRange.location !== 0 || otherRange.length !== [anArray count]))
|
||||
anArray = [anArray subarrayWithRange:otherRange];
|
||||
|
||||
if (anArray.isa !== _CPJavaScriptArray)
|
||||
anArray = [anArray _javaScriptArrayCopy];
|
||||
|
||||
splice.apply(self, [aRange.location, aRange.length].concat(anArray));
|
||||
}
|
||||
|
||||
- (void)setArray:(CPArray)anArray
|
||||
{
|
||||
if (anArray.isa === _CPJavaScriptArray)
|
||||
splice.apply(self, [0, self.length].concat(anArray));
|
||||
|
||||
else
|
||||
[super setArray:anArray];
|
||||
}
|
||||
|
||||
- (void)addObjectsFromArray:(CPArray)anArray
|
||||
{
|
||||
if (anArray.isa === _CPJavaScriptArray)
|
||||
splice.apply(self, [self.length, 0].concat(anArray));
|
||||
|
||||
else
|
||||
[super addObjectsFromArray:anArray];
|
||||
}
|
||||
|
||||
|
||||
- (void)copy
|
||||
{
|
||||
return slice.call(self, 0);
|
||||
|
||||
@@ -345,6 +345,12 @@ var CPObjectAccessorsForClassKey = @"$CPObjectAccessorsForClassKey",
|
||||
return [CPArray class];
|
||||
}
|
||||
|
||||
- (id)copy
|
||||
{
|
||||
// We do this to ensure we return a CPArray.
|
||||
return [CPArray arrayWithArray:self];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation _CPKeyValueCodingSet : CPSet
|
||||
@@ -400,6 +406,11 @@ var CPObjectAccessorsForClassKey = @"$CPObjectAccessorsForClassKey",
|
||||
return [CPSet class];
|
||||
}
|
||||
|
||||
- (id)copy
|
||||
{
|
||||
// We do this to ensure we return a CPSet.
|
||||
return [CPSet setWithSet:self];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -383,7 +383,7 @@
|
||||
|
||||
- (id)copy
|
||||
{
|
||||
return [[CPSet alloc] initWithSet:self];
|
||||
return [[self class] setWithSet:self];
|
||||
}
|
||||
|
||||
- (id)mutableCopy
|
||||
|
||||
@@ -42,10 +42,12 @@ exports.sprintf = function(format)
|
||||
}
|
||||
index += t.length;
|
||||
|
||||
if (t.charAt(0) != "%")
|
||||
{
|
||||
if (t.charAt(0) !== "%")
|
||||
result += t;
|
||||
}
|
||||
|
||||
else if (t === "%%")
|
||||
result += "%";
|
||||
|
||||
else
|
||||
{
|
||||
var subtokens = t.match(tagRegex);
|
||||
|
||||
@@ -102,4 +102,34 @@
|
||||
[self assertTrue:wasClicked];
|
||||
}
|
||||
|
||||
- (void)testSetObjectValue
|
||||
{
|
||||
[button setObjectValue:CPOnState];
|
||||
[self assert:CPOnState equals:[button objectValue] message:@"object value should be CPOnState"];
|
||||
[self assert:CPOnState equals:[button state] message:@"state should be CPOnState"];
|
||||
|
||||
// YES !== CPOnState, we used to fail on this
|
||||
[button setObjectValue:YES];
|
||||
[self assert:CPOnState equals:[button objectValue] message:@"YES should be translated to CPOnState"];
|
||||
[self assert:CPOnState equals:[button state] message:@"YES should be translated CPOnState"];
|
||||
|
||||
[button setObjectValue:NO];
|
||||
[self assert:CPOffState equals:[button objectValue] message:@"NO should be translated to CPOffState"];
|
||||
[self assert:CPOffState equals:[button state] message:@"NO should be translated to CPOffState"];
|
||||
|
||||
[button setObjectValue:CPOffState];
|
||||
[self assert:CPOffState equals:[button objectValue] message:@"object value should be CPOffState"];
|
||||
[self assert:CPOffState equals:[button state] message:@"state should be CPOnState"];
|
||||
|
||||
[button setAllowsMixedState:NO];
|
||||
[button setObjectValue:CPMixedState];
|
||||
[self assert:CPOnState equals:[button objectValue] message:@"Mixed state is not allowed, object value should be CPOnState"];
|
||||
[self assert:CPOnState equals:[button state] message:@"Mixed state is not allowed, state should be CPOnState"];
|
||||
|
||||
[button setAllowsMixedState:YES];
|
||||
[button setObjectValue:CPMixedState];
|
||||
[self assert:CPMixedState equals:[button objectValue] message:@"Mixed state is allowed, object value should be CPMixedState"];
|
||||
[self assert:CPMixedState equals:[button state] message:@"Mixed state is allowed, state should be CPMixedState"];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -76,5 +76,15 @@
|
||||
[self assert:[box frameSize].height equals:800 - [tabs frameSize].height / 2];
|
||||
}
|
||||
|
||||
- (void)testTabViewGetsSetOnViewItem
|
||||
{
|
||||
[self assert:[_tabItem1 tabView] equals:_tabView];
|
||||
}
|
||||
|
||||
- (void)testTabViewGetsRemoveOnViewItem
|
||||
{
|
||||
[_tabView removeTabViewItem:_tabItem1];
|
||||
[self assertNull:[_tabItem1 tabView]];
|
||||
}
|
||||
|
||||
@end
|
||||
+366
-333
@@ -1,150 +1,247 @@
|
||||
|
||||
@import <Foundation/Foundation.j>
|
||||
|
||||
|
||||
@implementation CPArrayTest : OJTestCase
|
||||
|
||||
- (void)testComponentsJoinedByString
|
||||
{
|
||||
var testStrings = [
|
||||
[[], "", ""],
|
||||
[[], "-", ""],
|
||||
[[1,2], "-", "1-2"],
|
||||
[[1,2,3], "-", "1-2-3"],
|
||||
[["123", 456], "-", "123-456"]
|
||||
];
|
||||
|
||||
for (var i = 0; i < testStrings.length; i++)
|
||||
[self assert:[testStrings[i][0] componentsJoinedByString:testStrings[i][1]] equals:testStrings[i][2]];
|
||||
}
|
||||
|
||||
- (void)testsInsertObjectsAtIndexes
|
||||
+ (Class)arrayClass
|
||||
{
|
||||
var array = [CPMutableArray arrayWithObjects:@"one", @"two", @"three", @"four"],
|
||||
newAdditions = [CPArray arrayWithObjects:@"a", @"b"],
|
||||
indexes = [CPMutableIndexSet indexSetWithIndex:1];
|
||||
return ConcreteArray;
|
||||
}
|
||||
|
||||
[indexes addIndex:3];
|
||||
- (void)test_containsObject_
|
||||
{
|
||||
var arrayClass = [[self class] arrayClass],
|
||||
array = [arrayClass arrayWithObjects:0, @"hello", [AlwaysEqual new], [arrayClass arrayWithObjects:0]];
|
||||
|
||||
[array insertObjects:newAdditions atIndexes:indexes];
|
||||
[self assertTrue:[array containsObject:0]];
|
||||
[self assertTrue:[array containsObject:@"hello"]];
|
||||
[self assertTrue:[array containsObject:[AlwaysEqual new]]]; // test isEqual:
|
||||
[self assertTrue:[array containsObject:[arrayClass arrayWithObjects:0]]];
|
||||
|
||||
[self assert:array equals:[@"one", @"a", @"two", @"b", @"three", @"four"]];
|
||||
[self assertFalse:[array containsObject:1]];
|
||||
[self assertFalse:[array containsObject:@"bye"]];
|
||||
[self assertFalse:[array containsObject:[arrayClass arrayWithObjects:1]]];
|
||||
}
|
||||
|
||||
var array = [CPMutableArray arrayWithObjects:@"one", @"two", @"three", @"four"],
|
||||
newAdditions = [CPArray arrayWithObjects:@"a", @"b"],
|
||||
indexes = [CPMutableIndexSet indexSetWithIndex:5];
|
||||
- (void)test_containsObjectIdenticalTo_
|
||||
{
|
||||
var arrayClass = [[self class] arrayClass],
|
||||
array = [arrayClass arrayWithObjects:0, @"hello", [AlwaysEqual new], [arrayClass arrayWithObjects:0]];
|
||||
|
||||
[indexes addIndex:4];
|
||||
[self assertTrue:[array containsObjectIdenticalTo:0]];
|
||||
[self assertTrue:[array containsObjectIdenticalTo:@"hello"]];
|
||||
|
||||
[array insertObjects:newAdditions atIndexes:indexes];
|
||||
[self assertFalse:[array containsObjectIdenticalTo:1]];
|
||||
[self assertFalse:[array containsObjectIdenticalTo:@"bye"]];
|
||||
[self assertFalse:[array containsObjectIdenticalTo:[AlwaysEqual new]]];
|
||||
[self assertFalse:[array containsObjectIdenticalTo:[arrayClass arrayWithObjects:0]]];
|
||||
[self assertFalse:[array containsObjectIdenticalTo:[arrayClass arrayWithObjects:1]]];
|
||||
}
|
||||
|
||||
[self assert:array equals:[@"one", @"two", @"three", @"four", @"a", @"b"]];
|
||||
- (void)test_count
|
||||
{
|
||||
var arrayClass = [[self class] arrayClass];
|
||||
|
||||
var array = [CPMutableArray arrayWithObjects:@"one", @"two", @"three", @"four"],
|
||||
newAdditions = [CPArray arrayWithObjects:@"a", @"b", @"c"],
|
||||
indexes = [CPMutableIndexSet indexSetWithIndex:1];
|
||||
[self assert:[[arrayClass array] count] same:0];
|
||||
[self assert:[[arrayClass arrayWithObjects:0, 1, 2] count] same:3];
|
||||
[self assert:[[arrayClass arrayWithObjects:0, 1, 2, nil] count] same:3];
|
||||
[self assert:[[arrayClass arrayWithObjects:0, 1, nil, 2, nil] count] same:2];
|
||||
}
|
||||
|
||||
[indexes addIndex:2];
|
||||
[indexes addIndex:4];
|
||||
- (void)test_lastObject
|
||||
{
|
||||
var arrayClass = [[self class] arrayClass];
|
||||
|
||||
[array insertObjects:newAdditions atIndexes:indexes];
|
||||
[self assert:[[arrayClass array] lastObject] same:nil];
|
||||
[self assert:[[arrayClass arrayWithObjects:0, 1, 2] lastObject] same:2];
|
||||
[self assert:[[arrayClass arrayWithObjects:0, 1, 2, nil] lastObject] same:2];
|
||||
[self assert:[[arrayClass arrayWithObjects:0, 1, nil, 2, nil] lastObject] same:1];
|
||||
}
|
||||
|
||||
[self assert:array equals:[@"one", @"a", @"b", @"two", @"c", @"three", @"four"]];
|
||||
- (void)test_objectAtIndex_
|
||||
{
|
||||
var arrayClass = [[self class] arrayClass],
|
||||
array = [arrayClass array];
|
||||
|
||||
[self assertThrows:function () { [array objectAtIndex:-1] }];
|
||||
[self assertThrows:function () { [array objectAtIndex:0] }];
|
||||
|
||||
var array = [CPMutableArray arrayWithObjects:@"one", @"two", @"three", @"four"],
|
||||
newAdditions = [CPArray arrayWithObjects:@"a", @"b", @"c"],
|
||||
indexes = [CPMutableIndexSet indexSetWithIndex:1];
|
||||
var array = [arrayClass arrayWithObjects:0, 1, 2];
|
||||
|
||||
[indexes addIndex:2];
|
||||
[indexes addIndex:6];
|
||||
[self assertThrows:function () { [array objectAtIndex:-1] }];
|
||||
[self assert:[array objectAtIndex:0] same:0];
|
||||
[self assert:[array objectAtIndex:1] same:1];
|
||||
[self assert:[array objectAtIndex:2] same:2];
|
||||
[self assertThrows:function () { [array objectAtIndex:3] }];
|
||||
}
|
||||
|
||||
[array insertObjects:newAdditions atIndexes:indexes];
|
||||
|
||||
[self assert:array equals:[@"one", @"a", @"b", @"two", @"three", @"four", @"c"]];
|
||||
|
||||
|
||||
var array = [CPMutableArray arrayWithObjects:@"one", @"two", @"three", @"four"],
|
||||
newAdditions = [CPArray arrayWithObjects:@"a", @"b"],
|
||||
indexes = [CPMutableIndexSet indexSetWithIndex:5];
|
||||
|
||||
[indexes addIndex:6];
|
||||
|
||||
try
|
||||
- (void)test_objectsAtIndexes_
|
||||
{
|
||||
function rangeIndexes(location, length)
|
||||
{
|
||||
[array insertObjects:newAdditions atIndexes:indexes];
|
||||
[self fail];
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
if ((e.isa) && [e name] == AssertionFailedError)
|
||||
throw e;
|
||||
return [CPIndexSet indexSetWithIndexesInRange:CPMakeRange(location, length)];
|
||||
}
|
||||
|
||||
var arrayClass = [[self class] arrayClass],
|
||||
array = [arrayClass array];
|
||||
|
||||
[self assertThrows:function () { [array objectsAtIndexes:rangeIndexes(0, 1)] }];
|
||||
|
||||
var array = [arrayClass arrayWithObjects:0, 1, 2];
|
||||
|
||||
[self assert:[array objectsAtIndexes:rangeIndexes(0, 1)] equals:[0]];
|
||||
[self assert:[array objectsAtIndexes:rangeIndexes(0, 2)] equals:[0, 1]];
|
||||
[self assert:[array objectsAtIndexes:rangeIndexes(0, 3)] equals:[0, 1, 2]];
|
||||
[self assertThrows:function () { [array objectsAtIndexes:rangeIndexes(0, 4)] }];
|
||||
[self assert:[array objectsAtIndexes:rangeIndexes(1, 1)] equals:[1]];
|
||||
[self assert:[array objectsAtIndexes:rangeIndexes(1, 2)] equals:[1, 2]];
|
||||
[self assertThrows:function () { [array objectsAtIndexes:rangeIndexes(1, 3)] }];
|
||||
[self assertThrows:function () { [array objectsAtIndexes:rangeIndexes(3, 1)] }];
|
||||
}
|
||||
|
||||
- (void)testRemoveObjectsAtIndexes
|
||||
- (void)test_indexOfObject_
|
||||
{
|
||||
var array = [CPMutableArray arrayWithObjects:@"one", @"two", @"three", @"four", nil],
|
||||
indexes = [CPMutableIndexSet indexSetWithIndex:2];
|
||||
var arrayClass = [[self class] arrayClass],
|
||||
array = [arrayClass array];
|
||||
|
||||
[array removeObjectsAtIndexes:indexes];
|
||||
[self assert:[array indexOfObject:0] same:CPNotFound];
|
||||
|
||||
[self assert:array equals:[@"one", @"two", @"four"]];
|
||||
var innerArray = [arrayClass arrayWithObjects:0];
|
||||
|
||||
array = [arrayClass arrayWithObjects:0, @"hello", [AlwaysEqual new], innerArray];
|
||||
|
||||
[self assert:[array indexOfObject:0] same:0];
|
||||
[self assert:[array indexOfObject:@"hello"] same:1];
|
||||
[self assert:[array indexOfObject:[AlwaysEqual new]] same:2];
|
||||
[self assert:[array indexOfObject:innerArray] same:3];
|
||||
[self assert:[array indexOfObject:[arrayClass arrayWithObjects:0]] same:3];
|
||||
|
||||
[self assert:[array indexOfObject:1] same:CPNotFound];
|
||||
[self assert:[array indexOfObject:@"bye"] same:CPNotFound];
|
||||
}
|
||||
|
||||
- (void)testIndexOfObjectPassingTest
|
||||
- (void)test_indexOfObjectIdenticalTo_
|
||||
{
|
||||
var array = [CPArray arrayWithObjects:{name:@"Tom", age:7}, {name:@"Dick", age:13}, {name:@"Harry", age:27}, {name:@"Zelda", age:7}],
|
||||
namePredicate = function(object, index) { return [object.name isEqual:@"Harry"]; },
|
||||
agePredicate = function(object, index) { return object.age === 13; },
|
||||
failPredicate = function(object, index) { return [object.name isEqual:@"Horton"]; },
|
||||
noPredicate = function(object, index) { return NO; },
|
||||
stopPredicate = function(object, index) { return nil; };
|
||||
var arrayClass = [[self class] arrayClass],
|
||||
array = [arrayClass array];
|
||||
|
||||
[self assert:[array indexOfObjectPassingTest:namePredicate] equals:2];
|
||||
[self assert:[array indexOfObjectPassingTest:agePredicate] equals:1];
|
||||
[self assert:[array indexOfObjectPassingTest:failPredicate] equals:CPNotFound];
|
||||
[self assert:[array indexOfObjectPassingTest:noPredicate] equals:CPNotFound];
|
||||
[self assert:[array indexOfObjectPassingTest:stopPredicate] equals:CPNotFound];
|
||||
[self assert:[array indexOfObject:0] same:CPNotFound];
|
||||
|
||||
var innerArray = [arrayClass arrayWithObjects:0];
|
||||
|
||||
array = [arrayClass arrayWithObjects:0, @"hello", [AlwaysEqual new], innerArray];
|
||||
|
||||
[self assert:[array indexOfObjectIdenticalTo:0] same:0];
|
||||
[self assert:[array indexOfObjectIdenticalTo:@"hello"] same:1];
|
||||
[self assert:[array indexOfObjectIdenticalTo:[AlwaysEqual new]] same:CPNotFound];
|
||||
[self assert:[array indexOfObjectIdenticalTo:innerArray] same:3];
|
||||
[self assert:[array indexOfObjectIdenticalTo:[arrayClass arrayWithObjects:0]] same:CPNotFound];
|
||||
|
||||
[self assert:[array indexOfObjectIdenticalTo:1] same:CPNotFound];
|
||||
[self assert:[array indexOfObjectIdenticalTo:@"bye"] same:CPNotFound];
|
||||
}
|
||||
|
||||
- (void)testIndexOfObjectPassingTestContext
|
||||
- (void)test_indexOfObjectPassingTest_
|
||||
{
|
||||
var array = [CPArray arrayWithObjects:{name:@"Tom", age:7}, {name:@"Dick", age:13}, {name:@"Harry", age:27}, {name:@"Zelda", age:7}],
|
||||
namePredicate = function(object, index, context) { return [object.name isEqual:context]; },
|
||||
agePredicate = function(object, index, context) { return object.age === context; };
|
||||
var array = [[[self class] arrayClass] arrayWithObjects:
|
||||
{ name:@"Tom", age:7 },
|
||||
{ name:@"Dick", age:13 },
|
||||
{ name:@"Harry", age:27 },
|
||||
{ name:@"Zelda", age:7 }];
|
||||
|
||||
[self assert:[array indexOfObjectPassingTest:namePredicate context:@"Harry"] equals:2];
|
||||
[self assert:[array indexOfObjectPassingTest:agePredicate context:13] equals:1];
|
||||
[self assert:[array indexOfObjectPassingTest:function() { return YES; }] same:0];
|
||||
[self assert:[array indexOfObjectPassingTest:function() { return NO; }] same:CPNotFound];
|
||||
[self assert:[array indexOfObjectPassingTest:function() { return nil; }] same:CPNotFound];
|
||||
|
||||
[self assert:[array indexOfObjectPassingTest:function(anObject, anIndex)
|
||||
{
|
||||
return [anObject.name isEqual:@"Harry"];
|
||||
}] same:2];
|
||||
|
||||
[self assert:[array indexOfObjectPassingTest:function(anObject, anIndex)
|
||||
{
|
||||
return anObject.age === 13;
|
||||
}] equals:1];
|
||||
|
||||
[self assert:[array indexOfObjectPassingTest:function(anObject, anIndex)
|
||||
{
|
||||
return [anObject.name isEqual:@"Horton"];
|
||||
}] equals:CPNotFound];
|
||||
}
|
||||
|
||||
- (void)testIndexOfObjectWithOptionsPassingTest
|
||||
- (void)test_indexOfObjectPassingTest_context_
|
||||
{
|
||||
var array = [CPArray arrayWithObjects:{name:@"Tom", age:7}, {name:@"Dick", age:13}, {name:@"Harry", age:27}, {name:@"Zelda", age:7}],
|
||||
namePredicate = function(object, index) { return [object.name isEqual:@"Harry"]; },
|
||||
agePredicate = function(object, index) { return object.age === 7; };
|
||||
var array = [[[self class] arrayClass] arrayWithObjects:
|
||||
{ name:@"Tom", age:7 },
|
||||
{ name:@"Dick", age:13 },
|
||||
{ name:@"Harry", age:27 },
|
||||
{ name:@"Zelda", age:7 }];
|
||||
|
||||
[self assert:[array indexOfObjectWithOptions:CPEnumerationNormal passingTest:namePredicate] equals:2];
|
||||
[self assert:[array indexOfObjectWithOptions:CPEnumerationReverse passingTest:namePredicate] equals:2];
|
||||
[self assert:[array indexOfObjectWithOptions:CPEnumerationNormal passingTest:agePredicate] equals:0];
|
||||
[self assert:[array indexOfObjectWithOptions:CPEnumerationReverse passingTest:agePredicate] equals:3];
|
||||
[self assert:[array indexOfObjectPassingTest:function(anObject, anIndex, aContext)
|
||||
{
|
||||
return [anObject.name isEqual:aContext];
|
||||
} context:@"Harry"] same:2];
|
||||
|
||||
[self assert:[array indexOfObjectPassingTest:function(anObject, anIndex, aContext)
|
||||
{
|
||||
return anObject.age === aContext;
|
||||
} context:13] same:1];
|
||||
}
|
||||
|
||||
- (void)testIndexOfObjectWithOptionsPassingTestContext
|
||||
{
|
||||
var array = [CPArray arrayWithObjects:{name:@"Tom", age:7}, {name:@"Dick", age:13}, {name:@"Harry", age:27}, {name:@"Zelda", age:7}],
|
||||
namePredicate = function(object, index, context) { return [object.name isEqual:context]; },
|
||||
agePredicate = function(object, index, context) { return object.age === context; };
|
||||
|
||||
[self assert:[array indexOfObjectWithOptions:CPEnumerationNormal passingTest:namePredicate context:@"Harry"] equals:2];
|
||||
[self assert:[array indexOfObjectWithOptions:CPEnumerationReverse passingTest:namePredicate context:@"Harry"] equals:2];
|
||||
[self assert:[array indexOfObjectWithOptions:CPEnumerationNormal passingTest:agePredicate context:7] equals:0];
|
||||
[self assert:[array indexOfObjectWithOptions:CPEnumerationReverse passingTest:agePredicate context:7] equals:3];
|
||||
- (void)test_indexOfObjectWithOptions_passingTest
|
||||
{
|
||||
var array = [[[self class] arrayClass] arrayWithObjects:
|
||||
{ name:@"Tom", age:7 },
|
||||
{ name:@"Dick", age:13 },
|
||||
{ name:@"Harry", age:27 },
|
||||
{ name:@"Zelda", age:7 }],
|
||||
namePredicate = function(anObject, anIndex)
|
||||
{
|
||||
return [anObject.name isEqual:@"Harry"];
|
||||
},
|
||||
agePredicate = function(anObject, anIndex)
|
||||
{
|
||||
return anObject.age === 7;
|
||||
};
|
||||
|
||||
[self assert:[array indexOfObjectWithOptions:CPEnumerationNormal passingTest:namePredicate] same:2];
|
||||
[self assert:[array indexOfObjectWithOptions:CPEnumerationReverse passingTest:namePredicate] same:2];
|
||||
[self assert:[array indexOfObjectWithOptions:CPEnumerationNormal passingTest:agePredicate] same:0];
|
||||
[self assert:[array indexOfObjectWithOptions:CPEnumerationReverse passingTest:agePredicate] same:3];
|
||||
}
|
||||
|
||||
- (void)testIndexOfObject_inSortedRange_options_usingComparator_
|
||||
- (void)test_indexOfObjectWithOptions_passingTest_context
|
||||
{
|
||||
var array = [0, 1, 1, 1, 2, 2, 3, 3, 4, 4, 7],
|
||||
arraySimple = [4, 5, 7, 8, 9, 10],
|
||||
numComparator = function(a, b) { return a - b; },
|
||||
var array = [[[self class] arrayClass] arrayWithObjects:
|
||||
{ name:@"Tom", age:7 },
|
||||
{ name:@"Dick", age:13 },
|
||||
{ name:@"Harry", age:27 },
|
||||
{ name:@"Zelda", age:7 }],
|
||||
namePredicate = function(anObject, anIndex, aContext)
|
||||
{
|
||||
return [anObject.name isEqual:aContext];
|
||||
},
|
||||
agePredicate = function(anObject, anIndex, aContext)
|
||||
{
|
||||
return anObject.age === aContext;
|
||||
};
|
||||
|
||||
[self assert:[array indexOfObjectWithOptions:CPEnumerationNormal passingTest:namePredicate context:@"Harry"] same:2];
|
||||
[self assert:[array indexOfObjectWithOptions:CPEnumerationReverse passingTest:namePredicate context:@"Harry"] same:2];
|
||||
[self assert:[array indexOfObjectWithOptions:CPEnumerationNormal passingTest:agePredicate context:7] same:0];
|
||||
[self assert:[array indexOfObjectWithOptions:CPEnumerationReverse passingTest:agePredicate context:7] same:3];
|
||||
}
|
||||
|
||||
- (void)test_indexOfObject_inSortedRange_options_usingComparator_
|
||||
{
|
||||
var arrayClass = [[self class] arrayClass],
|
||||
array = [arrayClass arrayWithObjects:0, 1, 1, 1, 2, 2, 3, 3, 4, 4, 7],
|
||||
arraySimple = [arrayClass arrayWithObjects:4, 5, 7, 8, 9, 10],
|
||||
numComparator = function(lhs, rhs) { return lhs - rhs; },
|
||||
index;
|
||||
|
||||
index = [arraySimple indexOfObject:7
|
||||
@@ -253,285 +350,221 @@
|
||||
|
||||
}
|
||||
|
||||
- (void)testIndexOutOfBounds
|
||||
- (void)test_isEqualToArray_
|
||||
{
|
||||
try
|
||||
{
|
||||
[[] objectAtIndex:0];
|
||||
[self assert:false];
|
||||
}
|
||||
catch (anException)
|
||||
{
|
||||
[self assert:[anException name] equals:CPRangeException];
|
||||
[self assertTrue:[[anException reason] rangeOfString:(@"index (0) beyond bounds (0)")].location !== CPNotFound];
|
||||
}
|
||||
var arrayClass = [[self class] arrayClass],
|
||||
lhs = [arrayClass arrayWithObjects:1, @"hello", [AlwaysEqual new], [arrayClass arrayWithObjects:1]],
|
||||
rhs = [arrayClass arrayWithObjects:1, @"hello", [AlwaysEqual new], [arrayClass arrayWithObjects:1]];
|
||||
|
||||
[[0, 1, 2] objectAtIndex:0];
|
||||
[[0, 1, 2] objectAtIndex:1];
|
||||
[[0, 1, 2] objectAtIndex:2];
|
||||
[self assertTrue:[lhs isEqualToArray:lhs]];
|
||||
[self assertTrue:[rhs isEqualToArray:rhs]];
|
||||
[self assertFalse:[lhs isEqualToArray:nil]];
|
||||
[self assertFalse:[rhs isEqualToArray:nil]];
|
||||
[self assertTrue:[lhs isEqualToArray:rhs]];
|
||||
[self assertTrue:[rhs isEqualToArray:lhs]];
|
||||
|
||||
try
|
||||
{
|
||||
[[0, 1, 2] objectAtIndex:3];
|
||||
[self assert:false];
|
||||
}
|
||||
catch (anException)
|
||||
{
|
||||
[self assert:[anException name] equals:CPRangeException];
|
||||
[self assertTrue:[[anException reason] rangeOfString:(@"index (3) beyond bounds (3)")].location !== CPNotFound];
|
||||
}
|
||||
lhs = [arrayClass arrayWithObjects:1];
|
||||
rhs = [arrayClass array];
|
||||
|
||||
try
|
||||
{
|
||||
[[0, 1, 2] objectAtIndex:4];
|
||||
[self assert:false];
|
||||
}
|
||||
catch (anException)
|
||||
{
|
||||
[self assert:[anException name] equals:CPRangeException];
|
||||
[self assertTrue:[[anException reason] rangeOfString:(@"index (4) beyond bounds (3)")].location !== CPNotFound];
|
||||
}
|
||||
[self assertTrue:[lhs isEqualToArray:lhs]];
|
||||
[self assertTrue:[rhs isEqualToArray:rhs]];
|
||||
[self assertFalse:[lhs isEqualToArray:nil]];
|
||||
[self assertFalse:[rhs isEqualToArray:nil]];
|
||||
[self assertFalse:[lhs isEqualToArray:rhs]];
|
||||
[self assertFalse:[rhs isEqualToArray:lhs]];
|
||||
|
||||
lhs = [arrayClass arrayWithObjects:1, 2, 3];
|
||||
rhs = [arrayClass arrayWithObjects:3, 2, 1];
|
||||
|
||||
[self assertTrue:[lhs isEqualToArray:lhs]];
|
||||
[self assertTrue:[rhs isEqualToArray:rhs]];
|
||||
[self assertFalse:[lhs isEqualToArray:nil]];
|
||||
[self assertFalse:[rhs isEqualToArray:nil]];
|
||||
[self assertFalse:[lhs isEqualToArray:rhs]];
|
||||
[self assertFalse:[rhs isEqualToArray:lhs]];
|
||||
|
||||
lhs = [arrayClass arrayWithObjects:1, 2, 3];
|
||||
rhs = [arrayClass arrayWithObjects:5];
|
||||
|
||||
[self assertTrue:[lhs isEqualToArray:lhs]];
|
||||
[self assertTrue:[rhs isEqualToArray:rhs]];
|
||||
[self assertFalse:[lhs isEqualToArray:nil]];
|
||||
[self assertFalse:[rhs isEqualToArray:nil]];
|
||||
[self assertFalse:[lhs isEqualToArray:rhs]];
|
||||
[self assertFalse:[rhs isEqualToArray:lhs]];
|
||||
}
|
||||
|
||||
- (void)testInsertObjectInArraySortedByDescriptors
|
||||
- (void)test_arrayByAddingObject_
|
||||
{
|
||||
var descriptors = [[[CPSortDescriptor alloc] initWithKey:@"intValue" ascending:YES]],
|
||||
array = [1, 3, 5];
|
||||
var arrayClass = [[self class] arrayClass],
|
||||
array = [arrayClass array],
|
||||
nextArray = [array arrayByAddingObject:0];
|
||||
|
||||
[array insertObject:0 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[0, 1, 3, 5] equals:array];
|
||||
[self assert:[array count] same:0];
|
||||
[self assert:[nextArray count] same:1];
|
||||
[self assert:nextArray equals:[arrayClass arrayWithObjects:0]];
|
||||
|
||||
array = [1, 3, 5];
|
||||
[array insertObject:2 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[1, 2, 3, 5] equals:array];
|
||||
array = nextArray;
|
||||
nextArray = [array arrayByAddingObject:1];
|
||||
|
||||
array = [1, 3, 5];
|
||||
[array insertObject:1 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[1, 1, 3, 5] equals:array];
|
||||
[self assert:[array count] same:1];
|
||||
[self assert:[nextArray count] same:2];
|
||||
[self assert:nextArray equals:[arrayClass arrayWithObjects:0, 1]];
|
||||
|
||||
array = [1, 3, 5];
|
||||
[array insertObject:6 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[1, 3, 5, 6] equals:array];
|
||||
array = nextArray;
|
||||
nextArray = [array arrayByAddingObject:[arrayClass arrayWithObjects:1, 3]];
|
||||
|
||||
array = [1, 3, 5];
|
||||
[array insertObject:3 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[1, 3, 3, 5] equals:array];
|
||||
|
||||
array = [];
|
||||
[array insertObject:3 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[3] equals:array];
|
||||
|
||||
descriptors = [[[CPSortDescriptor alloc] initWithKey:@"intValue" ascending:NO]];
|
||||
|
||||
array = [5, 3, 1];
|
||||
[array insertObject:0 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[5, 3, 1, 0] equals:array];
|
||||
|
||||
array = [5, 3, 1];
|
||||
[array insertObject:2 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[5, 3, 2, 1] equals:array];
|
||||
|
||||
array = [5, 3, 1];
|
||||
[array insertObject:1 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[5, 3, 1, 1] equals:array];
|
||||
|
||||
array = [5, 3, 1];
|
||||
[array insertObject:6 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[6, 5, 3, 1] equals:array];
|
||||
|
||||
array = [5, 3, 1];
|
||||
[array insertObject:3 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[5, 3, 3, 1] equals:array];
|
||||
|
||||
array = [];
|
||||
[array insertObject:3 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[3] equals:array];
|
||||
|
||||
descriptors = [[[CPSortDescriptor alloc] initWithKey:@"intValue" ascending:NO]];
|
||||
|
||||
array = [5, 3, 1];
|
||||
[array insertObject:0 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[5, 3, 1, 0] equals:array];
|
||||
|
||||
array = [5, 3, 1];
|
||||
[array insertObject:2 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[5, 3, 2, 1] equals:array];
|
||||
|
||||
array = [5, 3, 1];
|
||||
[array insertObject:1 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[5, 3, 1, 1] equals:array];
|
||||
|
||||
array = [5, 3, 1];
|
||||
[array insertObject:6 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[6, 5, 3, 1] equals:array];
|
||||
|
||||
array = [5, 3, 1];
|
||||
[array insertObject:3 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[5, 3, 3, 1] equals:array];
|
||||
|
||||
array = [];
|
||||
[array insertObject:3 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[3] equals:array];
|
||||
[self assert:[array count] same:2];
|
||||
[self assert:[nextArray count] same:3];
|
||||
[self assert:nextArray equals:[arrayClass arrayWithObjects:0, 1, [arrayClass arrayWithObjects:1, 3]]];
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
- (void)testInitWithArrayCopyItems
|
||||
- (void)test_arrayByAddingObjectFromArray_
|
||||
{
|
||||
var a = [[CopyableObject new], 2, 3, {empty:true}],
|
||||
b = [[CPArray alloc] initWithArray:a copyItems:YES];
|
||||
var arrayClass = [[self class] arrayClass],
|
||||
array = [arrayClass array],
|
||||
otherArray = [arrayClass array],
|
||||
nextArray = [array arrayByAddingObjectsFromArray:otherArray];
|
||||
|
||||
[self assert:a notEqual:b];
|
||||
[self assert:[array count] same:0];
|
||||
[self assert:[nextArray count] same:0];
|
||||
[self assert:array equals:[arrayClass array]];
|
||||
[self assert:otherArray equals:[arrayClass array]];
|
||||
[self assert:array equals:nextArray];
|
||||
|
||||
[self assert:a[0] notEqual:b[0]];
|
||||
[self assert:a[1] equals:b[1]];
|
||||
[self assert:a[2] equals:b[2]];
|
||||
[self assertTrue:a[3] === b[3]];
|
||||
otherArray = [arrayClass arrayWithObjects:1, 2, 3];
|
||||
nextArray = [array arrayByAddingObjectsFromArray:otherArray];
|
||||
|
||||
[self assert:[array count] same:0];
|
||||
[self assert:[otherArray count] same:3];
|
||||
[self assert:[nextArray count] same:3];
|
||||
[self assert:array equals:[arrayClass array]];
|
||||
[self assert:otherArray equals:[arrayClass arrayWithObjects:1, 2, 3]];
|
||||
[self assert:nextArray equals:[arrayClass arrayWithObjects:1, 2, 3]];
|
||||
|
||||
array = nextArray;
|
||||
otherArray = [arrayClass arrayWithObjects:5];
|
||||
nextArray = [array arrayByAddingObjectsFromArray:otherArray];
|
||||
|
||||
[self assert:[array count] same:3];
|
||||
[self assert:[otherArray count] same:1];
|
||||
[self assert:[nextArray count] same:4];
|
||||
[self assert:array equals:[arrayClass arrayWithObjects:1, 2, 3]];
|
||||
[self assert:otherArray equals:[arrayClass arrayWithObjects:5]];
|
||||
[self assert:nextArray equals:[arrayClass arrayWithObjects:1, 2, 3, 5]];
|
||||
|
||||
array = nextArray;
|
||||
otherArray = [1, 2, 3];
|
||||
nextArray = [array arrayByAddingObjectsFromArray:otherArray];
|
||||
|
||||
[self assert:[array count] same:4];
|
||||
[self assert:[otherArray count] same:3];
|
||||
[self assert:[nextArray count] same:7];
|
||||
[self assert:array equals:[arrayClass arrayWithObjects:1, 2, 3, 5]];
|
||||
[self assert:otherArray equals:[arrayClass arrayWithObjects:1, 2, 3]];
|
||||
[self assert:nextArray equals:[arrayClass arrayWithObjects:1, 2, 3, 5, 1, 2, 3]];
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
- (void)testIsEqualToArray
|
||||
- (void)test_componentsJoinedByString_
|
||||
{
|
||||
var a = [1, 2, 3],
|
||||
b = [5];
|
||||
var arrayClass = [[self class] arrayClass],
|
||||
tests = [
|
||||
[[arrayClass array], "", ""],
|
||||
[[arrayClass array], "-", ""],
|
||||
[[arrayClass arrayWithObjects:1, 2], "-", "1-2"],
|
||||
[[arrayClass arrayWithObjects:1, 2, 3], "-", "1-2-3"],
|
||||
[[arrayClass arrayWithObjects:"123", 456], "-", "123-456"]
|
||||
],
|
||||
index = 0,
|
||||
count = tests.length;
|
||||
|
||||
[self assertTrue:[a isEqualToArray:a]];
|
||||
[self assertFalse:[a isEqualToArray:b]];
|
||||
[self assertFalse:[a isEqualToArray:nil]];
|
||||
}
|
||||
|
||||
- (void)testIsEqualToArray
|
||||
{
|
||||
var a = [1, 2, 3],
|
||||
b = [5];
|
||||
|
||||
[self assertTrue:[a isEqualToArray:a]];
|
||||
[self assertFalse:[a isEqualToArray:b]];
|
||||
[self assertFalse:[a isEqualToArray:nil]];
|
||||
}
|
||||
|
||||
- (void)testThatCPArrayDoesSortUsingDescriptorsForStrings
|
||||
{
|
||||
var target = ["a", "b", "c", "d"],
|
||||
pretty = [];
|
||||
|
||||
for (var i = 0; i < target.length; i++)
|
||||
pretty.push([[CPPrettyObject alloc] initWithValue:target[i] number:i]);
|
||||
|
||||
[pretty sortUsingDescriptors:[[[CPSortDescriptor alloc] initWithKey:@"value" ascending:NO]]];
|
||||
|
||||
[self assert:"(\n\t3:d, \n\t2:c, \n\t1:b, \n\t0:a\n)" equals:[pretty description]];
|
||||
|
||||
[pretty sortUsingDescriptors:[[[CPSortDescriptor alloc] initWithKey:@"value" ascending:YES]]];
|
||||
|
||||
[self assert:"(\n\t0:a, \n\t1:b, \n\t2:c, \n\t3:d\n)" equals:[pretty description]]
|
||||
}
|
||||
|
||||
- (void)testThatCPArrayDoesSortUsingTwoDescriptors
|
||||
{
|
||||
var descriptors = [
|
||||
[[CPSortDescriptor alloc] initWithKey:@"value" ascending:NO],
|
||||
[[CPSortDescriptor alloc] initWithKey:@"number" ascending:NO]
|
||||
],
|
||||
target = [
|
||||
[[CPPrettyObject alloc] initWithValue:@"a" number:1],
|
||||
[[CPPrettyObject alloc] initWithValue:@"a" number:2],
|
||||
[[CPPrettyObject alloc] initWithValue:@"a" number:3],
|
||||
[[CPPrettyObject alloc] initWithValue:@"b" number:1],
|
||||
[[CPPrettyObject alloc] initWithValue:@"b" number:2],
|
||||
[[CPPrettyObject alloc] initWithValue:@"b" number:3],
|
||||
];
|
||||
|
||||
[target sortUsingDescriptors:descriptors];
|
||||
|
||||
[self assert:@"3:b" equals:[target[0] description]];
|
||||
[self assert:@"2:b" equals:[target[1] description]];
|
||||
[self assert:@"1:b" equals:[target[2] description]];
|
||||
[self assert:@"3:a" equals:[target[3] description]];
|
||||
[self assert:@"2:a" equals:[target[4] description]];
|
||||
[self assert:@"1:a" equals:[target[5] description]];
|
||||
}
|
||||
|
||||
- (void)testThatCPArrayDoesSortUsingTwoDescriptorsOpposite
|
||||
{
|
||||
var descriptors = [
|
||||
[[CPSortDescriptor alloc] initWithKey:@"number" ascending:NO],
|
||||
[[CPSortDescriptor alloc] initWithKey:@"value" ascending:NO]
|
||||
],
|
||||
target = [
|
||||
[[CPPrettyObject alloc] initWithValue:@"a" number:1],
|
||||
[[CPPrettyObject alloc] initWithValue:@"a" number:2],
|
||||
[[CPPrettyObject alloc] initWithValue:@"a" number:3],
|
||||
[[CPPrettyObject alloc] initWithValue:@"b" number:1],
|
||||
[[CPPrettyObject alloc] initWithValue:@"b" number:2],
|
||||
[[CPPrettyObject alloc] initWithValue:@"b" number:3],
|
||||
];
|
||||
|
||||
[target sortUsingDescriptors:descriptors];
|
||||
|
||||
[self assert:@"3:b" equals:[target[0] description]];
|
||||
[self assert:@"3:a" equals:[target[1] description]];
|
||||
[self assert:@"2:b" equals:[target[2] description]];
|
||||
[self assert:@"2:a" equals:[target[3] description]];
|
||||
[self assert:@"1:b" equals:[target[4] description]];
|
||||
[self assert:@"1:a" equals:[target[5] description]];
|
||||
}
|
||||
|
||||
- (void)testThatCPArrayDoesSortUsingDescriptorWithMultipleSameValues
|
||||
{
|
||||
var descriptors = [[[CPSortDescriptor alloc] initWithKey:@"intValue" ascending:NO]],
|
||||
target = [1, 1, 2, 4, 3, 1, 2, 4, 5, 1];
|
||||
|
||||
[target sortUsingDescriptors:descriptors];
|
||||
|
||||
[self assert:[5, 4, 4, 3, 2, 2, 1, 1, 1, 1] equals:target];
|
||||
for (; index < count; ++index)
|
||||
[self assert:[tests[index][0] componentsJoinedByString:tests[index][1]] equals:tests[index][2]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation CPPrettyObject : CPObject
|
||||
@implementation AlwaysEqual : CPObject
|
||||
{
|
||||
CPString value @accessors;
|
||||
CPNumber number @accessors;
|
||||
}
|
||||
|
||||
- (id)initWithValue:(CPString)aValue number:(CPNumber)aNumber
|
||||
- (BOOL)isEqual:(id)anObject
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
{
|
||||
number = aNumber;
|
||||
value = aValue;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (CPString)description
|
||||
{
|
||||
return number + ":" + value;
|
||||
return [anObject isKindOfClass:AlwaysEqual];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation CPArray (reverse)
|
||||
@implementation CPArray (TestingAdditions)
|
||||
|
||||
- (CPArray)arrayByReversingArray
|
||||
{
|
||||
var a = [];
|
||||
for (i = length - 1; i >= 0; --i)
|
||||
a.push(self[i]);
|
||||
var args = [[self class], @selector(arrayWithObjects:)],
|
||||
index = [self count];
|
||||
|
||||
return a;
|
||||
while (index--)
|
||||
args.push([self objectAtIndex:index]);
|
||||
|
||||
return objj_msgSend.apply(this, args);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation CopyableObject : CPObject
|
||||
@implementation ConcreteArray : CPArray
|
||||
{
|
||||
Array array;
|
||||
}
|
||||
|
||||
- (id)copy
|
||||
- (id)initWithObjects:(id)anObject, ...
|
||||
{
|
||||
return [[[self class] alloc] init];
|
||||
// The arguments array contains self and _cmd, so the first object is at position 2.
|
||||
var index = 2,
|
||||
count = arguments.length;
|
||||
|
||||
for (; index < count; ++index)
|
||||
if (arguments[index] === nil)
|
||||
break;
|
||||
|
||||
array = Array.prototype.slice.call(arguments, 2, index);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if (self)
|
||||
array = [];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithArray:(CPArray)anArray
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if (self)
|
||||
array = [anArray copy];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (CPUInteger)count
|
||||
{
|
||||
return array.length;
|
||||
}
|
||||
|
||||
- (id)objectAtIndex:(CPUInteger)anIndex
|
||||
{
|
||||
if (anIndex < 0 || anIndex >= [self count])
|
||||
throw "range error";
|
||||
|
||||
return array[anIndex];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -349,7 +349,7 @@ var accessIVARS = YES;
|
||||
"propertyWithPublicAccessor","propertyWithPrivateAccessor"
|
||||
];
|
||||
var allValues = [value,value,value,value,value,value];
|
||||
var dictForKeys = [CPDictionary dictionaryWithObjects: allValues forKeys: allKeys];
|
||||
var dictForKeys = [CPDictionary dictionaryWithObjects: allValues forKeys: allKeys];
|
||||
[self assertNoThrow:function(){[kvcTestObject setValuesForKeysWithDictionary: dictForKeys];}];
|
||||
}
|
||||
|
||||
@@ -361,7 +361,7 @@ var accessIVARS = YES;
|
||||
"propertyWithPublicAccessor","propertyWithPrivateAccessor"
|
||||
];
|
||||
var allValues = [value,value,value,value,value,value];
|
||||
var dictForKeys = [CPDictionary dictionaryWithObjects: allValues forKeys: allKeys];
|
||||
var dictForKeys = [CPDictionary dictionaryWithObjects: allValues forKeys: allKeys];
|
||||
[self assertThrows:function(){[kvcTestObject setValuesForKeysWithDictionary: dictForKeys];}];
|
||||
}
|
||||
|
||||
@@ -375,7 +375,7 @@ var accessIVARS = YES;
|
||||
"propertyWithPublicAccessor","propertyWithPrivateAccessor"
|
||||
];
|
||||
var allValues = [value,value,value,value,value,value];
|
||||
var dictForKeys = [CPDictionary dictionaryWithObjects: allValues forKeys: allKeys];
|
||||
var dictForKeys = [CPDictionary dictionaryWithObjects: allValues forKeys: allKeys];
|
||||
[kvcTestObject setValuesForKeysWithDictionary: dictForKeys];
|
||||
|
||||
var key, aValue, keyEnumerator = [dictForKeys keyEnumerator];
|
||||
@@ -426,7 +426,7 @@ var accessIVARS = YES;
|
||||
"propertyWithPublicAccessor","propertyWithPrivateAccessor"
|
||||
];
|
||||
var allValues = [value,value,value,value,value,value];
|
||||
var dictForKeys = [CPDictionary dictionaryWithObjects: allValues forKeys: allKeys];
|
||||
var dictForKeys = [CPDictionary dictionaryWithObjects: allValues forKeys: allKeys];
|
||||
[kvcTestObject setValuesForKeysWithDictionary: dictForKeys];
|
||||
|
||||
[self assertNull: [kvcTestObject valueForKey: "privatePropertyWithoutAccessors"]];
|
||||
@@ -459,7 +459,7 @@ var accessIVARS = YES;
|
||||
|
||||
@end
|
||||
|
||||
// CPNull
|
||||
// CPNull
|
||||
|
||||
@implementation CPKeyValueCodingTest (CPNullTest)
|
||||
|
||||
@@ -611,6 +611,14 @@ var accessIVARS = YES;
|
||||
[self assert:[@"two", @"four"] equals:[array objectsAtIndexes:indexes]];
|
||||
}
|
||||
|
||||
- (void)testKVArrayCopy
|
||||
{
|
||||
var object = [ObjectsAtIndexesClass new],
|
||||
array = [object valueForKey:@"objects"];
|
||||
|
||||
[self assert:[CPArray arrayWithObjects:@"one", @"two", @"three", @"four", @"five"] equals:[array copy]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -659,29 +667,16 @@ var accessIVARS = YES;
|
||||
[self assertFalse:[set containsObject:8]];
|
||||
[self assertFalse:[set containsObject:10]];
|
||||
|
||||
[self assert:[set setByAddingObjectsFromArray:[2, 3, 4, 5, 6]]
|
||||
[self assert:[set setByAddingObjectsFromArray:[2, 3, 4, 5, 6]]
|
||||
equals:[CPSet setWithObjects:0, 1, 2, 3, 4, 5, 6, 7]];
|
||||
}
|
||||
|
||||
- (void)testObjectsAtIndexes_
|
||||
- (void)testKVSetCopy
|
||||
{
|
||||
var object = [ObjectsAtIndexesClass new],
|
||||
array = [object valueForKey:@"objects"];
|
||||
var object = [UnorderedAccessorClass new],
|
||||
set = [object valueForKey:@"objects"];
|
||||
|
||||
[self assert:5 equals:[array count]];
|
||||
|
||||
[self assert:@"one" equals:[array objectAtIndex:0]];
|
||||
[self assert:@"two" equals:[array objectAtIndex:1]];
|
||||
[self assert:@"three" equals:[array objectAtIndex:2]];
|
||||
[self assert:@"four" equals:[array objectAtIndex:3]];
|
||||
[self assert:@"five" equals:[array objectAtIndex:4]];
|
||||
|
||||
var indexes = [CPIndexSet indexSet];
|
||||
|
||||
[indexes addIndex:1];
|
||||
[indexes addIndex:3];
|
||||
|
||||
[self assert:[@"two", @"four"] equals:[array objectsAtIndexes:indexes]];
|
||||
[self assert:[CPSet setWithObjects:0, 1, 3, 5, 7] equals:[set copy]];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,558 @@
|
||||
|
||||
@import <Foundation/Foundation.j>
|
||||
@import "CPArrayTest.j"
|
||||
|
||||
|
||||
@implementation CPMutableArrayTest : CPArrayTest
|
||||
|
||||
+ (Class)arrayClass
|
||||
{
|
||||
return ConcreteMutableArray;
|
||||
}
|
||||
|
||||
- (void)test_addObject_
|
||||
{
|
||||
var arrayClass = [[self class] arrayClass],
|
||||
array = [arrayClass array];
|
||||
|
||||
[array addObject:0];
|
||||
[self assert:array equals:[arrayClass arrayWithObjects:0]];
|
||||
|
||||
[array addObject:0];
|
||||
[self assert:array equals:[arrayClass arrayWithObjects:0, 0]];
|
||||
|
||||
[array addObject:1];
|
||||
[self assert:array equals:[arrayClass arrayWithObjects:0, 0, 1]];
|
||||
|
||||
[array addObject:[arrayClass arrayWithObjects:0, 1, 2]];
|
||||
[self assert:array equals:[arrayClass arrayWithObjects:0, 0, 1, [arrayClass arrayWithObjects:0, 1, 2]]];
|
||||
}
|
||||
|
||||
- (void)test_addObjectsFromArray_
|
||||
{
|
||||
var arrayClass = [[self class] arrayClass],
|
||||
array = [arrayClass array];
|
||||
|
||||
[array addObjectsFromArray:[arrayClass arrayWithObjects:0, 1, 2]];
|
||||
[self assert:array equals:[arrayClass arrayWithObjects:0, 1, 2]];
|
||||
|
||||
[array addObjectsFromArray:[0, 1, 2]];
|
||||
[self assert:array equals:[arrayClass arrayWithObjects:0, 1, 2, 0, 1, 2]];
|
||||
|
||||
[array addObjectsFromArray:[arrayClass array]];
|
||||
[self assert:array equals:[arrayClass arrayWithObjects:0, 1, 2, 0, 1, 2]];
|
||||
|
||||
[array addObjectsFromArray:[]];
|
||||
[self assert:array equals:[arrayClass arrayWithObjects:0, 1, 2, 0, 1, 2]];
|
||||
}
|
||||
|
||||
- (void)test_insertObjects_atIndexes_
|
||||
{
|
||||
var arrayClass = [[self class] arrayClass],
|
||||
array = [arrayClass array];
|
||||
|
||||
[array insertObjects:[arrayClass arrayWithObjects:2, 4] atIndexes:[CPIndexSet indexSetWithIndexesInRange:CPMakeRange(0, 2)]];
|
||||
|
||||
[self assert:array equals:[arrayClass arrayWithObjects:2, 4]];
|
||||
|
||||
[array insertObjects:[arrayClass arrayWithObjects:0] atIndexes:[CPIndexSet indexSetWithIndex:0]];
|
||||
|
||||
[self assert:array equals:[arrayClass arrayWithObjects:0, 2, 4]];
|
||||
|
||||
[array insertObjects:[arrayClass arrayWithObjects:5] atIndexes:[CPIndexSet indexSetWithIndex:3]];
|
||||
|
||||
[self assert:array equals:[arrayClass arrayWithObjects:0, 2, 4, 5]];
|
||||
|
||||
[array insertObjects:[arrayClass arrayWithObjects:6, 7] atIndexes:[CPIndexSet indexSetWithIndexesInRange:CPMakeRange(4, 2)]];
|
||||
|
||||
[self assert:array equals:[arrayClass arrayWithObjects:0, 2, 4, 5, 6, 7]];
|
||||
|
||||
[array insertObjects:[arrayClass arrayWithObjects:-2, -1] atIndexes:[CPIndexSet indexSetWithIndexesInRange:CPMakeRange(0, 2)]];
|
||||
|
||||
[self assert:array equals:[arrayClass arrayWithObjects:-2, -1, 0, 2, 4, 5, 6, 7]];
|
||||
|
||||
var indexSet = [CPMutableIndexSet indexSetWithIndex:3];
|
||||
|
||||
[indexSet addIndex:5];
|
||||
|
||||
[array insertObjects:[arrayClass arrayWithObjects:1, 3] atIndexes:indexSet];
|
||||
|
||||
[self assert:array equals:[arrayClass arrayWithObjects:-2, -1, 0, 1, 2, 3, 4, 5, 6, 7]];
|
||||
|
||||
[self assertThrows:function()
|
||||
{
|
||||
[array insertObjects:[arrayClass array] atIndexes:[CPIndexSet indexSetWithIndex:13]];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)test_removeObjectsAtIndexes_
|
||||
{
|
||||
var arrayClass = [[self class] arrayClass],
|
||||
array = [arrayClass arrayWithObjects:0, 1, 2, 3, 4, 5, 6];
|
||||
|
||||
[array removeObjectsAtIndexes:[CPIndexSet indexSet]];
|
||||
[self assert:array equals:[arrayClass arrayWithObjects:0, 1, 2, 3, 4, 5, 6]];
|
||||
|
||||
[array removeObjectsAtIndexes:[CPIndexSet indexSetWithIndex:2]];
|
||||
[self assert:array equals:[arrayClass arrayWithObjects:0, 1, 3, 4, 5, 6]];
|
||||
|
||||
[array removeObjectsAtIndexes:[CPIndexSet indexSetWithIndexesInRange:CPMakeRange(3, 2)]];
|
||||
[self assert:array equals:[arrayClass arrayWithObjects:0, 1, 3, 6]];
|
||||
|
||||
[array removeObjectsAtIndexes:[CPIndexSet indexSetWithIndexesInRange:CPMakeRange(0, 4)]];
|
||||
[self assert:array equals:[arrayClass array]];
|
||||
}
|
||||
|
||||
- (void)test_removeAllObjects
|
||||
{
|
||||
var arrayClass = [[self class] arrayClass],
|
||||
array = [arrayClass array];
|
||||
|
||||
[array removeAllObjects];
|
||||
[self assert:0 same:[array count]];
|
||||
[self assert:[arrayClass array] equals:array];
|
||||
|
||||
array = [arrayClass arrayWithObjects:0, 1, 2, 3, 4, 5, 6];
|
||||
|
||||
[array removeAllObjects];
|
||||
[self assert:0 same:[array count]];
|
||||
[self assert:[arrayClass array] equals:array];
|
||||
|
||||
array = [arrayClass arrayWithObjects:0, 1, 2, 3, 4, 5, 6, [arrayClass arrayWithObjects:0, 1, 2]];
|
||||
|
||||
[array removeAllObjects];
|
||||
[self assert:0 same:[array count]];
|
||||
[self assert:[arrayClass array] equals:array];
|
||||
}
|
||||
|
||||
- (void)test_removeObjectsInRange_
|
||||
{
|
||||
var arrayClass = [[self class] arrayClass],
|
||||
array = [arrayClass arrayWithObjects:0, 1, 2, 3, 4, 5, 6];
|
||||
|
||||
[array removeObjectsInRange:CPMakeRange(0, 0)];
|
||||
[self assert:array equals:[arrayClass arrayWithObjects:0, 1, 2, 3, 4, 5, 6]];
|
||||
|
||||
[array removeObjectsInRange:CPMakeRange(0, 1)];
|
||||
[self assert:array equals:[arrayClass arrayWithObjects:1, 2, 3, 4, 5, 6]];
|
||||
|
||||
[array removeObjectsInRange:CPMakeRange(2, 3)];
|
||||
[self assert:array equals:[arrayClass arrayWithObjects:1, 2, 6]];
|
||||
|
||||
[array removeObjectsInRange:CPMakeRange(2, 1)];
|
||||
[self assert:array equals:[arrayClass arrayWithObjects:1, 2]];
|
||||
|
||||
[array removeObjectsInRange:CPMakeRange(0, 2)];
|
||||
[self assert:array equals:[arrayClass array]];
|
||||
}
|
||||
|
||||
- (void)test_removeAllObjects
|
||||
{
|
||||
var arrayClass = [[self class] arrayClass],
|
||||
array = [arrayClass array];
|
||||
|
||||
[array removeAllObjects];
|
||||
[self assert:0 same:[array count]];
|
||||
[self assert:[arrayClass array] equals:array];
|
||||
|
||||
array = [arrayClass arrayWithObjects:0, 1, 2, 3, 4, 5, 6];
|
||||
|
||||
[array removeAllObjects];
|
||||
[self assert:0 same:[array count]];
|
||||
[self assert:[arrayClass array] equals:array];
|
||||
|
||||
array = [arrayClass arrayWithObjects:0, 1, 2, 3, 4, 5, 6, [arrayClass arrayWithObjects:0, 1, 2]];
|
||||
|
||||
[array removeAllObjects];
|
||||
[self assert:0 same:[array count]];
|
||||
[self assert:[arrayClass array] equals:array];
|
||||
}
|
||||
|
||||
- (void)test_setArray_
|
||||
{
|
||||
var arrayClass = [[self class] arrayClass],
|
||||
array = [arrayClass array];
|
||||
|
||||
[array setArray:[arrayClass array]];
|
||||
[self assert:[arrayClass array] equals:array];
|
||||
|
||||
[array setArray:[arrayClass arrayWithObjects:0, 1, 2, 3]];
|
||||
[self assert:[arrayClass arrayWithObjects:0, 1, 2, 3] equals:array];
|
||||
|
||||
[array setArray:[arrayClass array]];
|
||||
[self assert:[arrayClass array] equals:array];
|
||||
|
||||
[array setArray:[-1, 0, 1]];
|
||||
[self assert:[arrayClass arrayWithObjects:-1, 0, 1] equals:array];
|
||||
}
|
||||
|
||||
- (void)test_insertObject_inArraySortedByDescriptors_
|
||||
{
|
||||
var arrayClass = [[self class] arrayClass],
|
||||
descriptors = [[[CPSortDescriptor alloc] initWithKey:@"intValue" ascending:YES]],
|
||||
array = [arrayClass arrayWithObjects:1, 3, 5];
|
||||
|
||||
[array insertObject:0 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[0, 1, 3, 5] equals:array];
|
||||
|
||||
array = [arrayClass arrayWithObjects:1, 3, 5];
|
||||
[array insertObject:2 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[1, 2, 3, 5] equals:array];
|
||||
|
||||
array = [arrayClass arrayWithObjects:1, 3, 5];
|
||||
[array insertObject:1 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[1, 1, 3, 5] equals:array];
|
||||
|
||||
array = [arrayClass arrayWithObjects:1, 3, 5];
|
||||
[array insertObject:6 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[1, 3, 5, 6] equals:array];
|
||||
|
||||
array = [arrayClass arrayWithObjects:1, 3, 5];
|
||||
[array insertObject:3 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[1, 3, 3, 5] equals:array];
|
||||
|
||||
array = [arrayClass array];
|
||||
[array insertObject:3 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[3] equals:array];
|
||||
|
||||
descriptors = [[[CPSortDescriptor alloc] initWithKey:@"intValue" ascending:NO]];
|
||||
|
||||
array = [arrayClass arrayWithObjects:5, 3, 1];
|
||||
[array insertObject:0 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[5, 3, 1, 0] equals:array];
|
||||
|
||||
array = [arrayClass arrayWithObjects:5, 3, 1];
|
||||
[array insertObject:2 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[5, 3, 2, 1] equals:array];
|
||||
|
||||
array = [arrayClass arrayWithObjects:5, 3, 1];
|
||||
[array insertObject:1 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[5, 3, 1, 1] equals:array];
|
||||
|
||||
array = [arrayClass arrayWithObjects:5, 3, 1];
|
||||
[array insertObject:6 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[6, 5, 3, 1] equals:array];
|
||||
|
||||
array = [arrayClass arrayWithObjects:5, 3, 1];
|
||||
[array insertObject:3 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[5, 3, 3, 1] equals:array];
|
||||
|
||||
array = [arrayClass array];
|
||||
[array insertObject:3 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[3] equals:array];
|
||||
|
||||
descriptors = [[[CPSortDescriptor alloc] initWithKey:@"intValue" ascending:NO]];
|
||||
|
||||
array = [arrayClass arrayWithObjects:5, 3, 1];
|
||||
[array insertObject:0 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[5, 3, 1, 0] equals:array];
|
||||
|
||||
array = [arrayClass arrayWithObjects:5, 3, 1];
|
||||
[array insertObject:2 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[5, 3, 2, 1] equals:array];
|
||||
|
||||
array = [arrayClass arrayWithObjects:5, 3, 1];
|
||||
[array insertObject:1 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[5, 3, 1, 1] equals:array];
|
||||
|
||||
array = [arrayClass arrayWithObjects:5, 3, 1];
|
||||
[array insertObject:6 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[6, 5, 3, 1] equals:array];
|
||||
|
||||
array = [arrayClass arrayWithObjects:5, 3, 1];
|
||||
[array insertObject:3 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[5, 3, 3, 1] equals:array];
|
||||
|
||||
array = [arrayClass array];
|
||||
[array insertObject:3 inArraySortedByDescriptors:descriptors];
|
||||
[self assert:[3] equals:array];
|
||||
}
|
||||
|
||||
- (void)test_replaceObjectsInRange_withObjectFromArray_
|
||||
{
|
||||
var arrayClass = [[self class] arrayClass],
|
||||
array = [arrayClass arrayWithObjects:1, 2, 3, 4, 5];
|
||||
|
||||
[array replaceObjectsInRange:CPMakeRange(0, 0) withObjectsFromArray:[arrayClass array]];
|
||||
[self assert:[1, 2, 3, 4, 5] equals:array];
|
||||
|
||||
[array replaceObjectsInRange:CPMakeRange(0, 1) withObjectsFromArray:[arrayClass array]];
|
||||
[self assert:[2, 3, 4, 5] equals:array];
|
||||
|
||||
[array replaceObjectsInRange:CPMakeRange(3, 1) withObjectsFromArray:[arrayClass array]];
|
||||
[self assert:[2, 3, 4] equals:array];
|
||||
|
||||
[array replaceObjectsInRange:CPMakeRange(0, 3) withObjectsFromArray:[5, 4, 3, 2, 1]];
|
||||
[self assert:[5, 4, 3, 2, 1] equals:array];
|
||||
|
||||
[array replaceObjectsInRange:CPMakeRange(2, 0) withObjectsFromArray:[5, 4, 3, 2, 1]];
|
||||
[self assert:[5, 4, 5, 4, 3, 2, 1, 3, 2, 1] equals:array];
|
||||
|
||||
[array replaceObjectsInRange:CPMakeRange(2, 5) withObjectsFromArray:[1]];
|
||||
[self assert:[5, 4, 1, 3, 2, 1] equals:array];
|
||||
|
||||
[array replaceObjectsInRange:CPMakeRange(3, 3) withObjectsFromArray:[1, 4, 5]];
|
||||
[self assert:[5, 4, 1, 1, 4, 5] equals:array];
|
||||
|
||||
[array replaceObjectsInRange:CPMakeRange(0, 3) withObjectsFromArray:[1, 4, 5]];
|
||||
[self assert:[1, 4, 5, 1, 4, 5] equals:array];
|
||||
}
|
||||
|
||||
- (void)test_replaceObjectsInRange_withObjectFromArray_range_
|
||||
{
|
||||
var arrayClass = [[self class] arrayClass],
|
||||
array = [arrayClass arrayWithObjects:1, 2, 3, 4, 5];
|
||||
|
||||
[array replaceObjectsInRange:CPMakeRange(0, 0) withObjectsFromArray:[arrayClass array] range:CPMakeRange(0, 0)];
|
||||
[self assert:[1, 2, 3, 4, 5] equals:array];
|
||||
|
||||
[array replaceObjectsInRange:CPMakeRange(0, 1) withObjectsFromArray:[arrayClass array] range:CPMakeRange(0, 0)];
|
||||
[self assert:[2, 3, 4, 5] equals:array];
|
||||
|
||||
[array replaceObjectsInRange:CPMakeRange(3, 1) withObjectsFromArray:[arrayClass array] range:CPMakeRange(0, 0)];
|
||||
[self assert:[2, 3, 4] equals:array];
|
||||
|
||||
[array replaceObjectsInRange:CPMakeRange(0, 3) withObjectsFromArray:[5, 4, 3, 2, 1] range:CPMakeRange(1, 3)];
|
||||
[self assert:[4, 3, 2] equals:array];
|
||||
|
||||
[array replaceObjectsInRange:CPMakeRange(2, 0) withObjectsFromArray:[5, 4, 3, 2, 1] range:CPMakeRange(4, 1)];
|
||||
[self assert:[4, 3, 1, 2] equals:array];
|
||||
|
||||
[array replaceObjectsInRange:CPMakeRange(1, 2) withObjectsFromArray:[5] range:CPMakeRange(0, 0)];
|
||||
[self assert:[4, 2] equals:array];
|
||||
|
||||
[array replaceObjectsInRange:CPMakeRange(1, 1) withObjectsFromArray:[1, 4, 5] range:CPMakeRange(0, 3)];
|
||||
[self assert:[4, 1, 4, 5] equals:array];
|
||||
|
||||
[array replaceObjectsInRange:CPMakeRange(0, 3) withObjectsFromArray:[1, 4, 5] range:CPMakeRange(1, 1)];
|
||||
[self assert:[4, 5] equals:array];
|
||||
}
|
||||
|
||||
- (void)test_exchangeObjectAtIndex_withObjectAtIndex_
|
||||
{
|
||||
var arrayClass = [[self class] arrayClass],
|
||||
array = [arrayClass arrayWithObjects:1, 2, 3, 4, 5];
|
||||
|
||||
[array exchangeObjectAtIndex:0 withObjectAtIndex:0];
|
||||
[self assert:[1, 2, 3, 4, 5] equals:array];
|
||||
|
||||
[array exchangeObjectAtIndex:0 withObjectAtIndex:1];
|
||||
[self assert:[2, 1, 3, 4, 5] equals:array];
|
||||
|
||||
[array exchangeObjectAtIndex:1 withObjectAtIndex:3];
|
||||
[self assert:[2, 4, 3, 1, 5] equals:array];
|
||||
|
||||
[array exchangeObjectAtIndex:1 withObjectAtIndex:3];
|
||||
[self assert:[2, 1, 3, 4, 5] equals:array];
|
||||
|
||||
[array exchangeObjectAtIndex:4 withObjectAtIndex:2];
|
||||
[self assert:[2, 1, 5, 4, 3] equals:array];
|
||||
}
|
||||
|
||||
// Old Tests
|
||||
- (void)testInitWithArrayCopyItems
|
||||
{
|
||||
var a = [[CopyableObject new], 2, 3, {empty:true}],
|
||||
b = [[CPArray alloc] initWithArray:a copyItems:YES];
|
||||
|
||||
[self assert:a notEqual:b];
|
||||
|
||||
[self assert:a[0] notEqual:b[0]];
|
||||
[self assert:a[1] equals:b[1]];
|
||||
[self assert:a[2] equals:b[2]];
|
||||
[self assertTrue:a[3] === b[3]];
|
||||
}
|
||||
|
||||
- (void)testThatCPArrayDoesSortUsingDescriptorsForStrings
|
||||
{
|
||||
var target = ["a", "b", "c", "d"],
|
||||
pretty = [];
|
||||
|
||||
for (var i = 0; i < target.length; i++)
|
||||
pretty.push([[CPPrettyObject alloc] initWithValue:target[i] number:i]);
|
||||
|
||||
[pretty sortUsingDescriptors:[[[CPSortDescriptor alloc] initWithKey:@"value" ascending:NO]]];
|
||||
|
||||
[self assert:"(\n\t3:d, \n\t2:c, \n\t1:b, \n\t0:a\n)" equals:[pretty description]];
|
||||
|
||||
[pretty sortUsingDescriptors:[[[CPSortDescriptor alloc] initWithKey:@"value" ascending:YES]]];
|
||||
|
||||
[self assert:"(\n\t0:a, \n\t1:b, \n\t2:c, \n\t3:d\n)" equals:[pretty description]]
|
||||
}
|
||||
|
||||
- (void)testThatCPArrayDoesSortUsingTwoDescriptors
|
||||
{
|
||||
var descriptors = [
|
||||
[[CPSortDescriptor alloc] initWithKey:@"value" ascending:NO],
|
||||
[[CPSortDescriptor alloc] initWithKey:@"number" ascending:NO]
|
||||
],
|
||||
target = [
|
||||
[[CPPrettyObject alloc] initWithValue:@"a" number:1],
|
||||
[[CPPrettyObject alloc] initWithValue:@"a" number:2],
|
||||
[[CPPrettyObject alloc] initWithValue:@"a" number:3],
|
||||
[[CPPrettyObject alloc] initWithValue:@"b" number:1],
|
||||
[[CPPrettyObject alloc] initWithValue:@"b" number:2],
|
||||
[[CPPrettyObject alloc] initWithValue:@"b" number:3],
|
||||
];
|
||||
|
||||
[target sortUsingDescriptors:descriptors];
|
||||
|
||||
[self assert:@"3:b" equals:[target[0] description]];
|
||||
[self assert:@"2:b" equals:[target[1] description]];
|
||||
[self assert:@"1:b" equals:[target[2] description]];
|
||||
[self assert:@"3:a" equals:[target[3] description]];
|
||||
[self assert:@"2:a" equals:[target[4] description]];
|
||||
[self assert:@"1:a" equals:[target[5] description]];
|
||||
}
|
||||
|
||||
- (void)testThatCPArrayDoesSortUsingTwoDescriptorsOpposite
|
||||
{
|
||||
var descriptors = [
|
||||
[[CPSortDescriptor alloc] initWithKey:@"number" ascending:NO],
|
||||
[[CPSortDescriptor alloc] initWithKey:@"value" ascending:NO]
|
||||
],
|
||||
target = [
|
||||
[[CPPrettyObject alloc] initWithValue:@"a" number:1],
|
||||
[[CPPrettyObject alloc] initWithValue:@"a" number:2],
|
||||
[[CPPrettyObject alloc] initWithValue:@"a" number:3],
|
||||
[[CPPrettyObject alloc] initWithValue:@"b" number:1],
|
||||
[[CPPrettyObject alloc] initWithValue:@"b" number:2],
|
||||
[[CPPrettyObject alloc] initWithValue:@"b" number:3],
|
||||
];
|
||||
|
||||
[target sortUsingDescriptors:descriptors];
|
||||
|
||||
[self assert:@"3:b" equals:[target[0] description]];
|
||||
[self assert:@"3:a" equals:[target[1] description]];
|
||||
[self assert:@"2:b" equals:[target[2] description]];
|
||||
[self assert:@"2:a" equals:[target[3] description]];
|
||||
[self assert:@"1:b" equals:[target[4] description]];
|
||||
[self assert:@"1:a" equals:[target[5] description]];
|
||||
}
|
||||
|
||||
- (void)testThatCPArrayDoesSortUsingDescriptorWithMultipleSameValues
|
||||
{
|
||||
var descriptors = [[[CPSortDescriptor alloc] initWithKey:@"intValue" ascending:NO]],
|
||||
target = [1, 1, 2, 4, 3, 1, 2, 4, 5, 1];
|
||||
|
||||
[target sortUsingDescriptors:descriptors];
|
||||
|
||||
[self assert:[5, 4, 4, 3, 2, 2, 1, 1, 1, 1] equals:target];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation CPPrettyObject : CPObject
|
||||
{
|
||||
CPString value @accessors;
|
||||
CPNumber number @accessors;
|
||||
}
|
||||
|
||||
- (id)initWithValue:(CPString)aValue number:(CPNumber)aNumber
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
{
|
||||
number = aNumber;
|
||||
value = aValue;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (CPString)description
|
||||
{
|
||||
return number + ":" + value;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation CopyableObject : CPObject
|
||||
{
|
||||
}
|
||||
|
||||
- (id)copy
|
||||
{
|
||||
return [[[self class] alloc] init];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation ConcreteMutableArray : CPMutableArray
|
||||
{
|
||||
Array array;
|
||||
}
|
||||
|
||||
- (id)initWithObjects:(id)anObject, ...
|
||||
{
|
||||
// The arguments array contains self and _cmd, so the first object is at position 2.
|
||||
var index = 2,
|
||||
count = arguments.length;
|
||||
|
||||
for (; index < count; ++index)
|
||||
if (arguments[index] === nil)
|
||||
break;
|
||||
|
||||
array = Array.prototype.slice.call(arguments, 2, index);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if (self)
|
||||
array = [];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithArray:(CPArray)anArray
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if (self)
|
||||
array = [anArray copy];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (CPUInteger)count
|
||||
{
|
||||
return array.length;
|
||||
}
|
||||
|
||||
- (id)objectAtIndex:(CPUInteger)anIndex
|
||||
{
|
||||
if (anIndex < 0 || anIndex >= [self count])
|
||||
throw "range error";
|
||||
|
||||
return array[anIndex];
|
||||
}
|
||||
|
||||
- (void)insertObject:(id)anObject atIndex:(CPUInteger)anIndex
|
||||
{
|
||||
array.splice(anIndex, 0, anObject);
|
||||
}
|
||||
|
||||
- (void)removeObjectAtIndex:(CPUInteger)anIndex
|
||||
{
|
||||
array.splice(anIndex, 1);
|
||||
}
|
||||
|
||||
- (void)addObject:(id)anObject
|
||||
{
|
||||
array.push(anObject);
|
||||
}
|
||||
|
||||
- (void)removeLastObject
|
||||
{
|
||||
array.pop();
|
||||
}
|
||||
|
||||
- (void)replaceObjectAtIndex:(CPUInteger)anIndex withObject:(id)anObject
|
||||
{
|
||||
array[anIndex] = anObject;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
@import <Foundation/Foundation.j>
|
||||
|
||||
@import "CPMutableArrayTest.j"
|
||||
|
||||
|
||||
@implementation _CPJavaScriptArrayTest : CPMutableArrayTest
|
||||
{
|
||||
}
|
||||
|
||||
+ (Class)arrayClass
|
||||
{
|
||||
return _CPJavaScriptArray;
|
||||
}
|
||||
|
||||
@end
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"version": "0.8.1"
|
||||
"version": "0.9.0"
|
||||
}
|
||||
Reference in new issue
Block a user