-
Notifications
You must be signed in to change notification settings - Fork 5
/
list.go
63 lines (51 loc) · 1.14 KB
/
list.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
package gohamcrest
import (
"container/list"
"fmt"
)
type emptyList struct {
reason string
}
func (this *emptyList) Match(actual interface{}) bool {
list, ok := actual.(*list.List)
if ok {
return list==nil||list.Len()== 0
}else{
panic(fmt.Sprintf("type not match List.list,%T(actual)",list))
}
return false
}
func (this *emptyList)FailReason(actual interface{})string {
return fmt.Sprintf(this.reason,actual,LOGIC_NOT)
}
func (this *emptyList)NegationFailReason(actual interface{})string {
return fmt.Sprintf(this.reason,actual)
}
func EmptyList() Matcher {
return &emptyList{
reason:"list is %s nil, %v(actual)",
}
}
type hasItems struct {
BaseMatcher
}
func (this *hasItems) Match(actual interface{}) bool {
list, ok := actual.(*list.List)
if !ok {
panic(fmt.Sprintf("type not match List.list,%T(actual)",list))
}
flag := false
for e := list.Front(); e != nil; e = e.Next() {
if e.Value == this.Expected {
flag = true
break
}
}
return flag
}
func HasItems(expected interface{}) Matcher {
matcher := &hasItems{}
matcher.Expected=expected
matcher.Reason="List: %v is %s contain %v(excepted)"
return matcher
}