mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-25 04:57:03 +00:00
Fixed: CPAttributedString isEqual: despite attribute differences.
As soon as a range reached the end of the string the equality test would end with a YES, without even comparing the final attribute dict.
This commit is contained in:
@@ -413,7 +413,7 @@
|
||||
comparisonAttributes = [aString attributesAtIndex:0 effectiveRange:comparisonRange],
|
||||
length = _string.length;
|
||||
|
||||
while (CPMaxRange(CPUnionRange(myRange, comparisonRange)) < length)
|
||||
do
|
||||
{
|
||||
if (CPIntersectionRange(myRange, comparisonRange).length > 0 &&
|
||||
![myAttributes isEqualToDictionary:comparisonAttributes])
|
||||
@@ -424,7 +424,7 @@
|
||||
myAttributes = [self attributesAtIndex:CPMaxRange(myRange) effectiveRange:myRange];
|
||||
else
|
||||
comparisonAttributes = [aString attributesAtIndex:CPMaxRange(comparisonRange) effectiveRange:comparisonRange];
|
||||
}
|
||||
} while (CPMaxRange(CPUnionRange(myRange, comparisonRange)) < length);
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
@@ -207,6 +207,38 @@ var sharedObject = [CPObject new];
|
||||
[self assertFalse:[a isEqual:@"HELLO!"] message:"Expected a to not equal 'HELLO!', but it did"];
|
||||
}
|
||||
|
||||
- (void)testIsEqualEmpty
|
||||
{
|
||||
var a = [[CPMutableAttributedString alloc] initWithString:@""],
|
||||
b = [[CPMutableAttributedString alloc] initWithString:@""];
|
||||
|
||||
[self assertTrue:[a isEqual:b]];
|
||||
}
|
||||
|
||||
- (void)testIsEqualWithSimpleAttribute
|
||||
{
|
||||
var a = [[CPMutableAttributedString alloc] initWithString:@"GREETINGS!"],
|
||||
b = [[CPMutableAttributedString alloc] initWithString:@"GREETINGS!"];
|
||||
|
||||
[a addAttribute:"color" value:[CPColor redColor] range:CPMakeRange(0, 5)];
|
||||
[self assertFalse:[a isEqual:b] message:"red string should not equal string without color attribute"];
|
||||
[b addAttribute:"color" value:[CPColor redColor] range:CPMakeRange(0, 5)];
|
||||
[self assertTrue:[a isEqual:b]];
|
||||
}
|
||||
|
||||
- (void)testIsEqualWithTwoAttributes
|
||||
{
|
||||
var a = [[CPMutableAttributedString alloc] initWithString:@"GREETINGS!"],
|
||||
b = [[CPMutableAttributedString alloc] initWithString:@"GREETINGS!"];
|
||||
|
||||
[a addAttribute:"color" value:[CPColor redColor] range:CPMakeRange(0, 9)];
|
||||
[b addAttribute:"color" value:[CPColor redColor] range:CPMakeRange(0, 9)];
|
||||
[a addAttribute:"font" value:"Helvetica" range:CPMakeRange(1, 4)];
|
||||
[self assertFalse:[a isEqual:b] message:"font difference from index 1 should be found"];
|
||||
[b addAttribute:"font" value:"Helvetica" range:CPMakeRange(1, 4)];
|
||||
[self assertTrue:[a isEqual:b]];
|
||||
}
|
||||
|
||||
//Extracting a Substring
|
||||
//- (CPAttributedString)attributedSubstringFromRange:(CPRange)aRange
|
||||
- (void)testAttributedSubstringFromRange
|
||||
|
||||
Reference in New Issue
Block a user