Skip to content

Commit

Permalink
Merge branch 'master' of github.com:cappuccino/cappuccino into upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
Aparajita Fishman committed Jul 17, 2012
2 parents f0163e1 + a89ca14 commit b959f13
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
7 changes: 7 additions & 0 deletions AppKit/CPTableView.j
Expand Up @@ -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"]]];
}

/*!
Expand Down
26 changes: 26 additions & 0 deletions Foundation/CPDictionary.j
Expand Up @@ -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)
Expand Down
36 changes: 36 additions & 0 deletions Tests/Foundation/CPDictionaryTest.j
Expand Up @@ -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"]],
Expand Down

0 comments on commit b959f13

Please sign in to comment.