-
Notifications
You must be signed in to change notification settings - Fork 104
/
KeyedBoxTests.swift
64 lines (52 loc) · 1.75 KB
/
KeyedBoxTests.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
60
61
62
63
64
//
// UnkeyedBoxTests.swift
// XMLCoderTests
//
// Created by Vincent Esche on 12/18/18.
//
import XCTest
@testable import XMLCoder
class KeyedBoxTests: XCTestCase {
typealias Boxed = KeyedBox
let box = Boxed(
elements: ["foo": StringBox("bar"), "baz": IntBox(42)],
attributes: ["baz": StringBox("blee")]
)
func testIsNull() {
let box = Boxed()
XCTAssertEqual(box.isNull, false)
}
func testUnbox() {
let (elements, attributes) = box.unbox()
XCTAssertEqual(elements.count, 2)
XCTAssertEqual(elements["foo"] as? StringBox, StringBox("bar"))
XCTAssertEqual(elements["baz"] as? IntBox, IntBox(42))
XCTAssertEqual(attributes.count, 1)
XCTAssertEqual(attributes["baz"] as? StringBox, StringBox("blee"))
}
func testXMLString() {
XCTAssertEqual(box.xmlString(), nil)
}
func testDescription() {
// FIXME: once we have an order-preserving storage
// we can check against the full description:
let description = box.description
XCTAssertTrue(description.contains("\"foo\": bar"))
XCTAssertTrue(description.contains("\"baz\": 42"))
}
func testSequence() {
var sortedElements: [(String, Box)] = Array(box.elements)
sortedElements.sort { $0.0 < $1.0 }
XCTAssertEqual(sortedElements[0].0, "baz")
XCTAssertEqual(sortedElements[1].0, "foo")
}
func testSubscript() {
let box = Boxed(
elements: ["foo": StringBox("bar"), "baz": IntBox(42)],
attributes: ["baz": StringBox("blee")]
)
box.elements["bar"] = NullBox()
XCTAssertEqual(box.elements.count, 3)
XCTAssertEqual(box.elements["bar"] as? NullBox, NullBox())
}
}