forked from Cocoanetics/DTCoreText
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDTCoreTextLayoutFrameTest.m
More file actions
54 lines (38 loc) · 1.81 KB
/
Copy pathDTCoreTextLayoutFrameTest.m
File metadata and controls
54 lines (38 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
// DTCoreTextLayoutFrameTest.m
// DTCoreText
//
// Created by Oliver Drobnik on 14.11.13.
// Copyright (c) 2013 Drobnik.com. All rights reserved.
//
#import "DTCoreTextTestCase.h"
#import <DTCoreText/DTCoreText.h>
#import <XCTest/XCTest.h>
@interface DTCoreTextLayoutFrameTest : DTCoreTextTestCase
@end
@implementation DTCoreTextLayoutFrameTest
- (void)testVariableHeight
{
NSAttributedString *attributedString = [super attributedStringFromHTMLString:@"<b>Some bold text</b>" options:nil];
DTCoreTextLayouter *layouter = [[DTCoreTextLayouter alloc] initWithAttributedString:attributedString];
CGRect maxRect = CGRectMake(10, 20, 1024, CGFLOAT_HEIGHT_UNKNOWN);
NSRange entireString = NSMakeRange(0, [attributedString length]);
DTCoreTextLayoutFrame *layoutFrame = [layouter layoutFrameWithRect:maxRect range:entireString];
CGSize sizeNeeded = [layoutFrame frame].size;
CGSize sizeExpected = CGSizeMake(1024, 16);
XCTAssertEqual(sizeNeeded.height, sizeExpected.height, @"Size incorrect");
XCTAssertEqual(sizeNeeded.width, sizeExpected.width, @"Size incorrect");
}
- (void)testVariableHeightAndWidth
{
NSAttributedString *attributedString = [super attributedStringFromHTMLString:@"<b>Some bold text</b>" options:nil];
DTCoreTextLayouter *layouter = [[DTCoreTextLayouter alloc] initWithAttributedString:attributedString];
CGRect maxRect = CGRectMake(10, 20, CGFLOAT_WIDTH_UNKNOWN, CGFLOAT_HEIGHT_UNKNOWN);
NSRange entireString = NSMakeRange(0, [attributedString length]);
DTCoreTextLayoutFrame *layoutFrame = [layouter layoutFrameWithRect:maxRect range:entireString];
CGSize sizeNeeded = [layoutFrame frame].size;
CGSize sizeExpected = CGSizeMake(76, 16);
XCTAssertEqual(sizeNeeded.height, sizeExpected.height, @"Size incorrect");
XCTAssertEqual(sizeNeeded.width, sizeExpected.width, @"Size incorrect");
}
@end