2016-05-24 19:55:46 +00:00
|
|
|
package assert
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2016-11-27 20:39:09 +00:00
|
|
|
func (v *Assert) String(value string) *StringSubject {
|
2016-05-24 19:55:46 +00:00
|
|
|
return &StringSubject{
|
|
|
|
Subject: Subject{
|
2016-11-27 20:39:09 +00:00
|
|
|
a: v,
|
2016-05-24 19:55:46 +00:00
|
|
|
disp: value,
|
|
|
|
},
|
|
|
|
value: value,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type StringSubject struct {
|
|
|
|
Subject
|
|
|
|
value string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (subject *StringSubject) Equals(expectation string) {
|
|
|
|
if subject.value != expectation {
|
|
|
|
subject.Fail("is equal to", expectation)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (subject *StringSubject) NotEquals(expectation string) {
|
|
|
|
if subject.value == expectation {
|
|
|
|
subject.Fail("is not equal to ", expectation)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (subject *StringSubject) Contains(substring string) {
|
|
|
|
if !strings.Contains(subject.value, substring) {
|
|
|
|
subject.Fail("contains", substring)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (subject *StringSubject) NotContains(substring string) {
|
|
|
|
if strings.Contains(subject.value, substring) {
|
|
|
|
subject.Fail("doesn't contain", substring)
|
|
|
|
}
|
|
|
|
}
|
2017-04-11 14:58:51 +00:00
|
|
|
|
|
|
|
func (subject *StringSubject) IsEmpty() {
|
|
|
|
if len(subject.value) > 0 {
|
|
|
|
subject.FailWithMessage("is not empty.")
|
|
|
|
}
|
|
|
|
}
|