Moved new description functionallity from CFDictionary to CPDictionary.

Added testcase for both CPDictionary and CPArray. Fixed failing testcase.
Checked all new code with capp_lint for correct formatting.
This commit is contained in:
Martin Carlberg committed 2012-05-14 10:14:05 +02:00
1 parent 327debe3a8
commit 0abd9855c2
6 files changed
+52 -15

No files matched your search

+14 -1
View File
@@ -576,7 +576,20 @@
*/
- (CPString)description
{
return self.toString();
var string = "{\n\t",
keys = _keys,
index = 0,
count = _count;
for (; index < count; ++index)
{
var key = keys[index],
value = valueForKey(key);
string += key + " = \"" + CPDescriptionOfObject(value).split('\n').join("\n\t") + "\"\n\t";
}
return string + "}";
}
- (BOOL)containsKey:(id)aKey
+2 -2
View File
@@ -543,9 +543,9 @@ function CPDescriptionOfObject(anObject)
for (var property in anObject)
{
if (anObject.hasOwnProperty(property))
desc += " " + property + ":" + CPDescriptionOfObject(anObject[property]) + "\n";
desc += " " + property + ": " + CPDescriptionOfObject(anObject[property]) + "\n";
}
desc += "}";
return desc.split('\n').join("\n\t");
}
+9 -10
View File
@@ -135,19 +135,18 @@ DISPLAY_NAME(CFDictionary.prototype.valueForKey);
CFDictionary.prototype.toString = function()
{
var string = "{\n\t",
keys = this._keys,
index = 0,
count = this._count;
var string = "{\n",
keys = this._keys,
index = 0,
count = this._count;
for (; index < count; ++index)
{
var key = keys[index],
value = this.valueForKey(key);
string += key + " = \"" + CPDescriptionOfObject(value).split('\n').join("\n\t") + "\"\n\t";
var key = keys[index];
string += "\t" + key + " = \"" + String(this.valueForKey(key)).split('\n').join("\n\t") + "\"\n";
}
return string + "}";
};
+12
View File
@@ -526,6 +526,18 @@
[self assert:input1[1] equals:[output valueForKey:"1"] message:@"output[0]"];
}
- (void)testJSObjectDescription
{
var array = [CGRectMake(1, 2, 3, 4), CGPointMake(5, 6)],
d = [array description];
[self assertTrue:d.indexOf("x: 1") !== -1 message:"Can't find 'x: 1' in description of array " + d];
[self assertTrue:d.indexOf("y: 2") !== -1 message:"Can't find 'y: 2' in description of array " + d];
[self assertTrue:d.indexOf("width: 3") !== -1 message:"Can't find 'width: 3' in description of array " + d];
[self assertTrue:d.indexOf("height: 4") !== -1 message:"Can't find 'height: 4' in description of array " + d];
[self assertTrue:d.indexOf("x: 5") !== -1 message:"Can't find 'x: 5' in description of array " + d];
[self assertTrue:d.indexOf("y: 6") !== -1 message:"Can't find 'y: 6' in description of array " + d];
}
@end
+13
View File
@@ -237,4 +237,17 @@
[self assert:expected equals:result];
}
- (void)testJSObjectDescription
{
var dict = [[CPDictionary alloc] initWithObjects:[CGRectMake(1, 2, 3, 4), CGPointMake(5, 6)] forKeys:[@"key1", @"key2"]],
d = [dict description];
[self assertTrue:d.indexOf("x: 1") !== -1 message:"Can't find 'x: 1' in description of dictionary " + d];
[self assertTrue:d.indexOf("y: 2") !== -1 message:"Can't find 'y: 2' in description of dictionary " + d];
[self assertTrue:d.indexOf("width: 3") !== -1 message:"Can't find 'width: 3' in description of dictionary " + d];
[self assertTrue:d.indexOf("height: 4") !== -1 message:"Can't find 'height: 4' in description of dictionary " + d];
[self assertTrue:d.indexOf("x: 5") !== -1 message:"Can't find 'x: 5' in description of dictionary " + d];
[self assertTrue:d.indexOf("y: 6") !== -1 message:"Can't find 'y: 6' in description of dictionary " + d];
}
@end
+2 -2
View File
@@ -380,11 +380,11 @@
[pretty sortUsingDescriptors:[[[CPSortDescriptor alloc] initWithKey:@"value" ascending:NO]]];
[self assert:"(\n\t3:d, \n\t2:c, \n\t1:b, \n\t0:a\n)" equals:[pretty description]];
[self assert:"(\n\t3:d,\n\t2:c,\n\t1:b,\n\t0:a\n)" equals:[pretty description]];
[pretty sortUsingDescriptors:[[[CPSortDescriptor alloc] initWithKey:@"value" ascending:YES]]];
[self assert:"(\n\t0:a, \n\t1:b, \n\t2:c, \n\t3:d\n)" equals:[pretty description]]
[self assert:"(\n\t0:a,\n\t1:b,\n\t2:c,\n\t3:d\n)" equals:[pretty description]]
}
- (void)testThatCPArrayDoesSortUsingTwoDescriptors