UnitTests/TestAttributedStringAdditions.m
author Matthew Kotila
Mon, 14 Dec 2015 00:37:29 -0800
changeset 5949 334dc418b409
parent 4499 fe90d7000f7a
permissions -rw-r--r--
Transition Adium from SenTestingKit to XCTest.

In order to build on OS X 10.11, Xcode 7.2, several changes have been made that are outlined:
- Unit tests Target Build Settings modified:
* 'Wrapper Extension' set to 'xctest'
* 'Enable Modules (C and Objective-C)' set to 'Yes'
- UnitTests Target of AutoHyperlink.framework Build Settings modified:
* 'Wrapper Extension' set to 'xctest'
* 'Enable Modules (C and Objective-C)' set to 'Yes'
* 'Other Linker Flags' removed '-framework SenTestingKit'
- 'SenTestingKit.framework' removed from Adium -> Linked Frameworks -> System
- 'SenTestingKit.framework' removed from Adium -> Linked Frameworks -> AutoHyperlinks.framework.xcodeproj -> External Frameworks and Libraries -> Linked Frameworks
- Find and Replace within 'Adium/Unit tests' && 'Adium/Linked Frameworks/Others/AutoHyperlinks.framework.xcodeproj/UnitTests'
* '<SenTestingKit/SenTestingKit.h>' to '<XCTest/XCTest.h>'
* 'SenTestCase' to 'XCTestCase'
* 'STAssert' to 'XCTAssert'
* 'XCTAssertEquals(' to 'XCTAssertEqual('
* regex '(\[\[\[)([^\]]*\][^\]]*\])(\ autorelease\]);' to '[[$2;'
* regex '(\[)([^\]]*\][^\]]*)(\ autorelease\])' to '$2'
- modified AutoHyperlinks.framework.xcodeproj -> project.pbxproj
* line 331: ?productType = "com.apple.product-type.bundle.ocunit-test";' to 'productType = "com.apple.product-type.bundle.unit-test";'
- AIWebKitMessageViewController.h
* forward declare WebUIDelegate, WebFrameLoadDelegate protocols
* add WebUIDelegate, WebFrameLoadDelegate protocols to 'AIWebKitMessageViewController' class
- AIFacebookXMPPOAuthWebViewWindowController.m lines 107 && 108
* '[[domDoc getElementById:@"email"] setValue:self.autoFillUsername];' to '[domDoc getElementById:@"email"].innerHTML = self.autoFillUsername;'
* '[[domDoc getElementById:@"pass"] setValue:self.autoFillPassword];' to '[domDoc getElementById:@"pass"].innerHTML = self.autoFillPassword;'
- XCTAssertEqual for NSRanges modified to ?XCTAssertTrue(NSEqualRanges(range1, range2)), ...)' in Unit tests
3679
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2678
diff changeset
     1
/* 
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2678
diff changeset
     2
 * Adium is the legal property of its developers, whose names are listed in the copyright file included
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2678
diff changeset
     3
 * with this source distribution.
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2678
diff changeset
     4
 * 
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2678
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2678
diff changeset
     6
 * General Public License as published by the Free Software Foundation; either version 2 of the License,
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2678
diff changeset
     7
 * or (at your option) any later version.
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2678
diff changeset
     8
 * 
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2678
diff changeset
     9
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2678
diff changeset
    10
 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2678
diff changeset
    11
 * Public License for more details.
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2678
diff changeset
    12
 * 
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2678
diff changeset
    13
 * You should have received a copy of the GNU General Public License along with this program; if not,
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2678
diff changeset
    14
 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2678
diff changeset
    15
 */
