-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathall.go
66 lines (59 loc) · 1.42 KB
/
all.go
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
package hamcrest
type AllOfMatcher struct {
Matchers []Matcher
}
func (me *AllOfMatcher) Match(other interface{}) MatchResult {
result := &AllOfResult{}
for _, matcher := range me.Matchers {
mResult := matcher.Match(other)
if !mResult.Matched() {
result.Failures = append(result.Failures, mResult)
} else {
result.Sucesses = append(result.Sucesses, mResult)
}
}
return result
}
func (me *AllOfMatcher) WriteDescription(writer DescriptionWriter) {
writer.WriteString(" All of the following:( ")
writer.NewLine()
for idx, matcher := range me.Matchers {
if idx > 0 {
writer.NewLine()
writer.IncreaseIndent(2)
writer.WriteString(" - AND - ")
writer.DecreaseIndent(2)
writer.NewLine()
}
matcher.WriteDescription(writer)
}
writer.WriteString(" ) ")
}
type AllOfResult struct {
Failures []MatchResult
Sucesses []MatchResult
}
func (me *AllOfResult) Matched() bool {
return len(me.Failures) == 0
}
func (me *AllOfResult) WriteFailureReason(output DescriptionWriter) {
if me.Matched() {
output.WriteString("All Matched (")
reset := output.IncreaseIndent(1)
for _, item := range me.Sucesses {
output.NewLine()
item.WriteFailureReason(output)
}
reset()
output.NewLine()
} else {
output.WriteString("All Of (")
output.IncreaseIndent(1)
for _, item := range me.Failures {
output.NewLine()
item.WriteFailureReason(output)
}
output.DecreaseIndent(1)
}
output.WriteString(")")
}