-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stringasserts.go
68 lines (63 loc) · 1.48 KB
/
stringasserts.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package testes
import (
"strings"
)
// AssertStringHasPrefix returns true if all
// string arguments have the given prefix.
// args[0] must contain the prefix being tested.
func AssertStringHasPrefix(args ...string) bool {
if !CheckPairs(args...) {
return false
}
for _, s := range args[1:] {
if !strings.HasPrefix(s, args[0]) {
return false
}
}
return true
}
// AssertStringHasSuffix returns true if all
// string arguments have the given suffix.
// args[0] must contain the suffix being tested.
func AssertStringHasSuffix(args ...string) bool {
if !CheckPairs(args...) {
return false
}
for _, s := range args[1:] {
if !strings.HasSuffix(s, args[0]) {
return false
}
}
return true
}
// AssertStringEqualFold returns true if all
// string pairs have equal folding.
//
// EqualFold reports whether two strings, interpreted as
// UTF-8 strings, are equal under Unicode case-folding,
// which is a more general form of case-insensitivity.
//
// Only pairs of args are considered; number of args
// must be a positive integer multiple of two.
func AssertStringEqualFold(args ...string) bool {
if !CheckPairs(args...) {
return false
}
pairs := Args2Pairs(args...)
for _, arg := range pairs {
if strings.EqualFold(arg[0], arg[1]) {
return false
}
}
return true
}
// AssertTheEmptyString returns true if all string
// arguments are The Empty String.
func AssertTheEmptyString(args ...string) bool {
for _, s := range args {
if s != "" {
return false
}
}
return true
}