daily pastebin goal
41%
SHARE
TWEET

Untitled

a guest Feb 17th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import XCTest
  2. @testable import AttributedDynamicLabelDemo
  3.  
  4. class AttributedDynamicLabelDemoTests: XCTestCase {
  5.  
  6.   var subject: AttributedStringView!
  7.  
  8.   override func setUp() {
  9.     super.setUp()
  10.     subject = AttributedStringView()
  11.   }
  12.  
  13.   func testAttributedStringDynamicType() {
  14.     var extraSmallSizes: [CGFloat] = []
  15.     var largeSizes: [CGFloat] = []
  16.     var biggestSizes: [CGFloat] = []
  17.  
  18.     let fullTextRange = NSRange(location: 0,
  19.                                 length: subject.display.attributedText!.string.count)
  20.  
  21.     /// Test extraSmall content size
  22.     /// String 1: 14.8
  23.     /// String 2: 6.6
  24.     /// String 3: 14.8
  25.     /// String 4: 39.5
  26.     FontMetrics.default.sizeCategory = .extraSmall
  27.     NSMutableAttributedString(attributedString: subject.display.attributedText!)
  28.       .enumerateAttributes(in: fullTextRange,
  29.                            options: []) { attributes, range, stop in
  30.                              let gottenFont = attributes[.font] as! UIFont
  31.                              extraSmallSizes.append(gottenFont.pointSize)
  32.     }
  33.  
  34.     /// Test large content size
  35.     /// String 1: 18.0
  36.     /// String 2: 8.0
  37.     /// String 3: 18.0
  38.     /// String 4: 48.0
  39.     FontMetrics.default.sizeCategory = .large
  40.     NSMutableAttributedString(attributedString: subject.display.attributedText!)
  41.       .enumerateAttributes(in: fullTextRange,
  42.                            options: []) { attributes, range, stop in
  43.                              let gottenFont = attributes[.font] as! UIFont
  44.                              largeSizes.append(gottenFont.pointSize)
  45.     }
  46.  
  47.     /// Test accessibilityExtraExtraExtraLarge content size
  48.     /// String 1: 56.1
  49.     /// String 2: 24.9
  50.     /// String 3: 24.0
  51.     /// String 4: 149.6
  52.     FontMetrics.default.sizeCategory = .accessibilityExtraExtraExtraLarge
  53.     NSMutableAttributedString(attributedString: subject.display.attributedText!)
  54.       .enumerateAttributes(in: fullTextRange,
  55.                            options: []) { attributes, range, stop in
  56.                              let gottenFont = attributes[.font] as! UIFont
  57.                              biggestSizes.append(gottenFont.pointSize)
  58.     }
  59.  
  60.     for (index, smallSize) in extraSmallSizes.enumerated() {
  61.       XCTAssert(smallSize < largeSizes[index])
  62.       XCTAssert(largeSizes[index] < biggestSizes[index])
  63.     }
  64.   }
  65. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top