-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstring.go
More file actions
58 lines (48 loc) · 1.09 KB
/
string.go
File metadata and controls
58 lines (48 loc) · 1.09 KB
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
54
55
56
57
58
package gunit
import "strings"
type Stringy interface {
~string
}
func String[S Stringy](t T, actual S) *Str[S] {
return &Str[S]{t, actual}
}
type Str[S Stringy] struct {
T
actual S
}
func (s *Str[S]) EqualTo(expected S) {
s.Helper()
if s.actual != expected {
s.Errorf("wanted <%v> equal to <%v>", s.actual, expected)
}
}
func (s *Str[S]) Contains(needle S) {
s.Helper()
if !strings.Contains(string(s.actual), string(needle)) {
s.Errorf("want <%v> to contain <%v>", s.actual, needle)
}
}
func (s *Str[S]) HasPrefix(prefix S) {
s.Helper()
if !strings.HasPrefix(string(s.actual), string(prefix)) {
s.Errorf("want <%v> to have prefix <%v>", s.actual, prefix)
}
}
func (s *Str[S]) HasSuffix(suffix S) {
s.Helper()
if !strings.HasSuffix(string(s.actual), string(suffix)) {
s.Errorf("want <%v> to have prefix <%v>", s.actual, suffix)
}
}
func (s *Str[S]) IsEmpty() {
s.Helper()
if s.actual != "" {
s.Errorf("want <%v> to be empty, was not", s.actual)
}
}
func (s *Str[S]) IsNotEmpty() {
s.Helper()
if s.actual == "" {
s.Errorf("want <%v> to be empty, was not", s.actual)
}
}