From de04c727679909bd752aab4639bef1851292adb3 Mon Sep 17 00:00:00 2001 From: cacaodev Date: Fri, 13 Jul 2012 21:47:39 +0200 Subject: [PATCH] CPDictionary -initWithObjectsAndKeys: skip a nil key instead of breaking --- Foundation/CPDictionary.j | 2 +- Tests/Foundation/CPDictionaryTest.j | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Foundation/CPDictionary.j b/Foundation/CPDictionary.j index 17e3d14bb..5884be2ea 100755 --- a/Foundation/CPDictionary.j +++ b/Foundation/CPDictionary.j @@ -299,7 +299,7 @@ var value = arguments[index]; if (value === nil) - break; + continue; [self setObject:value forKey:arguments[index + 1]]; } diff --git a/Tests/Foundation/CPDictionaryTest.j b/Tests/Foundation/CPDictionaryTest.j index 2760de479..0904858a6 100644 --- a/Tests/Foundation/CPDictionaryTest.j +++ b/Tests/Foundation/CPDictionaryTest.j @@ -250,4 +250,13 @@ [self assertTrue:d.indexOf("y: 6") !== -1 message:"Can't find 'y: 6' in description of dictionary " + d]; } +- (void)testInitWithObjectsAndKeys +{ + var dict = [[CPDictionary alloc] initWithObjectsAndKeys:@"Value1", @"Key1", nil, @"Key2", @"Value3", @"Key3"]; + + [self assert:2 equals:[dict count]]; + [self assert:@"Value1" equals:[dict objectForKey:@"Key1"]]; + [self assert:nil equals:[dict objectForKey:@"Key2"]]; // No key/value pair + [self assert:@"Value3" equals:[dict objectForKey:@"Key3"]]; +} @end