Raise CPRangeException if CPString substringToIndex: is out of bounds.

This commit is contained in:
Alexander Ljungberg committed 2011-08-27 23:50:18 +01:00
1 parent 7a1cd5c545
commit c77a282aaf
2 files changed
+15

No files matched your search

+3
View File
@@ -314,6 +314,9 @@ var CPStringRegexSpecialCharacters = [
*/
- (CPString)substringToIndex:(unsigned)anIndex
{
if (anIndex > length)
[CPException raise:CPRangeException reason:"index out of bounds"];
return substring(0, anIndex);
}
+12
View File
@@ -128,6 +128,18 @@
[self assert:"abcd" equals:["abcd" substringToIndex:4]];
[self assert:"abc" equals:["abcd" substringToIndex:3]];
[self assert:"" equals:["abcd" substringToIndex:0]];
var sawException = false;
try
{
[@"abcd" substringToIndex:5];
}
catch (anException)
{
sawException = true;
[self assert:CPRangeException equals:[anException name]];
}
[self assertTrue:sawException message:"expected CPRangeException"];
}
- (void)testBoolValue