-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindows1251_test.go
More file actions
78 lines (71 loc) · 2.72 KB
/
windows1251_test.go
File metadata and controls
78 lines (71 loc) · 2.72 KB
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 futf
import (
"testing"
"github.com/stretchr/testify/assert"
"golang.org/x/text/encoding/charmap"
)
// TODO: they shoould pass. Its required to make Windows1251 guesser more strict
func TestWindows1251_Guese(t *testing.T) {
// t.Log(string(toEnc("Ñàíêò-Ïåòåðáóðã", charmap.ISO8859_1)))
// t.Log(string(dec(toEnc("Ñàíêò-Ïåòåðáóðã", charmap.ISO8859_1), charmap.Windows1251)))
// t.Log(string(Dec(Enc("Ñàíêò-Ïåòåðáóðã", charmap.Windows1252), charmap.Windows1251)))
// t.Log(string(dec([]byte("Ñàíêò-Ïåòåðáóðã"), charmap.ISO8859_1)))
// t.Log(string(dec([]byte("Ñàíêò-Ïåòåðáóðã"), charmap.ISO8859_1)))
// t.Log(string(dec([]byte("Ñàíêò-Ïåòåðáóðã"), charmap.Windows1251)))
// t.Log(string(dec(dec([]byte("Ñàíêò-Ïåòåðáóðã"), charmap.ISO8859_1), charmap.Windows1251)))
// t.Log(string(dec(dec([]byte("Ñàíêò-Ïåòåðáóðã"), charmap.ISO8859_1), charmap.Windows1252)))
tests := []struct {
name string
str []byte
wantProb int
}{
{
"long cyrillic sequence",
Enc("Привет!", charmap.Windows1251),
0,
},
{
"cyrillic chars separated",
Enc("П-р_и%в*е,т", charmap.Windows1251),
0,
},
{
"short cyrillic sequence",
Enc("При!!!!", charmap.Windows1251),
0,
},
{
"super short cyrillic sequence",
Enc("Пр!!!!", charmap.Windows1251),
0,
},
{
"Санкт-Петербург", //
[]byte("Санкт-Петербург"),
0,
},
{
"Санкт-Петербург", //
[]byte("Ñàíêò-Ïåòåðáóðã"),
100,
},
}
// t.Log(string(dec("Ñàíêò-Ïåòåðáóðã", charmap.Windows1251)))
// t.Log(string(dec("Ñàíêò-Ïåòåðáóðã", charmap.Windows1252)))
// t.Log(string(dec("Ñàíêò-Ïåòåðáóðã", charmap.ISO8859_1)))
// t.Log(string(Enc("Санкт-Петербург", charmap.Windows1251)))
// t.Log(string(toEnc("Санкт-Петербург", charmap.Windows1252)))
// t.Log(string(toEnc("Ñàíêò-Ïåòåðáóðã", charmap.Windows1251)))
// t.Log(string(toEnc("Ñàíêò-Ïåòåðáóðã", charmap.Windows1252)))
// t.Log(string(toEnc("Санкт-Петербург", charmap.Windows1251)))
// t.Log(string(toEnc("Санкт-Петербург", charmap.Windows1252)))
// t.Log(string(toEnc("Санкт-Петербург", charmap.Windows1252)))
// t.Log(string(toEnc("Санкт-Петербург", charmap.UtfBOM)))
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
g := &Windows1251{}
_, prob := g.Guese(tt.str)
assert.Equal(t, tt.wantProb, prob)
})
}
}