-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathregex_test.go
50 lines (45 loc) · 837 Bytes
/
regex_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
package main
import (
"math/rand"
"net/url"
"regexp"
"testing"
"time"
)
func TestRegex(t *testing.T) {
var list = []string{
"123",
"1",
"a",
"1223123",
"12344411sadfhwe213443",
"12a你",
"asd124,",
}
for _, v := range list {
b, e := regexp.MatchString(`^[a-zA-Z0-9_-]+$`, v)
if e != nil {
t.Errorf("check %s error: %s\n", v, e)
continue
}
if !b {
t.Logf("%s is false\n", v)
}
}
}
func TestUrl(t *testing.T) {
u := "http://127.0.0.1:9099/"
uu, _ := url.Parse(u)
t.Log(uu.Path)
}
// 0-9 -> 48-57 | A-Z 65-90 | a-z | 97-122
func TestASCII(t *testing.T) {
words := []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")
str := ""
for i := 0; i < 6; i++ {
rand.Seed(time.Now().UnixNano())
index := rand.Intn(len(words))
str += string(words[index])
}
t.Log(str)
}