Merge branch 'master' of github.com:cappuccino/cappuccino into upstream

This commit is contained in:
Aparajita Fishman committed 2012-07-17 15:11:13 -07:00
commit b959f13a0c
3 files changed
+69

No files matched your search

+7
View File
@@ -978,6 +978,13 @@ NOT YET IMPLEMENTED
columnIndexes = [CPIndexSet indexSetWithIndexesInRange:CPMakeRange(fromIndex, toIndex)];
[self reloadDataForRowIndexes:rowIndexes columnIndexes:columnIndexes];
// Notify even if programmatically moving a column as in Cocoa.
// TODO Only notify when a column drag operation ends, not each time a column reaches a new slot?
[[CPNotificationCenter defaultCenter] postNotificationName:CPTableViewColumnDidMoveNotification
object:self
userInfo:[CPDictionary dictionaryWithObjects:[fromIndex, toIndex]
forKeys:[@"CPOldColumn", @"CPNewColumn"]]];
}
/*!
+26
View File
@@ -654,6 +654,32 @@
var value = [self objectForKey:aKey];
return ((value !== nil) && (value !== undefined));
}
- (void)enumerateKeysAndObjectsUsingBlock:(Function /*(id aKey, id anObject, @ref BOOL stop)*/)aFunction
{
var shouldStop = NO,
shouldStopRef = AT_REF(shouldStop);
for (var index = 0; index < _count; index++)
{
var key = _keys[index],
value = valueForKey(key);
aFunction(key, value, shouldStopRef);
if (shouldStop)
return;
}
}
- (void)enumerateKeysAndObjectsWithOptions:(CPEnumerationOptions)opts usingBlock:(Function /*(id aKey, id anObject, @ref BOOL stop)*/)aFunction
{
// Ignore the options because neither option has an effect.
// CPEnumerationReverse has no effect on enumerating a CPDictionary because dictionary enumeration is not ordered.
// CPEnumerationConcurrent is not possible in a single threaded environment.
[self enumerateKeysAndObjectsUsingBlock:aFunction];
}
@end
@implementation CPDictionary (CPCoding)
+36
View File
@@ -348,6 +348,42 @@
[self assert:expected equals:result];
}
- (void)testEnumerateKeysAndObjectsUsingBlock_
{
var input0 = [CPDictionary dictionary],
input1 = [CPDictionary dictionaryWithJSObject:{a: 1, b: 3, c: "b"}],
output = [CPMutableDictionary dictionary],
outputFunction = function(aKey, anObject)
{
[output setValue:anObject forKey:aKey];
};
[input0 enumerateKeysAndObjectsUsingBlock:outputFunction];
[self assert:0 equals:[output count] message:@"output when enumerating empty dictionary"];
[input1 enumerateKeysAndObjectsUsingBlock:outputFunction];
[self assert:3 equals:[output count] message:@"output when enumerating input1"];
[self assert:input1 equals:output message:@"output should equal input"];
// Stop enumerating after two keys.
output = [CPMutableDictionary dictionary];
stoppingFunction = function(aKey, anObject, stop)
{
[output setValue:anObject forKey:aKey];
if ([output count] > 1)
stop(YES); // AT_DEREF(stop, YES) - FIXME Replace with proper @ref @deref when in ObjJ.
}
[input1 enumerateKeysAndObjectsUsingBlock:stoppingFunction];
[self assert:2 equals:[output count] message:@"output when enumerating input1 and stopping after 2"];
// CPEnumerationReverse shouldn't have any particular effect. Just check that it doesn't crash.
output = [CPMutableDictionary dictionary];
[input1 enumerateKeysAndObjectsWithOptions:CPEnumerationReverse usingBlock:outputFunction];
[self assert:3 equals:[output count] message:@"output when enumerating input1"];
[self assert:input1 equals:output message:@"output should equal input"];
}
- (void)testJSObjectDescription
{
var dict = [[CPDictionary alloc] initWithObjects:[CGRectMake(1, 2, 3, 4), CGPointMake(5, 6)] forKeys:[@"key1", @"key2"]],