forked from mtibben/confusables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfusables_test.go
106 lines (88 loc) · 2.19 KB
/
confusables_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
97
98
99
100
101
102
103
104
105
106
package confusables
import (
"fmt"
"testing"
)
func TestSkeleton(t *testing.T) {
s := "ρ⍺у𝓅𝒂ן"
expected := "paypal"
skeleton := Skeleton(s)
if skeleton != expected {
t.Error(fmt.Sprintf("Skeleton(%s) should result in %s", s, expected))
}
}
func TestCompareEqual(t *testing.T) {
vectors := [][]string{
[]string{"ρ⍺у𝓅𝒂ן", "𝔭𝒶ỿ𝕡𝕒ℓ"},
[]string{"𝖶", "W"},
[]string{"so̷s", "søs"},
[]string{"paypal", "paypal"},
[]string{"scope", "scope"},
[]string{"ø", "o̷"},
[]string{"O", "0"},
[]string{"ν", "v"},
[]string{"Ι", "l"},
[]string{"warning", "waming"},
}
for _, v := range vectors {
s1, s2 := v[0], v[1]
if !Confusable(s1, s2) {
t.Errorf("Skeleton strings %+q and %+q were expected to be equal", s1, s2)
}
}
}
func TestCompareDifferent(t *testing.T) {
s1 := "Paypal"
s2 := "paypal"
if Confusable(s1, s2) {
t.Errorf("Skeleton strings %+q and %+q were expected to be different", s1, s2)
}
}
func TestTweaksCompareEqual(t *testing.T) {
vectors := [][]string{
[]string{"ρ⍺у𝓅𝒂ן", "𝔭𝒶ỿ𝕡𝕒ℓ"},
[]string{"𝖶", "W"},
[]string{"so̷s", "søs"},
[]string{"paypal", "paypal"},
[]string{"scope", "scope"},
[]string{"ø", "o̷"},
[]string{"ν", "v"},
[]string{"Ι", "l"},
[]string{"Ӏ", "I"}, // palochka
[]string{"shivaram", "shivara𑜀"}, // 0x11700 "ahom letter ka"
}
for _, v := range vectors {
s1, s2 := v[0], v[1]
if SkeletonTweaked(s1) != SkeletonTweaked(s2) {
t.Errorf("Skeleton strings %+q and %+q were expected to be equal", s1, s2)
}
}
}
func TestTweaksCompareDifferent(t *testing.T) {
vectors := [][]string{
[]string{"shivaram", "shivararn"},
}
for _, v := range vectors {
if SkeletonTweaked(v[0]) == SkeletonTweaked(v[1]) {
t.Errorf("Skeleton strings %+q and %+q were expected to be different", v[0], v[1])
}
}
}
func BenchmarkSkeletonNoop(b *testing.B) {
s := "skeleton"
for i := 0; i < b.N; i++ {
Skeleton(s)
}
}
func BenchmarkSkeletonTweakedNoop(b *testing.B) {
s := "skeleton"
for i := 0; i < b.N; i++ {
SkeletonTweaked(s)
}
}
func BenchmarkSkeleton(b *testing.B) {
s := "ѕ𝗄℮|е𝗍ο𝔫"
for i := 0; i < b.N; i++ {
Skeleton(s)
}
}