blob: a00e50cecb1bfbe57f0d1a2f6e071f1def18e3ed (
plain)
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
|
import Foundation
import Testing
@testable import NorgKit
struct TaskStatusTests {
@Test func parsesEveryMarker() {
#expect(TaskStatus(marker: " ") == .undone)
#expect(TaskStatus(marker: "x") == .done)
#expect(TaskStatus(marker: "?") == .needsInput)
#expect(TaskStatus(marker: "!") == .urgent)
#expect(TaskStatus(marker: "+") == .recurring)
#expect(TaskStatus(marker: "-") == .pending)
#expect(TaskStatus(marker: "=") == .onHold)
#expect(TaskStatus(marker: "_") == .cancelled)
}
@Test func rejectsUnknownMarker() {
#expect(TaskStatus(marker: "z") == nil)
}
@Test func parsesEveryMarkerByte() {
#expect(TaskStatus(markerByte: UInt8(ascii: " ")) == .undone)
#expect(TaskStatus(markerByte: UInt8(ascii: "x")) == .done)
#expect(TaskStatus(markerByte: UInt8(ascii: "?")) == .needsInput)
#expect(TaskStatus(markerByte: UInt8(ascii: "!")) == .urgent)
#expect(TaskStatus(markerByte: UInt8(ascii: "+")) == .recurring)
#expect(TaskStatus(markerByte: UInt8(ascii: "-")) == .pending)
#expect(TaskStatus(markerByte: UInt8(ascii: "=")) == .onHold)
#expect(TaskStatus(markerByte: UInt8(ascii: "_")) == .cancelled)
}
@Test func rejectsUnknownMarkerByte() {
#expect(TaskStatus(markerByte: UInt8(ascii: "z")) == nil)
}
@Test func idEqualsRawValue() {
for status in TaskStatus.allCases {
#expect(status.id == status.rawValue)
}
}
@Test func rawValuesMatchMarkers() {
#expect(TaskStatus.undone.rawValue == " ")
#expect(TaskStatus.done.rawValue == "x")
#expect(TaskStatus.allCases.count == 8)
}
@Test func roundTripsThroughJSON() throws {
let data = try JSONEncoder().encode(TaskStatus.urgent)
#expect(try JSONDecoder().decode(TaskStatus.self, from: data) == .urgent)
}
}
|