UnitTests/TestAttributedStringAdditions.m
changeset 5949 334dc418b409
parent 4499 fe90d7000f7a
--- a/UnitTests/TestAttributedStringAdditions.m	Mon Aug 04 16:49:27 2014 -0400
+++ b/UnitTests/TestAttributedStringAdditions.m	Mon Dec 14 00:37:29 2015 -0800
@@ -31,28 +31,28 @@
 	NSRange attributedStringRange;
 
 	//First, try a string containing a URL.
-	STAssertNoThrow(attributedString = [NSAttributedString attributedStringWithLinkLabel:linkLabel linkDestination:linkURLString], @"attributedStringWithLinkLabel:linkDestination: threw an exception");
-	STAssertNotNil(attributedString, @"attributedStringWithLinkLabel:linkDestination: returned nil");
-	STAssertEqualObjects([attributedString string], linkLabel, @"Attributed string's text is not equal to the original string");
-	STAssertEquals([attributedString length], [linkLabel length], @"Attributed string is not the same length (%lu) as the original string (%lu)", [attributedString length], [linkLabel length]);
+	XCTAssertNoThrow(attributedString = [NSAttributedString attributedStringWithLinkLabel:linkLabel linkDestination:linkURLString], @"attributedStringWithLinkLabel:linkDestination: threw an exception");
+	XCTAssertNotNil(attributedString, @"attributedStringWithLinkLabel:linkDestination: returned nil");
+	XCTAssertEqualObjects([attributedString string], linkLabel, @"Attributed string's text is not equal to the original string");
+	XCTAssertEqual([attributedString length], [linkLabel length], @"Attributed string is not the same length (%lu) as the original string (%lu)", [attributedString length], [linkLabel length]);
 	linkValue = [attributedString attribute:NSLinkAttributeName atIndex:0UL effectiveRange:&linkRange];
-	STAssertNotNil(linkValue, @"Attributed string does not have a link");
-	STAssertTrue([linkValue isKindOfClass:[NSURL class]], @"Link value is not an NSURL");
-	STAssertEqualObjects(linkValue, linkURL, @"Link value is not equal to the URL we provided");
+	XCTAssertNotNil(linkValue, @"Attributed string does not have a link");
+	XCTAssertTrue([linkValue isKindOfClass:[NSURL class]], @"Link value is not an NSURL");
+	XCTAssertEqualObjects(linkValue, linkURL, @"Link value is not equal to the URL we provided");
 	attributedStringRange = (NSRange){ 0UL, [attributedString length] };
-	STAssertEquals(linkRange, attributedStringRange, @"Link range is not the entire range of the attributed string");
+	XCTAssertTrue(NSEqualRanges(linkRange, attributedStringRange), @"Link range is not the entire range of the attributed string");
 
 	//Next, try an NSURL object.
-	STAssertNoThrow(attributedString = [NSAttributedString attributedStringWithLinkLabel:linkLabel linkDestination:linkURL], @"attributedStringWithLinkLabel:linkDestination: threw an exception");
-	STAssertNotNil(attributedString, @"attributedStringWithLinkLabel:linkDestination: returned nil");
-	STAssertEqualObjects([attributedString string], linkLabel, @"Attributed string's text is not equal to the original string");
-	STAssertEquals([attributedString length], [linkLabel length], @"Attributed string is not the same length (%lu) as the original string (%lu)", [attributedString length], [linkLabel length]);
+	XCTAssertNoThrow(attributedString = [NSAttributedString attributedStringWithLinkLabel:linkLabel linkDestination:linkURL], @"attributedStringWithLinkLabel:linkDestination: threw an exception");
+	XCTAssertNotNil(attributedString, @"attributedStringWithLinkLabel:linkDestination: returned nil");
+	XCTAssertEqualObjects([attributedString string], linkLabel, @"Attributed string's text is not equal to the original string");
+	XCTAssertEqual([attributedString length], [linkLabel length], @"Attributed string is not the same length (%lu) as the original string (%lu)", [attributedString length], [linkLabel length]);
 	linkValue = [attributedString attribute:NSLinkAttributeName atIndex:0UL effectiveRange:&linkRange];
