Permalink
Browse files

- more tests with empty string

  • Loading branch information...
1 parent 208cfad commit 42b8552463cb2f4764086bef68a02cf8058f02f3 @emaillard committed Mar 10, 2010
Showing with 15 additions and 2 deletions.
  1. +15 −2 Tests/Foundation/CPAttributedStringTest.j
@@ -577,11 +577,20 @@ var sharedObject = [CPObject new];
[self assertTrue:value===1 message:"expected value to be '1', was: "+value];
[self assertTrue:CPEqualRanges(range, CPMakeRange(32, 13)) message:"expected key to be valid across {32, 13}, was: "+CPStringFromRange(range)];
+ /* test on an empty string */
string = [[CPAttributedString alloc] initWithString:""];
range = CPMakeRange(0, 0);
- [string replaceCharactersInRange:range withAttributedString:[[CPAttributedString alloc] initWithString:@"foo"]];
+ var attributes = [CPDictionary dictionaryWithObject:@"value" forKey:@"key"];
+ [string replaceCharactersInRange:range withAttributedString:[[CPAttributedString alloc] initWithString:@"foo" attributes:[attributes copy]]];
+
[self assertTrue:[string string]==="foo" message:"inserting foo using range "+CPStringFromRange(range)+" produced: "+[string string]];
+ var effectiveRange = CPMakeRange(0, 0),
+ assignedAttributes = [string attributesAtIndex:0 effectiveRange:effectiveRange];
+
+ [self assertTrue:[attributes isEqualToDictionary:assignedAttributes] message:"attributes differt should be { key = \"value\" } get "+[assignedAttributes description]];
+ [self assertTrue:CPEqualRanges(effectiveRange, CPMakeRange(0,3)) message:"effectiveRange should be {0, 3} get "+CPStringFromRange(effectiveRange)];
+
range = CPMakeRange([string length], 0);
[string replaceCharactersInRange:range withAttributedString:[[CPAttributedString alloc] initWithString:@"bar"]];
[self assertTrue:[string string]==="foobar" message:"inserting bar after foo using range "+CPStringFromRange(range)+" produced: "+[string string]];
@@ -593,7 +602,11 @@ var sharedObject = [CPObject new];
var string = [[CPAttributedString alloc] initWithString:"HELLO THERE"];
[string setAttributedString:[self stringForTesting]];
- [self assertTrue:[[self stringForTesting] isEqual:string] message:"setAttributedString should have made strings equal, but they were not"];
+ [self assertTrue:[[self stringForTesting] isEqual:string] message:"setAttributedString should have made strings equal, but they were not"];
+
+ string = [[CPAttributedString alloc] initWithString:""];
+ [string setAttributedString:[self stringForTesting]];
+ [self assertTrue:[[self stringForTesting] isEqual:string] message:"setAttributedString should have made strings equal, but they were not"];
}
@end

0 comments on commit 42b8552

Please sign in to comment.