当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
1 Star 5 Fork 1

joe_chou / tug
暂停

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
list.go 1.36 KB
一键复制 编辑 原始数据 按行查看 历史
joezou 提交于 2017-11-26 21:38 . refactor list
package tug
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 (this *hasItems)FailReason(actual interface{})string {
return fmt.Sprintf(this.Reason,EMPTY,this.Expected)
}
func (this *hasItems)NegationFailReason(actual interface{})string {
return fmt.Sprintf(this.Reason,LOGIC_NOT,this.Expected)
}
func HasItems(expected interface{}) Matcher {
matcher := &hasItems{}
matcher.Expected=expected
matcher.Reason="list is %s contain %v(excepted)"
return matcher
}
Go
1
https://gitee.com/joezou/tug.git
git@gitee.com:joezou/tug.git
joezou
tug
tug
master

搜索帮助