mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-10-15 04:54:29 +00:00
Raise CPRangeException if CPString substringToIndex: is out of bounds.
This commit is contained in:
1 parent
7a1cd5c545
commit
c77a282aaf
2 files changed
+15
No files matched your search
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user