-	STAssertNotNil(linkValue, @"Attributed string does not have a link");
-	STAssertTrue([linkValue isKindOfClass:[NSURL class]], @"Link value is not an NSURL");
-	STAssertEqualObjects(linkValue, linkURL, @"Link value is not equal to the URL we provided");
+	XCTAssertNotNil(linkValue, @"Attributed string does not have a link");
+	XCTAssertTrue([linkValue isKindOfClass:[NSURL class]], @"Link value is not an NSURL");
+	XCTAssertEqualObjects(linkValue, linkURL, @"Link value is not equal to the URL we provided");
 	attributedStringRange = (NSRange){ 0UL, [attributedString length] };
-	STAssertEquals(linkRange, attributedStringRange, @"Link range is not the entire range of the attributed string");
+	XCTAssertTrue(NSEqualRanges(linkRange, attributedStringRange), @"Link range is not the entire range of the attributed string");
 }
 - (void) testAttributedStringWithLinkedSubstring
 {
@@ -65,26 +65,26 @@
 	NSAttributedString *attributedString = nil;
 
 	//First, try a string containing a URL.
-	STAssertNoThrow(attributedString = [NSAttributedString attributedStringWithString:linkLabel linkRange:intendedLinkRange linkDestination:linkURLString], @"attributedStringWithLinkLabel:linkDestination: threw an exception");
-	STAssertNotNil(attributedString, @"attributedStringWithLinkLabel:linkDestination: returned nil");
-	STAssertEqualObjects([attributedString string], linkLabel, @"Attributed string's text is not equal to the original string");
-	STAssertEquals([attributedString length], [linkLabel length], @"Attributed string is not the same length (%lu) as the original string (%lu)", [attributedString length], [linkLabel length]);
+	XCTAssertNoThrow(attributedString = [NSAttributedString attributedStringWithString:linkLabel linkRange:intendedLinkRange linkDestination:linkURLString], @"attributedStringWithLinkLabel:linkDestination: threw an exception");
+	XCTAssertNotNil(attributedString, @"attributedStringWithLinkLabel:linkDestination: returned nil");
+	XCTAssertEqualObjects([attributedString string], linkLabel, @"Attributed string's text is not equal to the original string");
+	XCTAssertEqual([attributedString length], [linkLabel length], @"Attributed string is not the same length (%lu) as the original string (%lu)", [attributedString length], [linkLabel length]);
 	linkValue = [attributedString attribute:NSLinkAttributeName atIndex:intendedLinkRange.location effectiveRange:&linkRange];
-	STAssertNotNil(linkValue, @"Attributed string does not have a link");
-	STAssertTrue([linkValue isKindOfClass:[NSURL class]], @"Link value is not an NSURL");
-	STAssertEqualObjects(linkValue, linkURL, @"Link value is not equal to the URL we provided");
-	STAssertEquals(linkRange, intendedLinkRange, @"Link range is not the range we wanted to link");
+	XCTAssertNotNil(linkValue, @"Attributed string does not have a link");
+	XCTAssertTrue([linkValue isKindOfClass:[NSURL class]], @"Link value is not an NSURL");
+	XCTAssertEqualObjects(linkValue, linkURL, @"Link value is not equal to the URL we provided");
+	XCTAssertTrue(NSEqualRanges(linkRange, intendedLinkRange), @"Link range is not the range we wanted to link");
 
 	//Next, try an NSURL object.
-	STAssertNoThrow(attributedString = [NSAttributedString attributedStringWithString:linkLabel linkRange:intendedLinkRange linkDestination:linkURL], @"attributedStringWithLinkLabel:linkDestination: threw an exception");
-	STAssertNotNil(attributedString, @"attributedStringWithLinkLabel:linkDestination: returned nil");
-	STAssertEqualObjects([attributedString string], linkLabel, @"Attributed string's text is not equal to the original string");
-	STAssertEquals([attributedString length], [linkLabel length], @"Attributed string is not the same length (%lu) as the original string (%lu)", [attributedString length], [linkLabel length]);
+	XCTAssertNoThrow(attributedString = [NSAttributedString attributedStringWithString:linkLabel linkRange:intendedLinkRange linkDestination:linkURL], @"attributedStringWithLinkLabel:linkDestination: threw an exception");
+	XCTAssertNotNil(attributedString, @"attributedStringWithLinkLabel:linkDestination: returned nil");
+	XCTAssertEqualObjects([attributedString string], linkLabel, @"Attributed string's text is not equal to the original string");
+	XCTAssertEqual([attributedString length], [linkLabel length], @"Attributed string is not the same length (%lu) as the original string (%lu)", [attributedString length], [linkLabel length]);
 	linkValue = [attributedString attribute:NSLinkAttributeName atIndex:intendedLinkRange.location effectiveRange:&linkRange];
-	STAssertNotNil(linkValue, @"Attributed string does not have a link");
-	STAssertTrue([linkValue isKindOfClass:[NSURL class]], @"Link value is not an NSURL");
-	STAssertEqualObjects(linkValue, linkURL, @"Link value is not equal to the URL we provided");
-	STAssertEquals(linkRange, intendedLinkRange, @"Link range is not the range we wanted to link");
+	XCTAssertNotNil(linkValue, @"Attributed string does not have a link");
+	XCTAssertTrue([linkValue isKindOfClass:[NSURL class]], @"Link value is not an NSURL");
+	XCTAssertEqualObjects(linkValue, linkURL, @"Link value is not equal to the URL we provided");
+	XCTAssertTrue(NSEqualRanges(linkRange, intendedLinkRange), @"Link range is not the range we wanted to link");
 }
 - (void) testAttributedStringWithLinkedEntireStringUsingSubstringMethod
 {
@@ -98,28 +98,28 @@
 	NSRange attributedStringRange;
 
 	//First, try a string containing a URL.
-	STAssertNoThrow(attributedString = [NSAttributedString attributedStringWithString:linkLabel linkRange:intendedLinkRange linkDestination:linkURLString], @"attributedStringWithLinkLabel:linkDestination: threw an exception");
-	STAssertNotNil(attributedString, @"attributedStringWithLinkLabel:linkDestination: returned nil");
-	STAssertEqualObjects([attributedString string], linkLabel, @"Attributed string's text is not equal to the original string");
-	STAssertEquals([attributedString length], [linkLabel length], @"Attributed string is not the same length (%lu) as the original string (%lu)", [attributedString length], [linkLabel length]);
+	XCTAssertNoThrow(attributedString = [NSAttributedString attributedStringWithString:linkLabel linkRange:intendedLinkRange linkDestination:linkURLString], @"attributedStringWithLinkLabel:linkDestination: threw an exception");
+	XCTAssertNotNil(attributedString, @"attributedStringWithLinkLabel:linkDestination: returned nil");
+	XCTAssertEqualObjects([attributedString string], linkLabel, @"Attributed string's text is not equal to the original string");
+	XCTAssertEqual([attributedString length], [linkLabel length], @"Attributed string is not the same length (%lu) as the original string (%lu)", [attributedString length], [linkLabel length]);
 	linkValue = [attributedString attribute:NSLinkAttributeName atIndex:0UL effectiveRange:&linkRange];
-	STAssertNotNil(linkValue, @"Attributed string does not have a link");
-	STAssertTrue([linkValue isKindOfClass:[NSURL class]], @"Link value is not an NSURL");
-	STAssertEqualObjects(linkValue, linkURL, @"Link value is not equal to the URL we provided");
+	XCTAssertNotNil(linkValue, @"Attributed string does not have a link");
+	XCTAssertTrue([linkValue isKindOfClass:[NSURL class]], @"Link value is not an NSURL");
+	XCTAssertEqualObjects(linkValue, linkURL, @"Link value is not equal to the URL we provided");
 	attributedStringRange = (NSRange){ 0UL, [attributedString length] };
-	STAssertEquals(linkRange, attributedStringRange, @"Link range is not the entire range of the attributed string");
+	XCTAssertTrue(NSEqualRanges(linkRange, attributedStringRange), @"Link range is not the entire range of the attributed string");
 
 	//Next, try an NSURL object.
-	STAssertNoThrow(attributedString = [NSAttributedString attributedStringWithString:linkLabel linkRange:intendedLinkRange linkDestination:linkURL], @"attributedStringWithLinkLabel:linkDestination: threw an exception");
-	STAssertNotNil(attributedString, @"attributedStringWithLinkLabel:linkDestination: returned nil");
-	STAssertEqualObjects([attributedString string], linkLabel, @"Attributed string's text is not equal to the original string");
-	STAssertEquals([attributedString length], [linkLabel length], @"Attributed string is not the same length (%lu) as the original string (%lu)", [attributedString length], [linkLabel length]);
+	XCTAssertNoThrow(attributedString = [NSAttributedString attributedStringWithString:linkLabel linkRange:intendedLinkRange linkDestination:linkURL], @"attributedStringWithLinkLabel:linkDestination: threw an exception");
+	XCTAssertNotNil(attributedString, @"attributedStringWithLinkLabel:linkDestination: returned nil");
+	XCTAssertEqualObjects([attributedString string], linkLabel, @"Attributed string's text is not equal to the original string");
+	XCTAssertEqual([attributedString length], [linkLabel length], @"Attributed string is not the same length (%lu) as the original string (%lu)", [attributedString length], [linkLabel length]);
 	linkValue = [attributedString attribute:NSLinkAttributeName atIndex:0UL effectiveRange:&linkRange];
-	STAssertNotNil(linkValue, @"Attributed string does not have a link");
-	STAssertTrue([linkValue isKindOfClass:[NSURL class]], @"Link value is not an NSURL");
-	STAssertEqualObjects(linkValue, linkURL, @"Link value is not equal to the URL we provided");
+	XCTAssertNotNil(linkValue, @"Attributed string does not have a link");
+	XCTAssertTrue([linkValue isKindOfClass:[NSURL class]], @"Link value is not an NSURL");
+	XCTAssertEqualObjects(linkValue, linkURL, @"Link value is not equal to the URL we provided");
 	attributedStringRange = (NSRange){ 0UL, [attributedString length] };
-	STAssertEquals(linkRange, attributedStringRange, @"Link range is not the entire range of the attributed string");
+	XCTAssertTrue(NSEqualRanges(linkRange, attributedStringRange), @"Link range is not the entire range of the attributed string");
 }
 - (void) testAttributedStringWithLinkedEmptySubstring
 {
@@ -133,50 +133,50 @@
 	NSRange attributedStringRange;
 
 	//First, try a string containing a URL.
-	STAssertNoThrow(attributedString = [NSAttributedString attributedStringWithString:linkLabel linkRange:intendedLinkRange linkDestination:linkURLString], @"attributedStringWithLinkLabel:linkDestination: threw an exception");
-	STAssertNotNil(attributedString, @"attributedStringWithLinkLabel:linkDestination: returned nil");
-	STAssertEqualObjects([attributedString string], linkLabel, @"Attributed string's text is not equal to the original string");
-	STAssertEquals([attributedString length], [linkLabel length], @"Attributed string is not the same length (%lu) as the original string (%lu)", [attributedString length], [linkLabel length]);
+	XCTAssertNoThrow(attributedString = [NSAttributedString attributedStringWithString:linkLabel linkRange:intendedLinkRange linkDestination:linkURLString], @"attributedStringWithLinkLabel:linkDestination: threw an exception");
+	XCTAssertNotNil(attributedString, @"attributedStringWithLinkLabel:linkDestination: returned nil");
+	XCTAssertEqualObjects([attributedString string], linkLabel, @"Attributed string's text is not equal to the original string");
+	XCTAssertEqual([attributedString length], [linkLabel length], @"Attributed string is not the same length (%lu) as the original string (%lu)", [attributedString length], [linkLabel length]);
 	linkValue = [attributedString attribute:NSLinkAttributeName atIndex:intendedLinkRange.location effectiveRange:&linkRange];
-	STAssertNil(linkValue, @"Attributed string has a link");
+	XCTAssertNil(linkValue, @"Attributed string has a link");
 	//linkRange, at this point, should be the range that does not have a link, which should be the entire string.
 	attributedStringRange = (NSRange){ 0UL, [attributedString length] };
-	STAssertEquals(linkRange, attributedStringRange, @"Non-link range is not the entire string");
+	XCTAssertTrue(NSEqualRanges(linkRange, attributedStringRange), @"Non-link range is not the entire string");
 
 	//Next, try an NSURL object.
-	STAssertNoThrow(attributedString = [NSAttributedString attributedStringWithString:linkLabel linkRange:intendedLinkRange linkDestination:linkURL], @"attributedStringWithLinkLabel:linkDestination: threw an exception");
-	STAssertNotNil(attributedString, @"attributedStringWithLinkLabel:linkDestination: returned nil");
-	STAssertEqualObjects([attributedString string], linkLabel, @"Attributed string's text is not equal to the original string");
-	STAssertEquals([attributedString length], [linkLabel length], @"Attributed string is not the same length (%lu) as the original string (%lu)", [attributedString length], [linkLabel length]);
+	XCTAssertNoThrow(attributedString = [NSAttributedString attributedStringWithString:linkLabel linkRange:intendedLinkRange linkDestination:linkURL], @"attributedStringWithLinkLabel:linkDestination: threw an exception");
+	XCTAssertNotNil(attributedString, @"attributedStringWithLinkLabel:linkDestination: returned nil");
+	XCTAssertEqualObjects([attributedString string], linkLabel, @"Attributed string's text is not equal to the original string");
+	XCTAssertEqual([attributedString length], [linkLabel length], @"Attributed string is not the same length (%lu) as the original string (%lu)", [attributedString length], [linkLabel length]);
 	linkValue = [attributedString attribute:NSLinkAttributeName atIndex:intendedLinkRange.location effectiveRange:&linkRange];
-	STAssertNil(linkValue, @"Attributed string has a link");
+	XCTAssertNil(linkValue, @"Attributed string has a link");
 	//linkRange, at this point, should be the range that does not have a link, which should be the entire string.
 	attributedStringRange = (NSRange){ 0UL, [attributedString length] };
-	STAssertEquals(linkRange, attributedStringRange, @"Non-link range is not the entire string");
+	XCTAssertTrue(NSEqualRanges(linkRange, attributedStringRange), @"Non-link range is not the entire string");
 }
 
 - (void) testAttributedStringByConvertingLinksToStrings {
-	NSMutableAttributedString *input = [[[NSMutableAttributedString alloc] initWithString:@"Adium requires Growl."] autorelease];
+	NSMutableAttributedString *input = [[NSMutableAttributedString alloc] initWithString:@"Adium requires Growl."];
 	[input addAttribute:NSLinkAttributeName value:[NSURL URLWithString:@"http://www.adium.im/"] range:[[input string] rangeOfString:@"Adium"]];
 	[input addAttribute:NSLinkAttributeName value:[NSURL URLWithString:@"http://growl.info/"] range:[[input string] rangeOfString:@"Growl"]];
 
 	NSAttributedString *result = nil;
-	STAssertNoThrow(result = [input attributedStringByConvertingLinksToStrings], @"-attributedStringByConvertingLinksToStrings threw an exception");
-	STAssertNotNil(result, @"-attributedStringByConvertingLinksToStrings returned nil");
+	XCTAssertNoThrow(result = [input attributedStringByConvertingLinksToStrings], @"-attributedStringByConvertingLinksToStrings threw an exception");
+	XCTAssertNotNil(result, @"-attributedStringByConvertingLinksToStrings returned nil");
 
-	STAssertEqualObjects([result string], @"Adium (http://www.adium.im/) requires Growl (http://growl.info/).", @"-attributedStringByConvertingLinksToStrings did not correctly expand the links");
+	XCTAssertEqualObjects([result string], @"Adium (http://www.adium.im/) requires Growl (http://growl.info/).", @"-attributedStringByConvertingLinksToStrings did not correctly expand the links");
 }
 
 - (void) testAttributedStringByConvertingLinksToURLStrings {
-	NSMutableAttributedString *input = [[[NSMutableAttributedString alloc] initWithString:@"Adium requires Growl."] autorelease];
+	NSMutableAttributedString *input = [[NSMutableAttributedString alloc] initWithString:@"Adium requires Growl."];
 	[input addAttribute:NSLinkAttributeName value:[NSURL URLWithString:@"http://www.adium.im/"] range:[[input string] rangeOfString:@"Adium"]];
 	[input addAttribute:NSLinkAttributeName value:[NSURL URLWithString:@"http://growl.info/"] range:[[input string] rangeOfString:@"Growl"]];
 
 	NSAttributedString *result = nil;
-	STAssertNoThrow(result = [input attributedStringByConvertingLinksToURLStrings], @"-attributedStringByConvertingLinksToURLStrings threw an exception");
-	STAssertNotNil(result, @"-attributedStringByConvertingLinksToURLStrings returned nil");
+	XCTAssertNoThrow(result = [input attributedStringByConvertingLinksToURLStrings], @"-attributedStringByConvertingLinksToURLStrings threw an exception");
+	XCTAssertNotNil(result, @"-attributedStringByConvertingLinksToURLStrings returned nil");
 
-	STAssertEqualObjects([result string], @"http://www.adium.im/ requires http://growl.info/.", @"-attributedStringByConvertingLinksToURLStrings did not correctly expand the links");
+	XCTAssertEqualObjects([result string], @"http://www.adium.im/ requires http://growl.info/.", @"-attributedStringByConvertingLinksToURLStrings did not correctly expand the links");
 }
 
 @end