-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrings_test.go
95 lines (81 loc) · 1.82 KB
/
strings_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package utils_test
import (
"testing"
"github.com/gomig/utils"
)
func TestExtractNumbers(t *testing.T) {
res := utils.ExtractNumbers("This is text with 123 and 456")
if res != "123456" {
t.Log(res)
t.Fatal("failed!")
}
}
func TestExtractAlphaNum(t *testing.T) {
res := utils.ExtractAlphaNum("This is-text with 123 and _456", "-", "_")
if res != "Thisis-textwith123and_456" {
t.Log(res)
t.Fatal("failed!")
}
}
func TestExtractAlphaNumPersian(t *testing.T) {
res := utils.ExtractAlphaNumPersian("This is-textwith گچپژ and _456", "-", " ")
if res != "This is-textwith گچپژ and 456" {
t.Log(res)
t.Fatal("failed!")
}
}
func TestRandomStringFromCharset(t *testing.T) {
res, err := utils.RandomStringFromCharset(5, "1234567")
if err != nil {
t.Fatal(err)
}
if len(res) != 5 {
t.Log(res)
t.Fatal("failed!")
}
}
func TestRandomString(t *testing.T) {
res, err := utils.RandomString(5)
if err != nil {
t.Fatal(err)
}
if len(res) != 5 {
t.Log(res)
t.Fatal("failed!")
}
}
func TestSlugify(t *testing.T) {
res := utils.Slugify("Hel", " llo", "world")
if res != "Hel-llo-world" {
t.Log(res)
t.Fatal("failed!")
}
}
func TestSlugifyPersian(t *testing.T) {
res := utils.SlugifyPersian("خوش آمدید \n \r \t - to گچپژ")
if res != "خوش-آمدید-to-گچپژ" {
t.Log(res)
t.Fatal("failed!")
}
}
func TestConcatStr(t *testing.T) {
res := utils.ConcatStr(" ", "John", "", "Doe")
if res != "John Doe" {
t.Log(res)
t.Fatal("failed!")
}
}
func TestFormatNumber(t *testing.T) {
res := utils.FormatNumber("Total: %d$", 1230004)
if res != "Total: 1,230,004$" {
t.Log(res)
t.Fatal("failed!")
}
}
func TestFormatRx(t *testing.T) {
res := utils.FormatRx("02332337781", `^(\d{3})(\d{4})(\d{4})$`, "($1) $2-$3")
if res != "(023) 3233-7781" {
t.Log(res)
t.Fatal("failed!")
}
}