-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers_test.go
65 lines (57 loc) · 1.46 KB
/
helpers_test.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
package semver
import "testing"
var set = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789"
var containsMatches = []string{
"abce345656",
"controller",
"matches",
"12345678",
}
var containsMismatches = []string{
"this is not right",
"digitalmagasinet.no",
"@twitter",
}
var zeroesMismatches = []string{
"12434",
"5000",
"56032",
"12345678",
"0",
}
var zeroesMatches = []string{
"0003",
"02",
"034",
}
func TestContainsOnly(t *testing.T) {
// Check matches
matchesExpected := true
for _, x := range containsMatches {
if response := containsOnly(x, alphanumeric); response != matchesExpected {
t.Errorf("containsOnly(%q, %q) => %t, want %t", x, set, response, matchesExpected)
}
}
// Check mismatches
mismatchesExpected := false
for _, x := range containsMismatches {
if response := containsOnly(x, alphanumeric); response != mismatchesExpected {
t.Errorf("containsOnly(%q, %q) => %t, want %t", x, set, response, mismatchesExpected)
}
}
}
func TestLeadingZeroes(t *testing.T) {
matchesExpected := true
for _, x := range zeroesMatches {
if response := hasLeadingZero(x); response != matchesExpected {
t.Errorf("hasLeadingZero(%q): => %t, want %t", x, response, matchesExpected)
}
}
// Check mismatches
mismatchesExpected := false
for _, x := range zeroesMismatches {
if response := hasLeadingZero(x); response != mismatchesExpected {
t.Errorf("hasLeadingZero(%q): => %t, want %t", x, response, mismatchesExpected)
}
}
}