919
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    16
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    17
#import "TestAttributedStringAdditions.h"
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    18
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    19
#import <AIUtilities/AIAttributedStringAdditions.h>
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    20
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    21
@implementation TestAttributedStringAdditions
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    22
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    23
- (void) testLinkedAttributedString
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    24
{
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    25
	NSString *linkLabel = @"Adium";
4499
fe90d7000f7a Switched some adiumx.com links to adium.im. Added some "missing" wwws.
Adrian Godoroja <robotive@me.com>
parents: 3679
diff changeset
    26
	NSString *linkURLString = @"http://www.adium.im/";
919
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    27
	NSURL *linkURL = [NSURL URLWithString:linkURLString];
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    28
	NSRange linkRange = { 0UL, 0UL };
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    29
	id linkValue;
2678
461f8b7faf2f Fix a few warnings when building unit tests.
Stephen Holt <sholt@adium.im>
parents: 1076
diff changeset
    30
	NSAttributedString *attributedString = nil;
919
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    31
	NSRange attributedStringRange;
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    32
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    33
	//First, try a string containing a URL.
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
    34
	XCTAssertNoThrow(attributedString = [NSAttributedString attributedStringWithLinkLabel:linkLabel linkDestination:linkURLString], @"attributedStringWithLinkLabel:linkDestination: threw an exception");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
    35
	XCTAssertNotNil(attributedString, @"attributedStringWithLinkLabel:linkDestination: returned nil");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
    36
	XCTAssertEqualObjects([attributedString string], linkLabel, @"Attributed string's text is not equal to the original string");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
    37
	XCTAssertEqual([attributedString length], [linkLabel length], @"Attributed string is not the same length (%lu) as the original string (%lu)", [attributedString length], [linkLabel length]);
919
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    38
	linkValue = [attributedString attribute:NSLinkAttributeName atIndex:0UL effectiveRange:&linkRange];
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
    39
	XCTAssertNotNil(linkValue, @"Attributed string does not have a link");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
    40
	XCTAssertTrue([linkValue isKindOfClass:[NSURL class]], @"Link value is not an NSURL");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
    41
	XCTAssertEqualObjects(linkValue, linkURL, @"Link value is not equal to the URL we provided");
919
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    42
	attributedStringRange = (NSRange){ 0UL, [attributedString length] };
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
    43
	XCTAssertTrue(NSEqualRanges(linkRange, attributedStringRange), @"Link range is not the entire range of the attributed string");
919
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    44
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    45
	//Next, try an NSURL object.
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
    46
	XCTAssertNoThrow(attributedString = [NSAttributedString attributedStringWithLinkLabel:linkLabel linkDestination:linkURL], @"attributedStringWithLinkLabel:linkDestination: threw an exception");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
    47
	XCTAssertNotNil(attributedString, @"attributedStringWithLinkLabel:linkDestination: returned nil");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
    48
	XCTAssertEqualObjects([attributedString string], linkLabel, @"Attributed string's text is not equal to the original string");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
    49
	XCTAssertEqual([attributedString length], [linkLabel length], @"Attributed string is not the same length (%lu) as the original string (%lu)", [attributedString length], [linkLabel length]);
919
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    50
	linkValue = [attributedString attribute:NSLinkAttributeName atIndex:0UL effectiveRange:&linkRange];
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
    51
	XCTAssertNotNil(linkValue, @"Attributed string does not have a link");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
    52
	XCTAssertTrue([linkValue isKindOfClass:[NSURL class]], @"Link value is not an NSURL");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
    53
	XCTAssertEqualObjects(linkValue, linkURL, @"Link value is not equal to the URL we provided");
919
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    54
	attributedStringRange = (NSRange){ 0UL, [attributedString length] };
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
    55
	XCTAssertTrue(NSEqualRanges(linkRange, attributedStringRange), @"Link range is not the entire range of the attributed string");
919
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    56
}
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    57
- (void) testAttributedStringWithLinkedSubstring
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    58
{
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    59
	NSString *linkLabel = @"Download Adium now!";
4499
fe90d7000f7a Switched some adiumx.com links to adium.im. Added some "missing" wwws.
Adrian Godoroja <robotive@me.com>
parents: 3679
diff changeset
    60
	NSString *linkURLString = @"http://www.adium.im/";
919
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    61
	NSURL *linkURL = [NSURL URLWithString:linkURLString];
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    62
	NSRange intendedLinkRange = { 9UL, 5UL }; //@"Adium"
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    63
	NSRange linkRange = { 0UL, 0UL };
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    64
	id linkValue;
2678
461f8b7faf2f Fix a few warnings when building unit tests.
Stephen Holt <sholt@adium.im>
parents: 1076
diff changeset
    65
	NSAttributedString *attributedString = nil;
919
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    66
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    67
	//First, try a string containing a URL.
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
    68
	XCTAssertNoThrow(attributedString = [NSAttributedString attributedStringWithString:linkLabel linkRange:intendedLinkRange linkDestination:linkURLString], @"attributedStringWithLinkLabel:linkDestination: threw an exception");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
    69
	XCTAssertNotNil(attributedString, @"attributedStringWithLinkLabel:linkDestination: returned nil");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
    70
	XCTAssertEqualObjects([attributedString string], linkLabel, @"Attributed string's text is not equal to the original string");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
    71
	XCTAssertEqual([attributedString length], [linkLabel length], @"Attributed string is not the same length (%lu) as the original string (%lu)", [attributedString length], [linkLabel length]);
919
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    72
	linkValue = [attributedString attribute:NSLinkAttributeName atIndex:intendedLinkRange.location effectiveRange:&linkRange];
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
    73
	XCTAssertNotNil(linkValue, @"Attributed string does not have a link");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
    74
	XCTAssertTrue([linkValue isKindOfClass:[NSURL class]], @"Link value is not an NSURL");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
    75
	XCTAssertEqualObjects(linkValue, linkURL, @"Link value is not equal to the URL we provided");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
    76
	XCTAssertTrue(NSEqualRanges(linkRange, intendedLinkRange), @"Link range is not the range we wanted to link");
919
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    77
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    78
	//Next, try an NSURL object.
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
    79
	XCTAssertNoThrow(attributedString = [NSAttributedString attributedStringWithString:linkLabel linkRange:intendedLinkRange linkDestination:linkURL], @"attributedStringWithLinkLabel:linkDestination: threw an exception");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
    80
	XCTAssertNotNil(attributedString, @"attributedStringWithLinkLabel:linkDestination: returned nil");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
    81
	XCTAssertEqualObjects([attributedString string], linkLabel, @"Attributed string's text is not equal to the original string");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
    82
	XCTAssertEqual([attributedString length], [linkLabel length], @"Attributed string is not the same length (%lu) as the original string (%lu)", [attributedString length], [linkLabel length]);
919
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    83
	linkValue = [attributedString attribute:NSLinkAttributeName atIndex:intendedLinkRange.location effectiveRange:&linkRange];
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
    84
	XCTAssertNotNil(linkValue, @"Attributed string does not have a link");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
    85
	XCTAssertTrue([linkValue isKindOfClass:[NSURL class]], @"Link value is not an NSURL");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
    86
	XCTAssertEqualObjects(linkValue, linkURL, @"Link value is not equal to the URL we provided");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
    87
	XCTAssertTrue(NSEqualRanges(linkRange, intendedLinkRange), @"Link range is not the range we wanted to link");
919
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    88
}
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    89
- (void) testAttributedStringWithLinkedEntireStringUsingSubstringMethod
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    90
{
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    91
	NSString *linkLabel = @"Adium";
4499
fe90d7000f7a Switched some adiumx.com links to adium.im. Added some "missing" wwws.
Adrian Godoroja <robotive@me.com>
parents: 3679
diff changeset
    92
	NSString *linkURLString = @"http://www.adium.im/";
919
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    93
	NSURL *linkURL = [NSURL URLWithString:linkURLString];
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    94
	NSRange intendedLinkRange = { 0UL, [linkLabel length] };
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    95
	NSRange linkRange = { 0UL, 0UL };
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    96
	id linkValue;
2678
461f8b7faf2f Fix a few warnings when building unit tests.
Stephen Holt <sholt@adium.im>
parents: 1076
diff changeset
    97
	NSAttributedString *attributedString = nil;
919
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    98
	NSRange attributedStringRange;
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
    99
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
   100
	//First, try a string containing a URL.
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   101
	XCTAssertNoThrow(attributedString = [NSAttributedString attributedStringWithString:linkLabel linkRange:intendedLinkRange linkDestination:linkURLString], @"attributedStringWithLinkLabel:linkDestination: threw an exception");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   102
	XCTAssertNotNil(attributedString, @"attributedStringWithLinkLabel:linkDestination: returned nil");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   103
	XCTAssertEqualObjects([attributedString string], linkLabel, @"Attributed string's text is not equal to the original string");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   104
	XCTAssertEqual([attributedString length], [linkLabel length], @"Attributed string is not the same length (%lu) as the original string (%lu)", [attributedString length], [linkLabel length]);
919
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
   105
	linkValue = [attributedString attribute:NSLinkAttributeName atIndex:0UL effectiveRange:&linkRange];
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   106
	XCTAssertNotNil(linkValue, @"Attributed string does not have a link");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   107
	XCTAssertTrue([linkValue isKindOfClass:[NSURL class]], @"Link value is not an NSURL");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   108
	XCTAssertEqualObjects(linkValue, linkURL, @"Link value is not equal to the URL we provided");
919
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
   109
	attributedStringRange = (NSRange){ 0UL, [attributedString length] };
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   110
	XCTAssertTrue(NSEqualRanges(linkRange, attributedStringRange), @"Link range is not the entire range of the attributed string");
919
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
   111
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
   112
	//Next, try an NSURL object.
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   113
	XCTAssertNoThrow(attributedString = [NSAttributedString attributedStringWithString:linkLabel linkRange:intendedLinkRange linkDestination:linkURL], @"attributedStringWithLinkLabel:linkDestination: threw an exception");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   114
	XCTAssertNotNil(attributedString, @"attributedStringWithLinkLabel:linkDestination: returned nil");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   115
	XCTAssertEqualObjects([attributedString string], linkLabel, @"Attributed string's text is not equal to the original string");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   116
	XCTAssertEqual([attributedString length], [linkLabel length], @"Attributed string is not the same length (%lu) as the original string (%lu)", [attributedString length], [linkLabel length]);
919
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
   117
	linkValue = [attributedString attribute:NSLinkAttributeName atIndex:0UL effectiveRange:&linkRange];
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   118
	XCTAssertNotNil(linkValue, @"Attributed string does not have a link");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   119
	XCTAssertTrue([linkValue isKindOfClass:[NSURL class]], @"Link value is not an NSURL");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   120
	XCTAssertEqualObjects(linkValue, linkURL, @"Link value is not equal to the URL we provided");
919
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
   121
	attributedStringRange = (NSRange){ 0UL, [attributedString length] };
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   122
	XCTAssertTrue(NSEqualRanges(linkRange, attributedStringRange), @"Link range is not the entire range of the attributed string");
919
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
   123
}
921
5174bf83a8ef Added tests to make sure that linkifying an empty range works as advertised. These tests pass.
Peter Hosey
parents: 919
diff changeset
   124
