-
Notifications
You must be signed in to change notification settings - Fork 1
/
name_test.go
80 lines (74 loc) · 1.21 KB
/
name_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
package anonymize_test
import (
"strings"
"testing"
"github.com/emmanuelay/anonymize"
)
func TestAnonymizeName(t *testing.T) {
tests := []struct {
got string
want string
anonRune rune
}{
{
got: "Emmanuel Ay",
want: "E******* A*",
},
{
got: "Emmanuel Ay",
want: "E••••••• A•",
anonRune: '•',
},
{
got: "Em Ay",
want: "E* A*",
},
{
got: "E A",
want: "E A",
},
{
got: "E",
want: "E",
},
{
got: " ",
want: " ",
},
{
got: "",
want: "",
},
{
got: "Emmanuel von Ay",
want: "E******* v** A*",
},
{
got: "Emmanuel McDonalds",
want: "E******* M*D******",
},
{
got: "EMMANUEL MCDONALDS",
want: "E******* M********",
},
{
got: "Luke Skywalker",
want: "L*** S********",
},
{
got: "Luke SkyWalker",
want: "L*** S**W*****",
},
}
for _, test := range tests {
var result string
if test.anonRune > 0 {
result = anonymize.NameWithCustomRune(test.got, test.anonRune)
} else {
result = anonymize.Name(test.got)
}
if !strings.EqualFold(test.want, result) {
t.Errorf("Incorrect result for '%v': got '%v', want '%v'", test.got, result, test.want)
}
}
}