2011-02-16 08:21:17 +00:00
|
|
|
#import "Testing.h"
|
|
|
|
#import <Foundation/NSAttributedString.h>
|
|
|
|
#import <Foundation/NSAutoreleasePool.h>
|
|
|
|
|
2018-02-07 09:48:56 +00:00
|
|
|
@interface NSMutableAttributedString(evil)
|
|
|
|
-(void) _sanity;
|
|
|
|
@end
|
|
|
|
#if !defined(GNUSTEP_BASE_LIBRARY)
|
|
|
|
@implementation NSMutableAttributedString(evil)
|
|
|
|
- (void) _sanity
|
|
|
|
{
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
#endif
|
|
|
|
|
2013-02-15 09:21:32 +00:00
|
|
|
@interface NSColor : NSObject
|
|
|
|
+ (id) redColor;
|
|
|
|
+ (id) blueColor;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSColor
|
|
|
|
+ (id) redColor;
|
|
|
|
{
|
|
|
|
return [[self new] autorelease];
|
|
|
|
}
|
|
|
|
+ (id) blueColor;
|
|
|
|
{
|
|
|
|
return [[self new] autorelease];
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
NSString *NSForegroundColorAttributeName = @"NSForegroundColorAttributeName";
|
|
|
|
|
|
|
|
|
2011-02-16 08:21:17 +00:00
|
|
|
@interface NSMutableAttributedString (TestingAdditions)
|
2018-02-07 09:48:56 +00:00
|
|
|
-(BOOL)checkAttributes: (NSDictionary *)attr location: (int)location;
|
|
|
|
-(BOOL)checkAttributes: (NSDictionary *)attr range: (NSRange)range;
|
2011-02-16 08:21:17 +00:00
|
|
|
@end
|
|
|
|
@implementation NSMutableAttributedString (TestingAdditions)
|
2018-02-07 09:48:56 +00:00
|
|
|
-(BOOL) checkAttributes: (NSDictionary *)attr location: (int)loc
|
2011-02-16 08:21:17 +00:00
|
|
|
{
|
|
|
|
return [[self attributesAtIndex:loc
|
|
|
|
effectiveRange:NULL] isEqual:attr];
|
|
|
|
}
|
|
|
|
|
2018-02-07 09:48:56 +00:00
|
|
|
-(BOOL) checkAttributes: (NSDictionary *)attr range: (NSRange)range
|
2011-02-16 08:21:17 +00:00
|
|
|
{
|
|
|
|
NSRange aRange = range;
|
|
|
|
|
|
|
|
while (aRange.length > 0)
|
|
|
|
{
|
|
|
|
BOOL attrEqual;
|
2018-02-07 09:48:56 +00:00
|
|
|
attrEqual= [[self attributesAtIndex: aRange.location + (aRange.length - 1)
|
|
|
|
effectiveRange: NULL] isEqual: attr];
|
2011-02-16 08:21:17 +00:00
|
|
|
if (attrEqual == NO)
|
|
|
|
return NO;
|
|
|
|
|
|
|
|
aRange.length -= 1;
|
|
|
|
}
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
|
|
|
NSMutableAttributedString *attrStr;
|
|
|
|
NSString *baseString = @"0123456789";
|
|
|
|
NSDictionary *red, *gray, *blue;
|
|
|
|
|
2013-02-15 09:21:32 +00:00
|
|
|
NSMutableAttributedString *s;
|
|
|
|
s = [[[NSMutableAttributedString alloc]
|
|
|
|
initWithString: @"string"] autorelease];
|
2018-02-07 09:48:56 +00:00
|
|
|
[s _sanity];
|
2013-02-15 09:21:32 +00:00
|
|
|
PASS_EQUAL([s string], @"string", "equality OK for string value");
|
|
|
|
PASS([s length] == 6, "length reported correctly");
|
|
|
|
PASS_EQUAL([s attributesAtIndex: 0 effectiveRange: NULL],
|
|
|
|
[NSDictionary dictionary], "empty range has empty attributes dictionary");
|
|
|
|
[s setAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
[NSColor redColor], NSForegroundColorAttributeName, nil]
|
|
|
|
range: NSMakeRange(0, 3)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[s _sanity];
|
2013-02-15 09:21:32 +00:00
|
|
|
PASS([[s attributesAtIndex: 0 effectiveRange: NULL] count] == 1,
|
|
|
|
"newly set attribute dictionary contains one attribute");
|
|
|
|
PASS([[s attributesAtIndex: 3 effectiveRange: NULL] count] == 0,
|
|
|
|
"attribute dictionary at 3 contains no attributes");
|
|
|
|
[s setAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
[NSColor blueColor], NSForegroundColorAttributeName, nil]
|
|
|
|
range: NSMakeRange(3, 3)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[s _sanity];
|
2013-02-15 09:21:32 +00:00
|
|
|
PASS([[s attributesAtIndex: 0 effectiveRange: NULL] count] == 1,
|
|
|
|
"attribute count at 0 unchanged");
|
|
|
|
PASS([[s attributesAtIndex: 3 effectiveRange: NULL] count] == 1,
|
|
|
|
"new attribute count is 1");
|
|
|
|
|
2011-02-16 08:21:17 +00:00
|
|
|
red = [NSDictionary dictionaryWithObject:@"Red" forKey:@"Color"];
|
|
|
|
gray = [NSDictionary dictionaryWithObject:@"Gray" forKey:@"Color"];
|
|
|
|
blue = [NSDictionary dictionaryWithObject:@"Blue" forKey:@"Color"];
|
|
|
|
|
|
|
|
attrStr = [[NSMutableAttributedString alloc] initWithString:baseString
|
|
|
|
attributes:red];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
PASS([[attrStr string] isEqual:baseString] &&
|
|
|
|
[attrStr checkAttributes:red range:NSMakeRange(0,10)],
|
|
|
|
"-initWithString:attributes: works");
|
|
|
|
|
|
|
|
[attrStr setAttributes:blue range:NSMakeRange(0,10)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
PASS([attrStr checkAttributes:blue range:NSMakeRange(0,10)],
|
|
|
|
"-setAttributes:range: works for the whole string");
|
|
|
|
|
|
|
|
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
|
|
|
|
attributes:red]);
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:blue range:NSMakeRange(0,5)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
PASS([attrStr checkAttributes:blue range:NSMakeRange(0,5)] &&
|
|
|
|
[attrStr checkAttributes:red range:NSMakeRange(5,5)],
|
|
|
|
"-setAttributes:range: works for the first half of the string");
|
|
|
|
|
|
|
|
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
|
|
|
|
attributes:red]);
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:blue range:NSMakeRange(3,5)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
PASS([attrStr checkAttributes:red range:NSMakeRange(0,3)] &&
|
|
|
|
[attrStr checkAttributes:blue range:NSMakeRange(3,5)] &&
|
|
|
|
[attrStr checkAttributes:red range:NSMakeRange(8,2)],
|
|
|
|
"-setAttributes:range: works for the middle of the string");
|
|
|
|
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr setAttributes:blue range:NSMakeRange(4,3)];
|
|
|
|
[attrStr _sanity];
|
|
|
|
PASS([attrStr checkAttributes:red range:NSMakeRange(0,3)] &&
|
|
|
|
[attrStr checkAttributes:blue range:NSMakeRange(3,5)] &&
|
|
|
|
[attrStr checkAttributes:red range:NSMakeRange(8,2)],
|
|
|
|
"-setAttributes:range: works for same attributes in middle of string");
|
|
|
|
|
2011-02-16 08:21:17 +00:00
|
|
|
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
|
|
|
|
attributes:red]);
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:blue range:NSMakeRange(5,5)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
PASS([attrStr checkAttributes:red range:NSMakeRange(0,5)] &&
|
|
|
|
[attrStr checkAttributes:blue range:NSMakeRange(5,5)],
|
|
|
|
"-setAttributes:range: works for the last half of the string");
|
|
|
|
|
|
|
|
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
|
|
|
|
attributes:red]);
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:blue range:NSMakeRange(0,3)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:red range:NSMakeRange(3,4)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:gray range:NSMakeRange(7,3)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
PASS([attrStr checkAttributes:blue range:NSMakeRange(0,3)] &&
|
|
|
|
[attrStr checkAttributes:red range:NSMakeRange(3,4)] &&
|
|
|
|
[attrStr checkAttributes:gray range:NSMakeRange(7,3)],
|
|
|
|
"-setAttributes:range: works in three parts of the string");
|
|
|
|
|
|
|
|
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
|
|
|
|
attributes:red]);
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:blue range:NSMakeRange(0,5)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:red range:NSMakeRange(3,5)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:gray range:NSMakeRange(4,5)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
PASS([attrStr checkAttributes:blue range:NSMakeRange(0,3)] &&
|
|
|
|
[attrStr checkAttributes:red range:NSMakeRange(3,1)] &&
|
|
|
|
[attrStr checkAttributes:gray range:NSMakeRange(4,5)] &&
|
|
|
|
[attrStr checkAttributes:red range:NSMakeRange(9,1)],
|
|
|
|
"-setAttributes:range: works with overlapping");
|
|
|
|
|
|
|
|
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
|
|
|
|
attributes:red]);
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:blue range:NSMakeRange(1,2)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:blue range:NSMakeRange(4,2)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:blue range:NSMakeRange(7,2)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:gray range:NSMakeRange(2,6)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
PASS([attrStr checkAttributes:red range:NSMakeRange(0,1)] &&
|
|
|
|
[attrStr checkAttributes:blue range:NSMakeRange(1,1)] &&
|
|
|
|
[attrStr checkAttributes:gray range:NSMakeRange(2,6)] &&
|
|
|
|
[attrStr checkAttributes:blue range:NSMakeRange(8,1)] &&
|
|
|
|
[attrStr checkAttributes:red range:NSMakeRange(9,1)],
|
|
|
|
"-setAttributes:range: works with overlapping (2)");
|
|
|
|
|
|
|
|
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
|
|
|
|
attributes:red]);
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:blue range:NSMakeRange(2,5)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:gray range:NSMakeRange(2,5)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
PASS([attrStr checkAttributes:red range:NSMakeRange(0,2)] &&
|
|
|
|
[attrStr checkAttributes:gray range:NSMakeRange(2,5)] &&
|
|
|
|
[attrStr checkAttributes:red range:NSMakeRange(7,3)],
|
|
|
|
"-setAttributes:range: works with replacing");
|
|
|
|
|
|
|
|
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
|
|
|
|
attributes:red]);
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:blue range:NSMakeRange(1,8)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:red range:NSMakeRange(2,6)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:gray range:NSMakeRange(3,4)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
PASS([attrStr checkAttributes:red range:NSMakeRange(0,1)] &&
|
|
|
|
[attrStr checkAttributes:blue range:NSMakeRange(1,1)] &&
|
|
|
|
[attrStr checkAttributes:red range:NSMakeRange(2,1)] &&
|
|
|
|
[attrStr checkAttributes:gray range:NSMakeRange(3,4)] &&
|
|
|
|
[attrStr checkAttributes:red range:NSMakeRange(7,1)] &&
|
|
|
|
[attrStr checkAttributes:blue range:NSMakeRange(8,1)] &&
|
|
|
|
[attrStr checkAttributes:red range:NSMakeRange(9,1)],
|
|
|
|
"-setAttributes:range: works with chinese boxes");
|
|
|
|
|
|
|
|
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
|
|
|
|
attributes:red]);
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:blue range:NSMakeRange(1,3)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:gray range:NSMakeRange(1,4)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
PASS([attrStr checkAttributes:red range:NSMakeRange(0,1)] &&
|
|
|
|
[attrStr checkAttributes:gray range:NSMakeRange(1,4)] &&
|
|
|
|
[attrStr checkAttributes:red range:NSMakeRange(5,5)],
|
|
|
|
"-setAttributes:range: works with extending at the end (diff color)");
|
|
|
|
|
|
|
|
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
|
|
|
|
attributes:red]);
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:gray range:NSMakeRange(1,3)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:gray range:NSMakeRange(1,4)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
PASS([attrStr checkAttributes:red range:NSMakeRange(0,1)] &&
|
|
|
|
[attrStr checkAttributes:gray range:NSMakeRange(1,4)] &&
|
|
|
|
[attrStr checkAttributes:red range:NSMakeRange(5,5)],
|
|
|
|
"-setAttributes:range: works with extending at the end (diff color)");
|
|
|
|
|
|
|
|
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
|
|
|
|
attributes:red]);
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:blue range:NSMakeRange(2,3)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:gray range:NSMakeRange(1,4)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
PASS([attrStr checkAttributes:red range:NSMakeRange(0,1)] &&
|
|
|
|
[attrStr checkAttributes:gray range:NSMakeRange(1,4)] &&
|
|
|
|
[attrStr checkAttributes:red range:NSMakeRange(5,5)],
|
|
|
|
"-setAttributes:range: works with extending at the beginning (diff color)");
|
|
|
|
|
|
|
|
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
|
|
|
|
attributes:red]);
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:gray range:NSMakeRange(2,3)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:gray range:NSMakeRange(1,4)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
PASS([attrStr checkAttributes:red range:NSMakeRange(0,1)] &&
|
|
|
|
[attrStr checkAttributes:gray range:NSMakeRange(1,4)] &&
|
|
|
|
[attrStr checkAttributes:red range:NSMakeRange(5,5)],
|
|
|
|
"-setAttributes:range: works with extending at the beginning (same color)");
|
|
|
|
|
|
|
|
|
|
|
|
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
|
|
|
|
attributes:red]);
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:blue range:NSMakeRange(1,3)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:gray range:NSMakeRange(2,2)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
PASS([attrStr checkAttributes:red range:NSMakeRange(0,1)] &&
|
|
|
|
[attrStr checkAttributes:blue range:NSMakeRange(1,1)] &&
|
|
|
|
[attrStr checkAttributes:gray range:NSMakeRange(2,2)] &&
|
|
|
|
[attrStr checkAttributes:red range:NSMakeRange(4,6)],
|
|
|
|
"-setAttributes:range: works with subset at the end (diff color)");
|
|
|
|
|
|
|
|
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
|
|
|
|
attributes:red]);
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:gray range:NSMakeRange(1,3)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:gray range:NSMakeRange(2,2)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
PASS([attrStr checkAttributes:red range:NSMakeRange(0,1)] &&
|
|
|
|
[attrStr checkAttributes:gray range:NSMakeRange(1,3)] &&
|
|
|
|
[attrStr checkAttributes:red range:NSMakeRange(4,6)],
|
|
|
|
"-setAttributes:range: works with subset at the end (same color)");
|
|
|
|
|
|
|
|
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
|
|
|
|
attributes:red]);
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:blue range:NSMakeRange(2,3)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:gray range:NSMakeRange(2,2)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
PASS([attrStr checkAttributes:red range:NSMakeRange(0,2)] &&
|
|
|
|
[attrStr checkAttributes:gray range:NSMakeRange(2,2)] &&
|
|
|
|
[attrStr checkAttributes:blue range:NSMakeRange(4,1)] &&
|
|
|
|
[attrStr checkAttributes:red range:NSMakeRange(5,5)],
|
|
|
|
"-setAttributes:range: works with subset at the beginning (diff color)");
|
|
|
|
|
|
|
|
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
|
|
|
|
attributes:red]);
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:gray range:NSMakeRange(2,3)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:gray range:NSMakeRange(2,2)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
PASS([attrStr checkAttributes:red range:NSMakeRange(0,2)] &&
|
|
|
|
[attrStr checkAttributes:gray range:NSMakeRange(2,3)] &&
|
|
|
|
[attrStr checkAttributes:red range:NSMakeRange(5,5)],
|
|
|
|
"-setAttributes:range: works with subset at the beginning (same color)");
|
|
|
|
|
|
|
|
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
|
|
|
|
attributes:red]);
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:gray range:NSMakeRange(2,1)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:gray range:NSMakeRange(4,1)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:blue range:NSMakeRange(1,5)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
PASS([attrStr checkAttributes:red range:NSMakeRange(0,1)] &&
|
|
|
|
[attrStr checkAttributes:blue range:NSMakeRange(1,5)] &&
|
|
|
|
[attrStr checkAttributes:red range:NSMakeRange(6,4)],
|
|
|
|
"-setAttributes:range: works with subsets (diff color)");
|
|
|
|
|
|
|
|
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
|
|
|
|
attributes:red]);
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:blue range:NSMakeRange(2,1)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:blue range:NSMakeRange(4,1)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:blue range:NSMakeRange(1,5)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
PASS([attrStr checkAttributes:red range:NSMakeRange(0,1)] &&
|
|
|
|
[attrStr checkAttributes:blue range:NSMakeRange(1,5)] &&
|
|
|
|
[attrStr checkAttributes:red range:NSMakeRange(6,4)],
|
|
|
|
"-setAttributes:range: works with subsets (same color)");
|
|
|
|
|
|
|
|
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
|
|
|
|
attributes:red]);
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:blue range:NSMakeRange(2,1)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:blue range:NSMakeRange(4,1)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:blue range:NSMakeRange(7,2)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:red range:NSMakeRange(3,2)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:gray range:NSMakeRange(0,10)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
PASS([attrStr checkAttributes:gray range:NSMakeRange(0,10)],
|
|
|
|
"-setAttributes:range: works with setting attributes for the whole string");
|
|
|
|
|
|
|
|
ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString
|
|
|
|
attributes:red]);
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:blue range:NSMakeRange(0,1)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:blue range:NSMakeRange(1,1)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
[attrStr setAttributes:blue range:NSMakeRange(2,1)];
|
2018-02-07 09:48:56 +00:00
|
|
|
[attrStr _sanity];
|
2011-02-16 08:21:17 +00:00
|
|
|
PASS([attrStr checkAttributes:blue range:NSMakeRange(0,3)] &&
|
|
|
|
[attrStr checkAttributes:red range:NSMakeRange(3,7)],
|
|
|
|
"-setAttributes:range: works with nearby attributes");
|
|
|
|
|
|
|
|
[arp release]; arp = nil;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|