-
Notifications
You must be signed in to change notification settings - Fork 1
/
categories_test.go
96 lines (83 loc) · 1.75 KB
/
categories_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
96
package confusablehomoglyphs
import (
"reflect"
"sort"
"testing"
)
func TestAliasesCategories(t *testing.T) {
cases := []struct {
char rune
alias string
category string
}{
{'A', "LATIN", "L"},
{'τ', "GREEK", "L"},
{'-', "COMMON", "Pd"},
}
for _, c := range cases {
alias, cat := AliasesCategories(c.char)
if alias != c.alias {
t.Errorf("unexpected alias, expected: %v, actual: %v\n", c.alias, alias)
}
if cat != c.category {
t.Errorf("unexpected category, expected: %v, actual: %v\n", c.category, cat)
}
}
}
func TestAlias(t *testing.T) {
cases := []struct {
char rune
alias string
}{
{'A', "LATIN"},
{'τ', "GREEK"},
{'-', "COMMON"},
}
for _, c := range cases {
alias := Alias(c.char)
if alias != c.alias {
t.Errorf("unexpected alias, expected: %v, actual: %v\n", c.alias, alias)
}
}
}
func TestCategory(t *testing.T) {
cases := []struct {
char rune
category string
}{
{'A', "L"},
{'τ', "L"},
{'-', "Pd"},
}
for _, c := range cases {
category := Category(c.char)
if category != c.category {
t.Errorf("unexpected category, expected: %v, actual: %v\n", c.category, category)
}
}
}
func TestUniqueAliases(t *testing.T) {
cases := []struct {
str string
aliases []string
}{
{"ABC", []string{"LATIN"}},
{"ρAτ-", []string{"GREEK", "LATIN", "COMMON"}},
}
for _, c := range cases {
aliases := UniqueAliases(c.str)
if !sameArray(aliases, c.aliases) {
t.Errorf("unexpected unique aliases, expected: %v, actual: %v\n", c.aliases, aliases)
}
}
}
func sameArray(arr1 []string, arr2 []string) bool {
if len(arr1) != len(arr2) {
return false
}
ss1 := sort.StringSlice(arr1)
ss1.Sort()
ss2 := sort.StringSlice(arr2)
ss2.Sort()
return reflect.DeepEqual(ss1, ss2)
}