-
Notifications
You must be signed in to change notification settings - Fork 104
/
DataBoxTests.swift
59 lines (48 loc) · 1.3 KB
/
DataBoxTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// DataBoxTests.swift
// XMLCoderTests
//
// Created by Vincent Esche on 12/19/18.
//
import XCTest
@testable import XMLCoder
class DataBoxTests: XCTestCase {
typealias Boxed = DataBox
func testIsNull() {
let box = Boxed(Data(), format: .base64)
XCTAssertEqual(box.isNull, false)
}
func testUnbox() {
let values: [Boxed.Unboxed] = [
Data(base64Encoded: "bG9yZW0gaXBzdW0=")!,
Data(),
]
for unboxed in values {
let box = Boxed(unboxed, format: .base64)
XCTAssertEqual(box.unboxed, unboxed)
}
}
func testValidXMLStrings_base64() {
let xmlStrings = [
"",
"bG9yZW0gaXBzdW0=",
"ZG9sb3Igc2l0IGFtZXQ=",
"Y29uc2VjdGV0dXIgYWRpcGlzY2luZyBlbGl0",
]
for xmlString in xmlStrings {
let boxOrNil = DataBox(base64: xmlString)
XCTAssertNotNil(boxOrNil)
guard let box = boxOrNil else { continue }
XCTAssertEqual(box.xmlString(), xmlString)
}
}
func testInvalidXMLStrings_base64() {
let xmlStrings = [
"lorem ipsum",
]
for xmlString in xmlStrings {
let box = Boxed(base64: xmlString)
XCTAssertNil(box)
}
}
}