@@ -4,57 +4,47 @@ import XCTest
4
4
class DecodingTests : XCTestCase {
5
5
6
6
func testDecodeEmptyString( ) throws {
7
- let decoded = try " " . base64decoded ( )
8
- XCTAssertEqual ( decoded. count, 0 )
7
+ var decoded : [ UInt8 ] ?
8
+ XCTAssertNoThrow ( decoded = try " " . base64decoded ( ) )
9
+ XCTAssertEqual ( decoded? . count, 0 )
9
10
}
10
11
11
12
func testBase64DecodingArrayOfNulls( ) throws {
12
13
let expected = Array ( repeating: UInt8 ( 0 ) , count: 10 )
13
- let decoded = try " AAAAAAAAAAAAAA== " . base64decoded ( )
14
+ var decoded : [ UInt8 ] ?
15
+ XCTAssertNoThrow ( decoded = try " AAAAAAAAAAAAAA== " . base64decoded ( ) )
14
16
XCTAssertEqual ( decoded, expected)
15
17
}
16
18
17
- func testBase64DecodingAllTheBytesSequentially( ) throws {
19
+ func testBase64DecodingAllTheBytesSequentially( ) {
18
20
let base64 = " AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w== "
19
21
20
22
let expected = Array ( UInt8 ( 0 ) ... UInt8 ( 255 ) )
21
- let decoded = try base64. base64decoded ( )
23
+ var decoded : [ UInt8 ] ?
24
+ XCTAssertNoThrow ( decoded = try base64. base64decoded ( ) )
22
25
23
26
XCTAssertEqual ( decoded, expected)
24
27
}
25
28
26
- func testBase64UrlDecodingAllTheBytesSequentially( ) throws {
29
+ func testBase64UrlDecodingAllTheBytesSequentially( ) {
27
30
let base64 = " AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0-P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn-AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq-wsbKztLW2t7i5uru8vb6_wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t_g4eLj5OXm5-jp6uvs7e7v8PHy8_T19vf4-fr7_P3-_w== "
28
31
29
32
let expected = Array ( UInt8 ( 0 ) ... UInt8 ( 255 ) )
30
- let decoded = try base64. base64decoded ( options: . base64UrlAlphabet)
33
+ var decoded : [ UInt8 ] ?
34
+ XCTAssertNoThrow ( decoded = try base64. base64decoded ( options: . base64UrlAlphabet) )
31
35
32
36
XCTAssertEqual ( decoded, expected)
33
37
}
34
38
35
39
func testBase64DecodingWithPoop( ) {
36
- do {
37
- _ = try " 💩 " . base64decoded ( )
38
- XCTFail ( " This point should not be reached " )
39
- }
40
- catch Base64 . DecodingError . invalidCharacter( _) {
41
-
42
- }
43
- catch {
44
- XCTFail ( " Unexpected error: \( error) " )
40
+ XCTAssertThrowsError ( _ = try " 💩 " . base64decoded ( ) ) { ( error) in
41
+ XCTAssertEqual ( error as? Base64 . DecodingError , . invalidCharacter( 240 ) )
45
42
}
46
43
}
47
44
48
45
func testBase64DecodingWithInvalidLength( ) {
49
- do {
50
- _ = try " AAAAA " . base64decoded ( )
51
- XCTFail ( " This point should not be reached " )
52
- }
53
- catch Base64 . DecodingError . invalidLength {
54
-
55
- }
56
- catch {
57
- XCTFail ( " Unexpected error: \( error) " )
46
+ XCTAssertThrowsError ( _ = try " AAAAA " . base64decoded ( ) ) { ( error) in
47
+ XCTAssertEqual ( error as? Base64 . DecodingError , . invalidLength)
58
48
}
59
49
}
60
50
0 commit comments