@@ -13,24 +13,58 @@ final class TypogaphyTests: XCTestCase {
13
13
func testInit( ) {
14
14
// test the default initializer
15
15
let avenir = DefaultFontFamily ( familyName: " AvenirNext " )
16
- let typeInfo = Typography ( fontFamily: avenir, fontWeight: . bold, fontSize: 16 , lineHeight: 24 )
17
-
18
- XCTAssertNotNil ( typeInfo. generateLayout ( compatibleWith: . default) )
16
+ let typeInfo = Typography ( fontFamily: avenir, fontWeight: . regular, fontSize: 16 , lineHeight: 24 )
17
+ let layout = typeInfo. generateLayout ( compatibleWith: . default)
18
+
19
+ XCTAssertEqual ( layout. font. familyName, " Avenir Next " )
19
20
_testDefaults ( typeInfo)
20
21
}
21
22
22
23
func testInit2( ) {
23
24
// test the convenience initializer
24
- let typeInfo = Typography ( familyName: " AvenirNext " , fontWeight: . bold, fontSize: 16 , lineHeight: 24 )
25
-
26
- XCTAssertNotNil ( typeInfo. generateLayout ( compatibleWith: . default) )
25
+ let typeInfo = Typography ( familyName: " AvenirNext " , fontWeight: . regular, fontSize: 16 , lineHeight: 24 )
26
+ let layout = typeInfo. generateLayout ( compatibleWith: . default)
27
+
28
+ XCTAssertEqual ( layout. font. familyName, " Avenir Next " )
27
29
_testDefaults ( typeInfo)
28
30
}
29
31
32
+ func testFactory( ) throws {
33
+ // Given
34
+ Typography . factory = NotoSansFactory ( )
35
+ try UIFont . register ( name: " NotoSans-Regular " )
36
+ addTeardownBlock {
37
+ Typography . factory = DefaultFontFamilyFactory ( )
38
+ try UIFont . unregister ( name: " NotoSans-Regular " )
39
+ }
40
+
41
+ // When
42
+ let typeInfo = Typography ( familyName: " AvenirNext " , fontWeight: . regular, fontSize: 16 , lineHeight: 24 )
43
+ let layout = typeInfo. generateLayout ( compatibleWith: . default)
44
+
45
+ // Then
46
+ XCTAssertEqual ( layout. font. familyName, " Noto Sans " )
47
+ }
48
+
30
49
private func _testDefaults( _ typography: Typography ) {
31
50
// Confirm default init parameter values
32
51
XCTAssertEqual ( typography. letterSpacing, 0 )
33
52
XCTAssertEqual ( typography. textStyle, UIFont . TextStyle. body)
34
53
XCTAssertFalse ( typography. isFixed)
35
54
}
36
55
}
56
+
57
+ struct NotoSansFontFamily : FontFamily {
58
+ let familyName = " NotoSans "
59
+ }
60
+
61
+ extension Typography {
62
+ static let notoSans = NotoSansFontFamily ( )
63
+ }
64
+
65
+ struct NotoSansFactory : FontFamilyFactory {
66
+ // Always returns Noto Sans font family
67
+ func getFontFamily( familyName: String , style: YMatterType . Typography . FontStyle ) -> YMatterType . FontFamily {
68
+ Typography . notoSans
69
+ }
70
+ }
0 commit comments