@@ -87,7 +87,7 @@ final class TypographyFontTests: XCTestCase {
8787
8888 // The returned font should not exceed the requested maximum
8989 XCTAssertEqual ( layout. font. pointSize, $0. fontSize * 2 )
90- // The returned line height should not exceed th requested maximum
90+ // The returned line height should not exceed the requested maximum
9191 XCTAssertEqual ( layout. lineHeight, $0. lineHeight * 2 )
9292 // baselineOffset should be >= 0 and pixel-aligned
9393 XCTAssertGreaterThanOrEqual ( layout. baselineOffset, 0 )
@@ -117,7 +117,37 @@ final class TypographyFontTests: XCTestCase {
117117
118118 // The returned font should not exceed the requested maximum
119119 XCTAssertEqual ( layout. font. pointSize, size. fontSize * scaleFactor)
120- // The returned line height should not exceed th requested maximum
120+ // The returned line height should not exceed the requested maximum
121+ XCTAssertEqual ( layout. lineHeight, size. lineHeight * scaleFactor)
122+ // baselineOffset should be >= 0 and pixel-aligned
123+ XCTAssertGreaterThanOrEqual ( layout. baselineOffset, 0 )
124+ XCTAssertEqual ( layout. baselineOffset. ceiled ( ) , layout. baselineOffset)
125+ }
126+ }
127+ }
128+
129+ func testIntrinsicMaximumScaleFactor( ) {
130+ let fontFamily = DefaultFontFamily ( familyName: " Menlo " )
131+ let traits = UITraitCollection ( preferredContentSizeCategory: . accessibilityExtraExtraExtraLarge)
132+
133+ sizes. forEach { size in
134+ scaleFactors. forEach { scaleFactor in
135+ // Given we build a typography with a built-in max scale factor
136+ let typography = Typography (
137+ fontFamily: fontFamily,
138+ fontWeight: . bold,
139+ fontSize: size. fontSize,
140+ lineHeight: size. lineHeight,
141+ maximumScaleFactor: scaleFactor
142+ )
143+
144+ // When we request a layout without specifying any further max
145+ // (at the largest supported Dynamic Type size)
146+ let layout = typography. generateLayout ( compatibleWith: traits)
147+
148+ // The returned font should not exceed the requested maximum
149+ XCTAssertEqual ( layout. font. pointSize, size. fontSize * scaleFactor)
150+ // The returned line height should not exceed the requested maximum
121151 XCTAssertEqual ( layout. lineHeight, size. lineHeight * scaleFactor)
122152 // baselineOffset should be >= 0 and pixel-aligned
123153 XCTAssertGreaterThanOrEqual ( layout. baselineOffset, 0 )
@@ -157,6 +187,64 @@ final class TypographyFontTests: XCTestCase {
157187 }
158188 }
159189#endif
190+
191+ func test_maximumPointSize( ) {
192+ // Given
193+ let factors : [ CGFloat ? ] = [ nil , 1.5 , 2.0 , 2.5 ]
194+
195+ factors. forEach {
196+ let pointSize = CGFloat ( Int . random ( in: 10 ... 32 ) )
197+ let sut = Typography (
198+ fontFamily: AppleSDGothicNeoInfo ( ) ,
199+ fontWeight: . bold,
200+ fontSize: pointSize,
201+ lineHeight: ceil ( pointSize * 1.4 ) ,
202+ maximumScaleFactor: $0
203+ )
204+
205+ let maximumPointSize = sut. maximumPointSize
206+ if let factor = $0 {
207+ XCTAssertEqual ( maximumPointSize, pointSize * factor)
208+ } else {
209+ XCTAssertNil ( maximumPointSize)
210+ }
211+ }
212+ }
213+
214+ func test_getMaximumPointSize_withoutMaximumScaleFactor( ) {
215+ // Given
216+ let sut = Typography (
217+ fontFamily: AppleSDGothicNeoInfo ( ) ,
218+ fontWeight: . bold,
219+ fontSize: 12 ,
220+ lineHeight: 24
221+ )
222+ let maximumPointSize = CGFloat ( Int . random ( in: 16 ... 48 ) )
223+
224+ // Then
225+ XCTAssertNil ( sut. maximumPointSize)
226+ XCTAssertNil ( sut. getMaximumPointSize ( nil ) )
227+ XCTAssertEqual ( sut. getMaximumPointSize ( maximumPointSize) , maximumPointSize)
228+ }
229+
230+ func test_getMaximumPointSize_withMaximumScaleFactor( ) {
231+ // Given
232+ let sut = Typography (
233+ fontFamily: AppleSDGothicNeoInfo ( ) ,
234+ fontWeight: . bold,
235+ fontSize: 12 ,
236+ lineHeight: 24 ,
237+ maximumScaleFactor: 2
238+ )
239+ let lowerPointSize = CGFloat ( Int . random ( in: 13 ..< 24 ) )
240+ let higherPointSize = CGFloat ( Int . random ( in: 25 ... 48 ) )
241+
242+ // Then
243+ XCTAssertEqual ( sut. maximumPointSize, 24 )
244+ XCTAssertEqual ( sut. getMaximumPointSize ( nil ) , sut. maximumPointSize)
245+ XCTAssertEqual ( sut. getMaximumPointSize ( lowerPointSize) , lowerPointSize)
246+ XCTAssertEqual ( sut. getMaximumPointSize ( higherPointSize) , sut. maximumPointSize)
247+ }
160248}
161249
162250struct AppleSDGothicNeoInfo : FontFamily {
0 commit comments