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