mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-25 21:17:03 +00:00
CPScanner: When the scanner did not accumulate any string, do not change (to nil) the object passed as a ref in ...intoSring:ref() methods. With tests.
This commit is contained in:
@@ -140,11 +140,14 @@
|
||||
- (BOOL)_performScanWithSelector:(SEL)s withObject:(id)arg into:(id)ref
|
||||
{
|
||||
var ret = [self performSelector:s withObject:arg];
|
||||
|
||||
|
||||
if (ret == nil)
|
||||
return NO;
|
||||
|
||||
if (ref != nil)
|
||||
ref(ret);
|
||||
|
||||
return ret != NULL;
|
||||
return YES;
|
||||
}
|
||||
|
||||
/* ================================ */
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
@import <Foundation/Foundation.j>
|
||||
|
||||
@implementation CPScannerTest : OJTestCase
|
||||
{
|
||||
}
|
||||
|
||||
- (void)testNothingScanned
|
||||
{
|
||||
var x = @"x",
|
||||
str = x,
|
||||
scanner,
|
||||
result;
|
||||
|
||||
scanner = [CPScanner scannerWithString:@"a"];
|
||||
result = [scanner scanString:@"b" intoString:str];
|
||||
[self assertFalse:result message:"Result should be FALSE"];
|
||||
[self assertTrue:str === x message:"The string passed by reference should not change, is " + str];
|
||||
|
||||
scanner = [CPScanner scannerWithString:@"a"];
|
||||
result = [scanner scanUpToString:@"a" intoString:str];
|
||||
[self assertFalse:result message:"Result should be FALSE"];
|
||||
[self assertTrue:str === x message:"The string passed by reference should not change, is " + str];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user