@@ -39,6 +39,11 @@ class TestNSAttributedString : XCTestCase {
39
39
XCTAssertEqual ( range. location, NSNotFound)
40
40
XCTAssertEqual ( range. length, 0 )
41
41
XCTAssertEqual ( attrs. count, 0 )
42
+
43
+ let attribute = attrString. attribute ( " invalid " , atIndex: 0 , effectiveRange: & range)
44
+ XCTAssertNil ( attribute)
45
+ XCTAssertEqual ( range. location, NSNotFound)
46
+ XCTAssertEqual ( range. length, 0 )
42
47
}
43
48
44
49
func test_initWithStringAndAttributes( ) {
@@ -51,15 +56,27 @@ class TestNSAttributedString : XCTestCase {
51
56
52
57
var range = NSRange ( )
53
58
let attrs = attrString. attributesAtIndex ( 0 , effectiveRange: & range)
54
-
55
59
guard let value = attrs [ " attribute.placeholder.key " ] as? NSString else {
56
60
XCTAssert ( false , " attribute value not found " )
57
61
return
58
62
}
59
-
60
63
XCTAssertEqual ( range. location, 0 )
61
64
XCTAssertEqual ( range. length, attrString. length)
62
65
XCTAssertEqual ( value, " attribute.placeholder.value " )
66
+
67
+ let invalidAttribute = attrString. attribute ( " invalid " , atIndex: 0 , effectiveRange: & range)
68
+ XCTAssertNil ( invalidAttribute)
69
+ XCTAssertEqual ( range. location, NSNotFound)
70
+ XCTAssertEqual ( range. length, 0 )
71
+
72
+ let attribute = attrString. attribute ( " attribute.placeholder.key " , atIndex: 0 , effectiveRange: & range)
73
+ XCTAssertEqual ( range. location, 0 )
74
+ XCTAssertEqual ( range. length, attrString. length)
75
+ guard let validAttribute = attribute as? NSString else {
76
+ XCTAssert ( false , " attribuet not found " )
77
+ return
78
+ }
79
+ XCTAssertEqual ( validAttribute, " attribute.placeholder.value " )
63
80
}
64
81
65
82
}
0 commit comments