-
Notifications
You must be signed in to change notification settings - Fork 104
/
DateBoxTests.swift
149 lines (119 loc) · 3.5 KB
/
DateBoxTests.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//
// DateBoxTests.swift
// XMLCoderTests
//
// Created by Vincent Esche on 12/19/18.
//
import XCTest
@testable import XMLCoder
class DateBoxTests: XCTestCase {
typealias Boxed = DateBox
let customFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
return formatter
}()
func testIsNull() {
let box = Boxed(Date(), format: .iso8601)
XCTAssertEqual(box.isNull, false)
}
func testUnbox() {
let values: [Boxed.Unboxed] = [
Date(timeIntervalSince1970: 0.0),
Date(timeIntervalSinceReferenceDate: 0.0),
Date(),
]
for unboxed in values {
let box = Boxed(unboxed, format: .iso8601)
XCTAssertEqual(box.unboxed, unboxed)
}
}
func testValidStrings_secondsSince1970() {
let xmlStrings = [
"-1000.0",
"0.0",
"1000.0",
]
for xmlString in xmlStrings {
let boxOrNil = Boxed(secondsSince1970: xmlString)
XCTAssertNotNil(boxOrNil)
guard let box = boxOrNil else { continue }
XCTAssertEqual(box.xmlString, xmlString)
}
}
func testValidStrings_millisecondsSince1970() {
let xmlStrings = [
"-1000.0",
"0.0",
"1000.0",
]
for xmlString in xmlStrings {
let boxOrNil = Boxed(millisecondsSince1970: xmlString)
XCTAssertNotNil(boxOrNil)
guard let box = boxOrNil else { continue }
XCTAssertEqual(box.xmlString, xmlString)
}
}
func testValidStrings_iso8601() {
let xmlStrings = [
"1970-01-23T01:23:45Z",
]
for xmlString in xmlStrings {
let boxOrNil = Boxed(iso8601: xmlString)
XCTAssertNotNil(boxOrNil)
guard let box = boxOrNil else { continue }
XCTAssertEqual(box.xmlString, xmlString)
}
}
func testValidStrings_formatter() {
let xmlStrings = [
"1970-01-23 01:23:45",
]
for xmlString in xmlStrings {
let boxOrNil = Boxed(xmlString: xmlString, formatter: customFormatter)
XCTAssertNotNil(boxOrNil)
guard let box = boxOrNil else { continue }
XCTAssertEqual(box.xmlString, xmlString)
}
}
func testInvalidStrings_secondsSince1970() {
let xmlStrings = [
"lorem ipsum",
"",
]
for xmlString in xmlStrings {
let boxOrNil = Boxed(secondsSince1970: xmlString)
XCTAssertNil(boxOrNil)
}
}
func testInvalidStrings_millisecondsSince1970() {
let xmlStrings = [
"lorem ipsum",
"",
]
for xmlString in xmlStrings {
let boxOrNil = Boxed(millisecondsSince1970: xmlString)
XCTAssertNil(boxOrNil)
}
}
func testInvalidStrings_iso8601() {
let xmlStrings = [
"lorem ipsum",
"",
]
for xmlString in xmlStrings {
let boxOrNil = Boxed(iso8601: xmlString)
XCTAssertNil(boxOrNil)
}
}
func testInvalidStrings_formatter() {
let xmlStrings = [
"lorem ipsum",
"",
]
for xmlString in xmlStrings {
let boxOrNil = Boxed(xmlString: xmlString, formatter: customFormatter)
XCTAssertNil(boxOrNil)
}
}
}