@@ -11,56 +11,63 @@ class TestURLResponse : XCTestCase {
11
11
static var allTests : [ ( String , ( TestURLResponse ) -> ( ) throws -> Void ) ] {
12
12
return [
13
13
( " test_URL " , test_URL) ,
14
- ( " test_MIMEType_1 " , test_MIMEType_1) ,
15
- ( " test_MIMEType_2 " , test_MIMEType_2) ,
14
+ ( " test_MIMEType " , test_MIMEType) ,
16
15
( " test_ExpectedContentLength " , test_ExpectedContentLength) ,
17
16
( " test_TextEncodingName " , test_TextEncodingName) ,
18
- ( " test_suggestedFilename " , test_suggestedFilename ) ,
17
+ ( " test_suggestedFilename_1 " , test_suggestedFilename_1 ) ,
19
18
( " test_suggestedFilename_2 " , test_suggestedFilename_2) ,
20
19
( " test_suggestedFilename_3 " , test_suggestedFilename_3) ,
21
20
( " test_copywithzone " , test_copyWithZone) ,
22
21
( " test_NSCoding " , test_NSCoding) ,
23
22
]
24
23
}
25
24
25
+ let testURL = URL ( string: " test " ) !
26
+
26
27
func test_URL( ) {
27
28
let url = URL ( string: " a/test/path " ) !
28
29
let res = URLResponse ( url: url, mimeType: " txt " , expectedContentLength: 0 , textEncodingName: nil )
29
30
XCTAssertEqual ( res. url, url, " should be the expected url " )
30
31
}
31
32
32
- func test_MIMEType_1 ( ) {
33
- let mimetype = " text/plain "
34
- let res = URLResponse ( url: URL ( string : " test " ) ! , mimeType: mimetype, expectedContentLength: 0 , textEncodingName: nil )
33
+ func test_MIMEType ( ) {
34
+ var mimetype : String ? = " text/plain "
35
+ var res = URLResponse ( url: testURL , mimeType: mimetype, expectedContentLength: 0 , textEncodingName: nil )
35
36
XCTAssertEqual ( res. mimeType, mimetype, " should be the passed in mimetype " )
36
- }
37
-
38
- func test_MIMEType_2( ) {
39
- let mimetype = " APPlication/wordperFECT "
40
- let res = URLResponse ( url: URL ( string: " test " ) !, mimeType: mimetype, expectedContentLength: 0 , textEncodingName: nil )
37
+
38
+ mimetype = " APPlication/wordperFECT "
39
+ res = URLResponse ( url: testURL, mimeType: mimetype, expectedContentLength: 0 , textEncodingName: nil )
40
+ XCTAssertEqual ( res. mimeType, mimetype, " should be the other mimetype " )
41
+
42
+ mimetype = nil
43
+ res = URLResponse ( url: testURL, mimeType: mimetype, expectedContentLength: 0 , textEncodingName: nil )
41
44
XCTAssertEqual ( res. mimeType, mimetype, " should be the other mimetype " )
42
45
}
43
-
46
+
44
47
func test_ExpectedContentLength( ) {
45
- let zeroContentLength = 0
46
- let positiveContentLength = 100
47
- let url = URL ( string: " test " ) !
48
- let res1 = URLResponse ( url: url, mimeType: " text/plain " , expectedContentLength: zeroContentLength, textEncodingName: nil )
49
- XCTAssertEqual ( res1. expectedContentLength, Int64 ( zeroContentLength) , " should be Int65 of the zero length " )
50
- let res2 = URLResponse ( url: url, mimeType: " text/plain " , expectedContentLength: positiveContentLength, textEncodingName: nil )
51
- XCTAssertEqual ( res2. expectedContentLength, Int64 ( positiveContentLength) , " should be Int64 of the positive content length " )
48
+ var contentLength = 100
49
+ var res = URLResponse ( url: testURL, mimeType: " text/plain " , expectedContentLength: contentLength, textEncodingName: nil )
50
+ XCTAssertEqual ( res. expectedContentLength, Int64 ( contentLength) , " should be positive Int64 content length " )
51
+
52
+ contentLength = 0
53
+ res = URLResponse ( url: testURL, mimeType: nil , expectedContentLength: contentLength, textEncodingName: nil )
54
+ XCTAssertEqual ( res. expectedContentLength, Int64 ( contentLength) , " should be zero Int64 content length " )
55
+
56
+ contentLength = - 1
57
+ res = URLResponse ( url: testURL, mimeType: nil , expectedContentLength: contentLength, textEncodingName: nil )
58
+ XCTAssertEqual ( res. expectedContentLength, Int64 ( contentLength) , " should be invalid (-1) Int64 content length " )
52
59
}
53
60
54
61
func test_TextEncodingName( ) {
55
62
let encoding = " utf8 "
56
- let url = URL ( string : " test " ) !
57
- let res1 = URLResponse ( url : url , mimeType : nil , expectedContentLength : 0 , textEncodingName : encoding)
58
- XCTAssertEqual ( res1 . textEncodingName , encoding , " should be the utf8 encoding " )
59
- let res2 = URLResponse ( url: url , mimeType: nil , expectedContentLength: 0 , textEncodingName: nil )
60
- XCTAssertNil ( res2 . textEncodingName)
63
+ var res = URLResponse ( url : testURL , mimeType : nil , expectedContentLength : 0 , textEncodingName : encoding )
64
+ XCTAssertEqual ( res . textEncodingName , encoding , " should be the utf8 encoding" )
65
+
66
+ res = URLResponse ( url: testURL , mimeType: nil , expectedContentLength: 0 , textEncodingName: nil )
67
+ XCTAssertNil ( res . textEncodingName)
61
68
}
62
69
63
- func test_suggestedFilename ( ) {
70
+ func test_suggestedFilename_1 ( ) {
64
71
let url = URL ( string: " a/test/name.extension " ) !
65
72
let res = URLResponse ( url: url, mimeType: " txt " , expectedContentLength: 0 , textEncodingName: nil )
66
73
XCTAssertEqual ( res. suggestedFilename, " name.extension " )
@@ -77,6 +84,7 @@ class TestURLResponse : XCTestCase {
77
84
let res = URLResponse ( url: url, mimeType: " txt " , expectedContentLength: 0 , textEncodingName: nil )
78
85
XCTAssertEqual ( res. suggestedFilename, " Unknown " )
79
86
}
87
+
80
88
func test_copyWithZone( ) {
81
89
let url = URL ( string: " a/test/path " ) !
82
90
let res = URLResponse ( url: url, mimeType: " txt " , expectedContentLength: 0 , textEncodingName: nil )
0 commit comments