-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathunicode_test.go
60 lines (56 loc) · 1.66 KB
/
unicode_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
package devstatscode
import (
"testing"
lib "github.com/cncf/devstatscode"
)
func TestStripUnicode(t *testing.T) {
// Test cases
var testCases = []struct {
str, expected string
}{
{str: "hello", expected: "hello"},
{str: "control:\t\n\r", expected: "control:"},
{str: "gżegżółką", expected: "gzegzoka"},
{str: "net_ease_网易有态", expected: "net_ease_"},
}
// Execute test cases
for index, test := range testCases {
expected := test.expected
got := lib.StripUnicode(test.str)
if got != expected {
t.Errorf(
"test number %d, expected %v, got %v",
index+1, expected, got,
)
}
}
}
// NormalizeName - clean DB string from ', ", -, /, ., " ", trim leading and trailing space, lowercase
// Normalize Unicode characters
func TestNormalizeName(t *testing.T) {
// Test cases
var testCases = []struct {
str, expected string
}{
{str: "hello", expected: "hello"},
{str: "control:\t\n\r", expected: "control"},
{str: "gżegżółką", expected: "gzegzoka"},
{str: "net_ease_网易有态", expected: "netease"},
{str: " see;hello-world/k8s.io, said: HE`MAN ", expected: "seehelloworldk8siosaidheman"},
{str: "Contributions (issues, PRs, git pushes)", expected: "contributionsissuesprsgitpushes"},
{str: "Exclude (ro[bot]nik)", expected: "excluderobotnik"},
{str: "comment\"sallcoted'ivoire", expected: "commentsallcotedivoire"},
{str: "Piraeus-Datastore", expected: "piraeusdatastore"},
}
// Execute test cases
for index, test := range testCases {
expected := test.expected
got := lib.NormalizeName(test.str)
if got != expected {
t.Errorf(
"test number %d, expected %v, got %v",
index+1, expected, got,
)
}
}
}