-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanonymizer_test.go
78 lines (67 loc) · 2.54 KB
/
anonymizer_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
package anonymizer
import (
"testing"
"github.com/matryer/is"
)
func TestAnonymize_Default(t *testing.T) {
t.Parallel()
is := is.New(t)
a := New(nil)
is.Equal(a.Anonymize("Albert"), "█▄▄▄▄▄")
is.Equal(a.Anonymize("Albert hello"), "█▄▄▄▄▄ hello")
is.Equal(a.Anonymize("Hello Albert"), "Hello █▄▄▄▄▄")
is.Equal(a.Anonymize("Hello, Albert. How are you?"), "Hello, █▄▄▄▄▄. How are you?")
is.Equal(a.Anonymize("MyLoKo"), "█▄█▄█▄")
is.Equal(a.Anonymize("12 34"), "00 00")
is.Equal(a.Anonymize("12-34"), "00-00")
is.Equal(a.Anonymize("Lelystad"), "█▄▄▄▄▄▄▄")
is.Equal(a.Anonymize("Flёur"), "█▄▄▄▄")
}
func TestAnonymize_Dutch(t *testing.T) {
t.Parallel()
is := is.New(t)
d, err := LoadDict("nl")
is.NoErr(err)
a := New(d)
is.Equal(a.Anonymize("Albert"), "█▄▄▄▄▄")
is.Equal(a.Anonymize("hoi Albert!"), "hoi █▄▄▄▄▄!")
is.Equal(a.Anonymize("Hoi Albert!"), "Hoi █▄▄▄▄▄!")
is.Equal(a.Anonymize("Hoi Hoi!"), "Hoi █▄▄!")
is.Equal(a.Anonymize("hoe gaat het, asdasd?"), "hoe gaat het, ▄▄▄▄▄▄?")
is.Equal(a.Anonymize("MyLoKo"), "█▄█▄█▄")
is.Equal(a.Anonymize("12 34"), "00 00")
is.Equal(a.Anonymize("12-34"), "00-00")
is.Equal(a.Anonymize("Lelystad"), "█▄▄▄▄▄▄▄")
is.Equal(a.Anonymize("Flёur"), "█▄▄▄▄")
}
func TestIterWords(t *testing.T) {
t.Parallel()
is := is.New(t)
listWords := func(text string) []string {
words := make([]string, 0)
runes := []rune(text)
for span := range iterWords(runes) {
word := runes[span.start:span.end]
words = append(words, string(word))
}
return words
}
is.Equal(listWords("hello world"), []string{"hello", "world"})
is.Equal(listWords("HeLlO wOrLd"), []string{"HeLlO", "wOrLd"})
is.Equal(listWords("привет, мир!"), []string{"привет", "мир"})
is.Equal(listWords("Привет, мир!"), []string{"Привет", "мир"})
}
// func TestSentenceStart(t *testing.T) {
// t.Parallel()
// is := is.New(t)
// is.True(isSentenceStart([]rune("hello"), 0))
// is.True(isSentenceStart([]rune(". Hello"), 2))
// is.True(isSentenceStart([]rune("? Hello"), 2))
// is.True(isSentenceStart([]rune("⁉ Hello"), 2))
// is.True(isSentenceStart([]rune("h.Hello"), 2))
// is.True(isSentenceStart([]rune("..Hello"), 2))
// is.True(isSentenceStart([]rune(". Hello"), 3))
// is.True(!isSentenceStart([]rune(", Hello"), 2))
// is.True(!isSentenceStart([]rune("' Hello"), 2))
// is.True(!isSentenceStart([]rune(".,Hello"), 2))
// }