-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestableVisitor.swift
85 lines (69 loc) · 1.71 KB
/
TestableVisitor.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
@testable import PGNKit
final class TestableVisitor: Visitor {
typealias VisitorResult = Void
var events: [VisitorEvent] = []
var nags: [Nag] {
var result = [Nag]()
for event in events {
if case let .nag(nag) = event {
result.append(nag)
}
}
return result
}
var sans: [String] {
var result = [String]()
for event in events {
if case let .san(san) = event {
result.append(san)
}
}
return result
}
func beginGame() {
events.append(.beginGame)
}
func beginHeaders() {
events.append(.beginHeaders)
}
func header(key: String, value: String) {
events.append(.header(key: key, value: value))
}
func endHeaders() {
events.append(.endHeaders)
}
func san(_ san: String) {
events.append(.san(san))
}
func nag(_ nag: PGNKit.Nag) {
events.append(.nag(nag))
}
func comment(_ comment: String) {
events.append(.comment(comment))
}
func beginVariation() {
events.append(.beginVariation)
}
func endVariation() {
events.append(.endVariation)
}
func outcome(_ outcome: PGNKit.Outcome) {
events.append(.outcome(outcome))
}
func endGame() {
events.append(.endGame)
}
}
enum VisitorEvent: Hashable {
case beginGame
case beginHeaders
case header(key: String, value: String)
case endHeaders
case san(String)
case nag(Nag)
case comment(String)
case beginVariation
case endVariation
case outcome(Outcome)
case endGame
}