1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/joezou-tug

Клонировать/Скачать
string.go 1.2 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
joezou Отправлено 26.11.2017 16:38 f9d7c5a
package tug
import (
"strings"
)
func toString(o interface{}) string {
return o.(string)
}
type startWith struct {
BaseMatcher
}
func (this *startWith) Match(actual interface{}) bool {
excepted := toString(this.Expected)
if str, ok := actual.(string); ok {
return strings.HasPrefix(str, excepted)
}
return false
}
func StartWith(expected string) Matcher {
matcher := &startWith{}
matcher.Expected=expected
matcher.Reason="%v %s start with %v"
return matcher
}
type endWith struct {
BaseMatcher
}
func (this *endWith) Match(actual interface{}) bool {
excepted := toString(this.Expected)
if str, ok := actual.(string); ok {
return strings.HasSuffix(str, excepted)
}
return false
}
func EndWith(expected string) Matcher {
matcher := &endWith{}
matcher.Expected=expected
matcher.Reason="%v %s end with %v"
return matcher
}
type containString struct {
BaseMatcher
}
func (this *containString) Match(actual interface{}) bool {
excepted := toString(this.Expected)
if str, ok := actual.(string); ok {
return strings.Contains(str, excepted)
}
return false
}
func ContainString(expected string) Matcher {
matcher := &containString{}
matcher.Expected=expected
matcher.Reason="%v %s contain %v"
return matcher
}

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/joezou-tug.git
git@api.gitlife.ru:oschina-mirror/joezou-tug.git
oschina-mirror
joezou-tug
joezou-tug
master