-
Notifications
You must be signed in to change notification settings - Fork 104
/
UnkeyedBoxTests.swift
60 lines (49 loc) · 1.57 KB
/
UnkeyedBoxTests.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
//
// UnkeyedBoxTests.swift
// XMLCoderTests
//
// Created by Vincent Esche on 12/18/18.
//
import XCTest
@testable import XMLCoder
class UnkeyedBoxTests: XCTestCase {
typealias Boxed = UnkeyedBox
let box = Boxed([StringBox("foo"), IntBox(42)])
func testIsNull() {
let box = Boxed()
XCTAssertEqual(box.isNull, false)
}
func testUnbox() {
let unboxed = box.unbox()
XCTAssertEqual(unboxed.count, 2)
XCTAssertEqual(unboxed[0] as? StringBox, StringBox("foo"))
XCTAssertEqual(unboxed[1] as? IntBox, IntBox(42))
}
func testXMLString() {
XCTAssertEqual(box.xmlString(), nil)
}
func testDescription() {
XCTAssertEqual(box.description, "[foo, 42]")
}
func testSequence() {
let sequence = IteratorSequence(box.makeIterator())
let array: [Box] = Array(sequence)
XCTAssertEqual(array[0] as? StringBox, StringBox("foo"))
XCTAssertEqual(array[1] as? IntBox, IntBox(42))
}
func testSubscript() {
let box = Boxed([StringBox("foo"), IntBox(42)])
box[0] = NullBox()
XCTAssertEqual(box.count, 2)
XCTAssertEqual(box[0] as? NullBox, NullBox())
XCTAssertEqual(box[1] as? IntBox, IntBox(42))
}
func testInsertAt() {
let box = Boxed([StringBox("foo"), IntBox(42)])
box.insert(NullBox(), at: 1)
XCTAssertEqual(box.count, 3)
XCTAssertEqual(box[0] as? StringBox, StringBox("foo"))
XCTAssertEqual(box[1] as? NullBox, NullBox())
XCTAssertEqual(box[2] as? IntBox, IntBox(42))
}
}