-
Notifications
You must be signed in to change notification settings - Fork 0
/
stringsubject.go
53 lines (42 loc) · 1.36 KB
/
stringsubject.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package assert
import (
"strings"
"github.com/v2ray/v2ray-core/common/serial"
)
func StringLiteral(value string) *StringSubject {
return String(serial.StringLiteral((value)))
}
func String(value serial.String) *StringSubject {
return &StringSubject{value: value}
}
type StringSubject struct {
Subject
value serial.String
}
func (subject *StringSubject) Named(name string) *StringSubject {
subject.Subject.Named(name)
return subject
}
func (subject *StringSubject) DisplayString() string {
return subject.Subject.DisplayString(subject.value.String())
}
func (subject *StringSubject) Equals(expectation string) {
if subject.value.String() != expectation {
subject.Fail(subject.DisplayString(), "is equal to", serial.StringLiteral(expectation))
}
}
func (subject *StringSubject) NotEquals(expectation string) {
if subject.value.String() == expectation {
subject.Fail(subject.DisplayString(), "is not equal to ", serial.StringLiteral(expectation))
}
}
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)
}
}