- (void) testAttributedStringWithLinkedEmptySubstring
5174bf83a8ef Added tests to make sure that linkifying an empty range works as advertised. These tests pass.
Peter Hosey
parents: 919
diff changeset
   125
{
5174bf83a8ef Added tests to make sure that linkifying an empty range works as advertised. These tests pass.
Peter Hosey
parents: 919
diff changeset
   126
	NSString *linkLabel = @"Download Adium now!";
4499
fe90d7000f7a Switched some adiumx.com links to adium.im. Added some "missing" wwws.
Adrian Godoroja <robotive@me.com>
parents: 3679
diff changeset
   127
	NSString *linkURLString = @"http://www.adium.im/";
921
5174bf83a8ef Added tests to make sure that linkifying an empty range works as advertised. These tests pass.
Peter Hosey
parents: 919
diff changeset
   128
	NSURL *linkURL = [NSURL URLWithString:linkURLString];
5174bf83a8ef Added tests to make sure that linkifying an empty range works as advertised. These tests pass.
Peter Hosey
parents: 919
diff changeset
   129
	NSRange intendedLinkRange = { 9UL, 0UL }; //@""
5174bf83a8ef Added tests to make sure that linkifying an empty range works as advertised. These tests pass.
Peter Hosey
parents: 919
diff changeset
   130
	NSRange linkRange = { 0UL, 0UL };
5174bf83a8ef Added tests to make sure that linkifying an empty range works as advertised. These tests pass.
Peter Hosey
parents: 919
diff changeset
   131
	id linkValue;
2678
461f8b7faf2f Fix a few warnings when building unit tests.
Stephen Holt <sholt@adium.im>
parents: 1076
diff changeset
   132
	NSAttributedString *attributedString = nil;
921
5174bf83a8ef Added tests to make sure that linkifying an empty range works as advertised. These tests pass.
Peter Hosey
parents: 919
diff changeset
   133
	NSRange attributedStringRange;
5174bf83a8ef Added tests to make sure that linkifying an empty range works as advertised. These tests pass.
Peter Hosey
parents: 919
diff changeset
   134
5174bf83a8ef Added tests to make sure that linkifying an empty range works as advertised. These tests pass.
Peter Hosey
parents: 919
diff changeset
   135
	//First, try a string containing a URL.
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   136
	XCTAssertNoThrow(attributedString = [NSAttributedString attributedStringWithString:linkLabel linkRange:intendedLinkRange linkDestination:linkURLString], @"attributedStringWithLinkLabel:linkDestination: threw an exception");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   137
	XCTAssertNotNil(attributedString, @"attributedStringWithLinkLabel:linkDestination: returned nil");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   138
	XCTAssertEqualObjects([attributedString string], linkLabel, @"Attributed string's text is not equal to the original string");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   139
	XCTAssertEqual([attributedString length], [linkLabel length], @"Attributed string is not the same length (%lu) as the original string (%lu)", [attributedString length], [linkLabel length]);
921
5174bf83a8ef Added tests to make sure that linkifying an empty range works as advertised. These tests pass.
Peter Hosey
parents: 919
diff changeset
   140
	linkValue = [attributedString attribute:NSLinkAttributeName atIndex:intendedLinkRange.location effectiveRange:&linkRange];
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   141
	XCTAssertNil(linkValue, @"Attributed string has a link");
921
5174bf83a8ef Added tests to make sure that linkifying an empty range works as advertised. These tests pass.
Peter Hosey
parents: 919
diff changeset
   142
	//linkRange, at this point, should be the range that does not have a link, which should be the entire string.
5174bf83a8ef Added tests to make sure that linkifying an empty range works as advertised. These tests pass.
Peter Hosey
parents: 919
diff changeset
   143
	attributedStringRange = (NSRange){ 0UL, [attributedString length] };
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   144
	XCTAssertTrue(NSEqualRanges(linkRange, attributedStringRange), @"Non-link range is not the entire string");
921
5174bf83a8ef Added tests to make sure that linkifying an empty range works as advertised. These tests pass.
Peter Hosey
parents: 919
diff changeset
   145
5174bf83a8ef Added tests to make sure that linkifying an empty range works as advertised. These tests pass.
Peter Hosey
parents: 919
diff changeset
   146
	//Next, try an NSURL object.
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   147
	XCTAssertNoThrow(attributedString = [NSAttributedString attributedStringWithString:linkLabel linkRange:intendedLinkRange linkDestination:linkURL], @"attributedStringWithLinkLabel:linkDestination: threw an exception");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   148
	XCTAssertNotNil(attributedString, @"attributedStringWithLinkLabel:linkDestination: returned nil");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   149
	XCTAssertEqualObjects([attributedString string], linkLabel, @"Attributed string's text is not equal to the original string");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   150
	XCTAssertEqual([attributedString length], [linkLabel length], @"Attributed string is not the same length (%lu) as the original string (%lu)", [attributedString length], [linkLabel length]);
921
5174bf83a8ef Added tests to make sure that linkifying an empty range works as advertised. These tests pass.
Peter Hosey
parents: 919
diff changeset
   151
	linkValue = [attributedString attribute:NSLinkAttributeName atIndex:intendedLinkRange.location effectiveRange:&linkRange];
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   152
	XCTAssertNil(linkValue, @"Attributed string has a link");
921
5174bf83a8ef Added tests to make sure that linkifying an empty range works as advertised. These tests pass.
Peter Hosey
parents: 919
diff changeset
   153
	//linkRange, at this point, should be the range that does not have a link, which should be the entire string.
5174bf83a8ef Added tests to make sure that linkifying an empty range works as advertised. These tests pass.
Peter Hosey
parents: 919
diff changeset
   154
	attributedStringRange = (NSRange){ 0UL, [attributedString length] };
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   155
	XCTAssertTrue(NSEqualRanges(linkRange, attributedStringRange), @"Non-link range is not the entire string");
921
5174bf83a8ef Added tests to make sure that linkifying an empty range works as advertised. These tests pass.
Peter Hosey
parents: 919
diff changeset
   156
}
919
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
   157
