mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-04-27 16:09:08 -04:00
simplify testing
This commit is contained in:
44
testing/assert/string.go
Normal file
44
testing/assert/string.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package assert
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (this *Assert) String(value string) *StringSubject {
|
||||
return &StringSubject{
|
||||
Subject: Subject{
|
||||
a: this,
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user