-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathapi_test.go
More file actions
65 lines (56 loc) · 1.35 KB
/
api_test.go
File metadata and controls
65 lines (56 loc) · 1.35 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
59
60
61
62
63
64
65
package main
import (
"testing"
"fmt"
)
type Test struct {
Key string
Valid bool
}
func TestPGP(t *testing.T) {
fmt.Println("Testing PGP regex")
test := []Test{
{"CAFEBABE", true},
{"caFeD00d", true},
{"12345678", true},
{"ORANGEEE", false},
{"12O21333", false},
{"CAFEBABECAFEBABE", true},
{"C2AccAb3CDDDad2F", true},
{"1234567890ABCDEF", true},
{"3ABC12AAAAC2134D", true},
{"ABC12CCAADD333X9", false},
}
for i, p := range test {
fmt.Print(i)
fmt.Print(" - " + p.Key + " is valid? ")
fmt.Print(PGPRegexp.Match([]byte(p.Key)))
fmt.Print(" (should be ")
fmt.Print(p.Valid)
fmt.Println(")")
if PGPRegexp.Match([]byte(p.Key)) != p.Valid {
t.Errorf("%s returned %v when it should have returned %v!", p.Key, !p.Valid, p.Valid)
}
}
}
func TestEmail(t *testing.T) {
fmt.Println("Testing Email regex")
test := []Test{
{"nodeatlaszz323@example.com", true},
{"123@exle.ch", true},
{"abc+xyz@some.site.co.uk", true},
{"thisisanemail.com", false},
{"yooo@", false},
}
for i, e := range test {
fmt.Print(i)
fmt.Print(" - " + e.Key + " is valid? ")
fmt.Print(EmailRegexp.Match([]byte(e.Key)))
fmt.Print(" (should be ")
fmt.Print(e.Valid)
fmt.Println(")")
if EmailRegexp.Match([]byte(e.Key)) != e.Valid {
t.Errorf("%s returned %v when it should have returned %v!", e.Key, !e.Valid, e.Valid)
}
}
}