mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-25 13:07:02 +00:00
Unit test KVCArray setArray: behaviour.
This commit is contained in:
@@ -15,7 +15,7 @@ var COUNTER;
|
||||
COUNTER = 0;
|
||||
}
|
||||
|
||||
- (void)_patchSelector:(SEL)theSelector
|
||||
- (void)_patchSelector:(SEL)selectors, ...
|
||||
{
|
||||
var method_dtable = [[self object] class].method_dtable,
|
||||
method_list = [[self object] class].method_list,
|
||||
@@ -40,10 +40,14 @@ var COUNTER;
|
||||
[method_list removeObject:implementation];
|
||||
}
|
||||
|
||||
var method = class_getInstanceMethod([[self implementedObject] class], theSelector),
|
||||
implementation = method_getImplementation(method);
|
||||
for (var i = 2; i < arguments.length; i++)
|
||||
{
|
||||
var theSelector = arguments[i],
|
||||
method = class_getInstanceMethod([[self implementedObject] class], theSelector),
|
||||
implementation = method_getImplementation(method);
|
||||
|
||||
class_addMethod([[self object] class], theSelector, implementation);
|
||||
class_addMethod([[self object] class], theSelector, implementation);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)testUsesCountOfKey
|
||||
@@ -299,6 +303,20 @@ var COUNTER;
|
||||
message:@"replaceObjectInValuesAtIndexes:withValues: should have been called once"];
|
||||
}
|
||||
|
||||
- (void)testSetArray
|
||||
{
|
||||
[self _patchSelector:@selector(removeObjectFromValuesAtIndex:), @selector(insertObject:inValuesAtIndex:)];
|
||||
|
||||
// This should result in all 10 objects being removed from the values and the 2 new ones being inserted
|
||||
// in a KVO compliant manner.
|
||||
[[[self object] mutableArrayValueForKey:@"values"] setArray:[88, 99]];
|
||||
|
||||
[self assert:[88, 99] equals:[[self object] values]];
|
||||
[self assert:12
|
||||
equals:COUNTER
|
||||
message:@"removeObjectFromValuesAtIndex: should have been called 10 times and insertObject:inValuesAtIndex: 2 times"];
|
||||
}
|
||||
|
||||
- (void)testKVCArrayOperators
|
||||
{
|
||||
var one = [1, 1, 1, 1, 1, 1, 1, 1],
|
||||
@@ -382,7 +400,7 @@ var COUNTER;
|
||||
|
||||
- (void)insertObject:(id)theObject inValuesAtIndex:(int)theIndex
|
||||
{
|
||||
// CPLog.warn(@"insertObject: %@ inValuesAtIndex: %@", theObject, theIndex);
|
||||
CPLog.warn(@"insertObject: %@ inValuesAtIndex: %@", theObject, theIndex);
|
||||
|
||||
COUNTER += 1;
|
||||
[[self values] insertObject:theObject atIndex:theIndex];
|
||||
@@ -398,7 +416,7 @@ var COUNTER;
|
||||
|
||||
- (void)removeObjectFromValuesAtIndex:(int)theIndex
|
||||
{
|
||||
// CPLog.warn(@"removeObjectFromValuesAtIndex: %@", theIndex);
|
||||
CPLog.warn(@"removeObjectFromValuesAtIndex: %@", theIndex);
|
||||
|
||||
COUNTER += 1;
|
||||
[[self values] removeObjectAtIndex:theIndex];
|
||||
|
||||
Reference in New Issue
Block a user