1074
5affc71167ba Added a unit test for the `-[NSAttributedString(AIAttributedStringAdditions) attributedStringByConvertingLinksToStrings]` method. This test passes.
Peter Hosey
parents: 922
diff changeset
   158
- (void) testAttributedStringByConvertingLinksToStrings {
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   159
	NSMutableAttributedString *input = [[NSMutableAttributedString alloc] initWithString:@"Adium requires Growl."];
4499
fe90d7000f7a Switched some adiumx.com links to adium.im. Added some "missing" wwws.
Adrian Godoroja <robotive@me.com>
parents: 3679
diff changeset
   160
	[input addAttribute:NSLinkAttributeName value:[NSURL URLWithString:@"http://www.adium.im/"] range:[[input string] rangeOfString:@"Adium"]];
1074
5affc71167ba Added a unit test for the `-[NSAttributedString(AIAttributedStringAdditions) attributedStringByConvertingLinksToStrings]` method. This test passes.
Peter Hosey
parents: 922
diff changeset
   161
	[input addAttribute:NSLinkAttributeName value:[NSURL URLWithString:@"http://growl.info/"] range:[[input string] rangeOfString:@"Growl"]];
5affc71167ba Added a unit test for the `-[NSAttributedString(AIAttributedStringAdditions) attributedStringByConvertingLinksToStrings]` method. This test passes.
Peter Hosey
parents: 922
diff changeset
   162
2678
461f8b7faf2f Fix a few warnings when building unit tests.
Stephen Holt <sholt@adium.im>
parents: 1076
diff changeset
   163
	NSAttributedString *result = nil;
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   164
	XCTAssertNoThrow(result = [input attributedStringByConvertingLinksToStrings], @"-attributedStringByConvertingLinksToStrings threw an exception");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   165
	XCTAssertNotNil(result, @"-attributedStringByConvertingLinksToStrings returned nil");
1074
5affc71167ba Added a unit test for the `-[NSAttributedString(AIAttributedStringAdditions) attributedStringByConvertingLinksToStrings]` method. This test passes.
Peter Hosey
parents: 922
diff changeset
   166
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   167
	XCTAssertEqualObjects([result string], @"Adium (http://www.adium.im/) requires Growl (http://growl.info/).", @"-attributedStringByConvertingLinksToStrings did not correctly expand the links");
1074
5affc71167ba Added a unit test for the `-[NSAttributedString(AIAttributedStringAdditions) attributedStringByConvertingLinksToStrings]` method. This test passes.
Peter Hosey
parents: 922
diff changeset
   168
}
5affc71167ba Added a unit test for the `-[NSAttributedString(AIAttributedStringAdditions) attributedStringByConvertingLinksToStrings]` method. This test passes.
Peter Hosey
parents: 922
diff changeset
   169
