Skip to content

Commit

Permalink
Added unit test for sizeThatFits when using a custom truncation token…
Browse files Browse the repository at this point in the history
… with a dynamic height label.
  • Loading branch information
dillan committed Oct 26, 2016
1 parent 9a8cf93 commit 0763af6
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Example/TTTAttributedLabelTests/TTTAttributedLabelTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
attributes:TTTAttributedTestAttributesDictionary()];
}

static inline NSAttributedString * TTTAttributedTruncationTokenString() {
return [[NSAttributedString alloc] initWithString:@"+++"
attributes:TTTAttributedTestAttributesDictionary()];
}

static inline void TTTSizeAttributedLabel(TTTAttributedLabel *label) {
CGSize size = [TTTAttributedLabel sizeThatFitsAttributedString:label.attributedText
withConstraints:kTestLabelSize
Expand Down Expand Up @@ -197,6 +202,19 @@ - (void)testMultilineLabelSizing {
XCTAssertGreaterThan(size.height, font.pointSize, @"Text should size to more than one line");
}

- (void)testMultilineLabelSizeThatFitsWithTruncationToken {
NSAttributedString *testString = TTTAttributedTestString();
label.text = testString;

NSAttributedString *tokenString = TTTAttributedTruncationTokenString();
label.attributedTruncationToken = tokenString;

CGSize size = [label sizeThatFits:kTestLabelSize];

UIFont *font = [testString attribute:NSFontAttributeName atIndex:0 effectiveRange:NULL];
XCTAssertGreaterThan(size.height, font.pointSize, @"Text should size to more than one line");
}

- (void)testContainsLinkAtPoint {
label.text = TTTAttributedTestString();
[label addLinkToURL:testURL withRange:NSMakeRange(0, 4)];
Expand Down

0 comments on commit 0763af6

Please sign in to comment.