1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-09 03:37:37 -05:00
v2fly/testing/assert/stringsubject.go

54 lines
1.4 KiB
Go
Raw Normal View History

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 {
2015-12-02 11:27:55 -05:00
return String(serial.StringLiteral((value)))
2015-12-02 10:41:19 -05:00
}
func String(value serial.String) *StringSubject {
return &StringSubject{value: value}
2015-09-09 09:18:29 -04: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 {
subject.Fail(subject.DisplayString(), "is equal to", serial.StringLiteral(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 {
subject.Fail(subject.DisplayString(), "is not equal to ", serial.StringLiteral(expectation))
}
}
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)
}
}