Skip to content

Commit

Permalink
Fix isTruncated logic in ASTextNode2 (TextureGroup#1259)
Browse files Browse the repository at this point in the history
* Fix isTruncated logic in ASTextNode2

* Add truncation tests
  • Loading branch information
maicki authored and wsdwsd0829 committed Mar 15, 2019
1 parent 15243ba commit 10d1a6d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Source/ASTextNode2.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ - (void)setTruncationMode:(NSLineBreakMode)truncationMode

- (BOOL)isTruncated
{
return ASLockedSelf([self locked_textLayoutForSize:[self _locked_threadSafeBounds].size].truncatedLine == nil);
return ASLockedSelf([self locked_textLayoutForSize:[self _locked_threadSafeBounds].size].truncatedLine != nil);
}

- (BOOL)shouldTruncateForConstrainedSize:(ASSizeRange)constrainedSize
Expand Down
9 changes: 9 additions & 0 deletions Tests/ASTextNode2Tests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#import <AsyncDisplayKit/ASDisplayNode+Beta.h>
#import <AsyncDisplayKit/ASTextNode2.h>
#import <AsyncDisplayKit/ASTextNode+Beta.h>

#import <XCTest/XCTest.h>

Expand Down Expand Up @@ -63,6 +64,14 @@ - (void)setUp
_textNode.attributedText = _attributedText;
}

- (void)testTruncation
{
XCTAssertTrue([(ASTextNode *)_textNode shouldTruncateForConstrainedSize:ASSizeRangeMake(CGSizeMake(100, 100))], @"Text Node should truncate");

_textNode.frame = CGRectMake(0, 0, 100, 100);
XCTAssertTrue(_textNode.isTruncated, @"Text Node should be truncated");
}

- (void)testAccessibility
{
XCTAssertTrue(_textNode.isAccessibilityElement, @"Should be an accessibility element");
Expand Down
9 changes: 9 additions & 0 deletions Tests/ASTextNodeTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#import <AsyncDisplayKit/ASAvailability.h>
#import <AsyncDisplayKit/ASLayout.h>
#import <AsyncDisplayKit/ASTextNode.h>
#import <AsyncDisplayKit/ASTextNode+Beta.h>

#import <XCTest/XCTest.h>
#import <AsyncDisplayKit/CoreGraphics+ASConvenience.h>
Expand Down Expand Up @@ -102,6 +103,14 @@ - (void)testAllocASTextNode

#pragma mark - ASTextNode

- (void)testTruncation
{
XCTAssertTrue([_textNode shouldTruncateForConstrainedSize:ASSizeRangeMake(CGSizeMake(100, 100))], @"");

_textNode.frame = CGRectMake(0, 0, 100, 100);
XCTAssertTrue(_textNode.isTruncated, @"Text Node should be truncated");
}

- (void)testSettingTruncationMessage
{
NSAttributedString *truncation = [[NSAttributedString alloc] initWithString:@"..." attributes:nil];
Expand Down

0 comments on commit 10d1a6d

Please sign in to comment.