@@ -4,100 +4,100 @@ import XCTest
44@testable import Layout
55
66final class AttributedStringExpressionTests : XCTestCase {
7- func testAttributedStringExpressionTextAndFont( ) {
7+ func testAttributedStringExpressionTextAndFont( ) throws {
88 let node = LayoutNode ( )
99 let expression = LayoutExpression ( attributedStringExpression: " foo " , for: node)
10- let result = try ! expression? . evaluate ( ) as! NSAttributedString
10+ let result = try expression? . evaluate ( ) as! NSAttributedString
1111 XCTAssertEqual ( result. string, " foo " )
1212 XCTAssertEqual ( result. attribute ( NSAttributedString . Key. font, at: 0 , effectiveRange: nil ) as? UIFont , . systemFont( ofSize: 17 ) )
1313 }
1414
15- func testAttributedStringHTMLExpression( ) {
15+ func testAttributedStringHTMLExpression( ) throws {
1616 let node = LayoutNode ( )
1717 let expression = LayoutExpression ( attributedStringExpression: " <b>foo</b> " , for: node)
18- let result = try ! expression? . evaluate ( ) as! NSAttributedString
18+ let result = try expression? . evaluate ( ) as! NSAttributedString
1919 XCTAssertEqual ( result. string, " foo " )
2020 XCTAssertEqual ( result. attribute ( NSAttributedString . Key. font, at: 0 , effectiveRange: nil ) as? UIFont , . boldSystemFont( ofSize: 17 ) )
2121 }
2222
23- func testAttributedStringContainingUnicode( ) {
23+ func testAttributedStringContainingUnicode( ) throws {
2424 let node = LayoutNode ( )
2525 let text = " 🤔😂 "
2626 let expression = LayoutExpression ( attributedStringExpression: " <i> \( text) </i> " , for: node)
27- let result = try ! expression? . evaluate ( ) as! NSAttributedString
27+ let result = try expression? . evaluate ( ) as! NSAttributedString
2828 XCTAssertEqual ( result. string, text)
2929 }
3030
31- func testAttributedStringInheritsFont( ) {
31+ func testAttributedStringInheritsFont( ) throws {
3232 let label = UILabel ( )
3333 label. font = UIFont ( name: " Courier " , size: 57 )
3434 let node = LayoutNode ( view: label)
3535 let expression = LayoutExpression ( attributedStringExpression: " foo " , for: node)
36- let result = try ! expression? . evaluate ( ) as! NSAttributedString
36+ let result = try expression? . evaluate ( ) as! NSAttributedString
3737 XCTAssertEqual ( result. attribute ( NSAttributedString . Key. font, at: 0 , effectiveRange: nil ) as? UIFont , label. font)
3838 }
3939
40- func testAttributedStringInheritsTextColor( ) {
40+ func testAttributedStringInheritsTextColor( ) throws {
4141 let label = UILabel ( )
4242 label. textColor = . red
4343 let node = LayoutNode ( view: label)
4444 let expression = LayoutExpression ( attributedStringExpression: " foo " , for: node)
45- let result = try ! expression? . evaluate ( ) as! NSAttributedString
45+ let result = try expression? . evaluate ( ) as! NSAttributedString
4646 XCTAssertEqual ( result. attribute ( NSAttributedString . Key. foregroundColor, at: 0 , effectiveRange: nil ) as? UIColor , . red)
4747 }
4848
49- func testAttributedStringInheritsTextAlignment( ) {
49+ func testAttributedStringInheritsTextAlignment( ) throws {
5050 let label = UILabel ( )
5151 label. textAlignment = . right
5252 let node = LayoutNode ( view: label)
5353 let expression = LayoutExpression ( attributedStringExpression: " foo " , for: node)
54- let result = try ! expression? . evaluate ( ) as! NSAttributedString
54+ let result = try expression? . evaluate ( ) as! NSAttributedString
5555 let paragraphStyle = result. attribute ( NSAttributedString . Key. paragraphStyle, at: 0 , effectiveRange: nil ) as! NSParagraphStyle
5656 XCTAssertEqual ( paragraphStyle. alignment, . right)
5757 }
5858
59- func testAttributedStringInheritsLinebreakMode( ) {
59+ func testAttributedStringInheritsLinebreakMode( ) throws {
6060 let label = UILabel ( )
6161 label. lineBreakMode = . byTruncatingHead
6262 let node = LayoutNode ( view: label)
6363 let expression = LayoutExpression ( attributedStringExpression: " foo " , for: node)
64- let result = try ! expression? . evaluate ( ) as! NSAttributedString
64+ let result = try expression? . evaluate ( ) as! NSAttributedString
6565 let paragraphStyle = result. attribute ( NSAttributedString . Key. paragraphStyle, at: 0 , effectiveRange: nil ) as! NSParagraphStyle
6666 XCTAssertEqual ( paragraphStyle. lineBreakMode, . byTruncatingHead)
6767 }
6868
69- func testAttributedStringContainingStringConstant( ) {
69+ func testAttributedStringContainingStringConstant( ) throws {
7070 let node = LayoutNode ( constants: [ " bar " : " bar " ] )
7171 let expression = LayoutExpression ( attributedStringExpression: " hello world {bar} " , for: node)
72- let result = try ! expression? . evaluate ( ) as! NSAttributedString
72+ let result = try expression? . evaluate ( ) as! NSAttributedString
7373 XCTAssertEqual ( result. string, " hello world bar " )
7474 }
7575
76- func testAttributedStringContainingAttributedStringConstant( ) {
76+ func testAttributedStringContainingAttributedStringConstant( ) throws {
7777 let node = LayoutNode ( constants: [ " bar " : NSAttributedString ( string: " bar " , attributes: [
7878 NSAttributedString . Key. foregroundColor: UIColor . red,
7979 ] ) ] )
8080 let expression = LayoutExpression ( attributedStringExpression: " hello world {bar} " , for: node)
81- let result = try ! expression? . evaluate ( ) as! NSAttributedString
81+ let result = try expression? . evaluate ( ) as! NSAttributedString
8282 XCTAssertEqual ( result. string, " hello world bar " )
8383 XCTAssertEqual ( result. attribute ( NSAttributedString . Key. foregroundColor, at: 12 , effectiveRange: nil ) as? UIColor , . red)
8484 }
8585
86- func testAttributedStringContainingHTMLConstant( ) {
86+ func testAttributedStringContainingHTMLConstant( ) throws {
8787 let node = LayoutNode ( constants: [ " bar " : " <i>bar</i> " ] )
8888 let expression = LayoutExpression ( attributedStringExpression: " <b>foo {bar}</b> " , for: node)
89- let result = try ! expression? . evaluate ( ) as! NSAttributedString
89+ let result = try expression? . evaluate ( ) as! NSAttributedString
9090 XCTAssertEqual ( result. string, " foo bar " )
9191 XCTAssertEqual ( result. attribute ( NSAttributedString . Key. font, at: 0 , effectiveRange: nil ) as? UIFont , . boldSystemFont( ofSize: 17 ) )
9292 let traits = ( result. attribute ( NSAttributedString . Key. font, at: 4 , effectiveRange: nil ) as? UIFont ) ? . fontDescriptor. symbolicTraits
9393 XCTAssert ( traits? . contains ( . traitItalic) == true )
9494 XCTAssert ( traits? . contains ( . traitBold) == true )
9595 }
9696
97- func testAttributedStringContainingAmbiguousTokens( ) {
97+ func testAttributedStringContainingAmbiguousTokens( ) throws {
9898 let node = LayoutNode ( constants: [ " foo " : " $(2) " , " bar " : " $(3) " ] )
9999 let expression = LayoutExpression ( attributedStringExpression: " <b>$(1)</b>{foo}{bar} " , for: node)
100- let result = try ! expression? . evaluate ( ) as! NSAttributedString
100+ let result = try expression? . evaluate ( ) as! NSAttributedString
101101 XCTAssertEqual ( result. string, " $(1)$(2)$(3) " )
102102 }
103103}
0 commit comments