2015-12-02 09:27:18 -05:00
|
|
|
package assert
|
2015-09-09 09:18:29 -04:00
|
|
|
|
2015-12-02 10:41:19 -05:00
|
|
|
import (
|
2015-12-05 15:10:14 -05:00
|
|
|
"strings"
|
|
|
|
|
2015-12-02 11:27:55 -05:00
|
|
|
"github.com/v2ray/v2ray-core/common/serial"
|
2015-12-02 10:41:19 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func StringLiteral(value string) *StringSubject {
|
2016-05-23 14:23:40 -04:00
|
|
|
return String(serial.StringT((value)))
|
2015-12-02 10:41:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func String(value serial.String) *StringSubject {
|
2015-12-02 09:27:18 -05:00
|
|
|
return &StringSubject{value: value}
|
2015-09-09 09:18:29 -04:00
|
|
|
}
|
|
|
|
|
2015-12-02 09:27:18 -05:00
|
|
|
type StringSubject struct {
|
|
|
|
Subject
|
2015-12-02 10:41:19 -05:00
|
|
|
value serial.String
|
2015-09-09 09:18:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (subject *StringSubject) Named(name string) *StringSubject {
|
|
|
|
subject.Subject.Named(name)
|
|
|
|
return subject
|
|
|
|
}
|
|
|
|
|
|
|
|
func (subject *StringSubject) DisplayString() string {
|
2015-12-02 10:41:19 -05:00
|
|
|
return subject.Subject.DisplayString(subject.value.String())
|
2015-09-09 09:18:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (subject *StringSubject) Equals(expectation string) {
|
2015-12-02 10:41:19 -05:00
|
|
|
if subject.value.String() != expectation {
|
2016-05-23 14:23:40 -04:00
|
|
|
subject.Fail(subject.DisplayString(), "is equal to", serial.StringT(expectation))
|
2015-09-09 09:18:29 -04:00
|
|
|
}
|
|
|
|
}
|
2015-12-05 15:10:14 -05:00
|
|
|
|
2015-12-12 07:11:49 -05:00
|
|
|
func (subject *StringSubject) NotEquals(expectation string) {
|
|
|
|
if subject.value.String() == expectation {
|
2016-05-23 14:23:40 -04:00
|
|
|
subject.Fail(subject.DisplayString(), "is not equal to ", serial.StringT(expectation))
|
2015-12-12 07:11:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-05 15:10:14 -05:00
|
|
|
func (subject *StringSubject) Contains(substring serial.String) {
|
|
|
|
if !strings.Contains(subject.value.String(), substring.String()) {
|
|
|
|
subject.Fail(subject.DisplayString(), "contains", substring)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (subject *StringSubject) NotContains(substring serial.String) {
|
|
|
|
if strings.Contains(subject.value.String(), substring.String()) {
|
|
|
|
subject.Fail(subject.DisplayString(), "doesn't contain", substring)
|
|
|
|
}
|
|
|
|
}
|