Fixed: The init method ’initWithObjects:count:’ for CPArray did not work on native CPJavaScriptArray when ’count’ is not the same as the length on the provided array.

A test case for this is also added in the test class CPArrayTest
This commit is contained in:
Martin Carlberg committed 2015-09-25 17:07:15 +02:00
1 parent 448c2a27d4
commit 8599ad4a3c
3 files changed
+41 -1

No files matched your search

+1 -1
View File
@@ -91,7 +91,7 @@ var concat = Array.prototype.concat,
- (id)initWithObjects:(CPArray)objects count:(CPUInteger)aCount
{
if ([objects isKindOfClass:_CPJavaScriptArray])
return slice.call(objects, 0);
return slice.call(objects, 0, aCount);
var array = [],
index = 0;
+25
View File
@@ -11,6 +11,16 @@
return ConcreteArray;
}
- (void)test_initWithObjects_count_
{
var arrayClass = [[self class] arrayClass],
array = [[arrayClass alloc] initWithObjects:[@"hello", @"bye", @"goodnight", @"seeya"] count:2];
[self assert:[array count] equals:2];
[self assert:[array objectAtIndex:0] equals:@"hello"];
[self assert:[array objectAtIndex:1] equals:@"bye"];
}
- (void)test_containsObject_
{
var arrayClass = [[self class] arrayClass],
@@ -763,6 +773,21 @@
return self;
}
- (id)initWithObjects:(CPArray)objects count:(CPUInteger)aCount
{
self = [super init];
if (self)
{
array = [];
for (var index = 0; index < aCount; ++index)
array.push([objects objectAtIndex:index]);
}
return self;
}
- (CPUInteger)count
{
return array.length;
+15
View File
@@ -555,6 +555,21 @@
return self;
}
- (id)initWithObjects:(CPArray)objects count:(CPUInteger)aCount
{
self = [super init];
if (self)
{
array = [];
for (var index = 0; index < aCount; ++index)
array.push([objects objectAtIndex:index]);
}
return self;
}
- (CPUInteger)count
{
return array.length;