1076
8a6ee77c5733 Added an `attributedStringByConvertingLinksToURLStrings` method. Comes with a test, which passes. Unlike the other method, this one replaces the link with its URL only.
Peter Hosey
parents: 1074
diff changeset
   170
- (void) testAttributedStringByConvertingLinksToURLStrings {
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   171
	NSMutableAttributedString *input = [[NSMutableAttributedString alloc] initWithString:@"Adium requires Growl."];
4499
fe90d7000f7a Switched some adiumx.com links to adium.im. Added some "missing" wwws.
Adrian Godoroja <robotive@me.com>
parents: 3679
diff changeset
   172
	[input addAttribute:NSLinkAttributeName value:[NSURL URLWithString:@"http://www.adium.im/"] range:[[input string] rangeOfString:@"Adium"]];
1076
8a6ee77c5733 Added an `attributedStringByConvertingLinksToURLStrings` method. Comes with a test, which passes. Unlike the other method, this one replaces the link with its URL only.
Peter Hosey
parents: 1074
diff changeset
   173
	[input addAttribute:NSLinkAttributeName value:[NSURL URLWithString:@"http://growl.info/"] range:[[input string] rangeOfString:@"Growl"]];
8a6ee77c5733 Added an `attributedStringByConvertingLinksToURLStrings` method. Comes with a test, which passes. Unlike the other method, this one replaces the link with its URL only.
Peter Hosey
parents: 1074
diff changeset
   174
2678
461f8b7faf2f Fix a few warnings when building unit tests.
Stephen Holt <sholt@adium.im>
parents: 1076
diff changeset
   175
	NSAttributedString *result = nil;
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   176
	XCTAssertNoThrow(result = [input attributedStringByConvertingLinksToURLStrings], @"-attributedStringByConvertingLinksToURLStrings threw an exception");
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   177
	XCTAssertNotNil(result, @"-attributedStringByConvertingLinksToURLStrings returned nil");
1076
8a6ee77c5733 Added an `attributedStringByConvertingLinksToURLStrings` method. Comes with a test, which passes. Unlike the other method, this one replaces the link with its URL only.
Peter Hosey
parents: 1074
diff changeset
   178
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 4499
diff changeset
   179
	XCTAssertEqualObjects([result string], @"http://www.adium.im/ requires http://growl.info/.", @"-attributedStringByConvertingLinksToURLStrings did not correctly expand the links");
1076
8a6ee77c5733 Added an `attributedStringByConvertingLinksToURLStrings` method. Comes with a test, which passes. Unlike the other method, this one replaces the link with its URL only.
Peter Hosey
parents: 1074
diff changeset
   180
}
8a6ee77c5733 Added an `attributedStringByConvertingLinksToURLStrings` method. Comes with a test, which passes. Unlike the other method, this one replaces the link with its URL only.
Peter Hosey
parents: 1074
diff changeset
   181
919
110e9af27e1c Added methods to easily create linkified attributed strings. Example usages:
Peter Hosey
parents:
diff changeset
   182
@end