-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathunicode_test.go
165 lines (158 loc) · 3.99 KB
/
unicode_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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package readline
import (
"testing"
)
func TestSetRunePos(t *testing.T) {
tests := []struct {
Value string
Start int
RunePos int
ExpectedRPos int
ExpectedCPos int
}{
{
Value: "hello world!",
Start: 5,
RunePos: 7,
ExpectedRPos: 7,
ExpectedCPos: 7,
},
{
Value: "举手之劳就可以使办公室更加环保,比如,使用再生纸。",
Start: 2,
RunePos: 13,
ExpectedRPos: 13,
ExpectedCPos: 25,
},
{
Value: "举手之劳就可以使办公室更加环保,比如,使用再生纸。",
Start: 2,
RunePos: 14,
ExpectedRPos: 14,
ExpectedCPos: 27,
},
{
Value: "foo举手之劳就可以使办公室更加环保,比如,使用再生纸。",
Start: 2,
RunePos: 6,
ExpectedRPos: 6,
ExpectedCPos: 8,
},
{
Value: "foo举手之劳就可以使办公室更加环保,比如,使用再生纸。",
Start: 2,
RunePos: 7,
ExpectedRPos: 7,
ExpectedCPos: 10,
},
{
Value: "举手之劳就可以使办公室更加环保,比如,使用再生纸。",
Start: 2,
RunePos: 3,
ExpectedRPos: 3,
ExpectedCPos: 5,
},
{
Value: "举手之劳就可以使办公室更加环保,比如,使用再生纸。",
Start: 2,
RunePos: 4,
ExpectedRPos: 4,
ExpectedCPos: 7,
},
}
for i, test := range tests {
u := new(UnicodeT)
u.Set(new(Instance), []rune(test.Value))
u.SetRunePos(test.Start)
u.SetRunePos(test.RunePos)
rPos := u.RunePos()
cPos := u.CellPos()
if rPos != test.ExpectedRPos || cPos != test.ExpectedCPos {
t.Errorf("Unexpected position in test %d", i)
t.Logf(" Value: '%s'", test.Value)
t.Logf(" Start: %d", test.Start)
t.Logf(" SetRunePos: %d", test.RunePos)
t.Logf(" exp rPos: %d", test.ExpectedRPos)
t.Logf(" act rPos: %d", rPos)
t.Logf(" exp cPos: %d", test.ExpectedCPos)
t.Logf(" act cPos: %d", cPos)
}
}
}
func TestSetCellPos(t *testing.T) {
tests := []struct {
Value string
Start int
CellPos int
ExpectedRPos int
ExpectedCPos int
}{
{
Value: "hello world!",
Start: 5,
CellPos: 7,
ExpectedRPos: 7,
ExpectedCPos: 7,
},
{
Value: "举手之劳就可以使办公室更加环保,比如,使用再生纸。",
Start: 2,
CellPos: 25,
ExpectedRPos: 13,
ExpectedCPos: 25,
},
{
Value: "举手之劳就可以使办公室更加环保,比如,使用再生纸。",
Start: 2,
CellPos: 26,
ExpectedRPos: 13,
ExpectedCPos: 25,
},
{
Value: "foo举手之劳就可以使办公室更加环保,比如,使用再生纸。",
Start: 2,
CellPos: 8,
ExpectedRPos: 6,
ExpectedCPos: 8,
},
{
Value: "foo举手之劳就可以使办公室更加环保,比如,使用再生纸。",
Start: 2,
CellPos: 9,
ExpectedRPos: 6,
ExpectedCPos: 8,
},
{
Value: "举手之劳就可以使办公室更加环保,比如,使用再生纸。",
Start: 2,
CellPos: 5,
ExpectedRPos: 3,
ExpectedCPos: 5,
},
{
Value: "举手之劳就可以使办公室更加环保,比如,使用再生纸。",
Start: 2,
CellPos: 6,
ExpectedRPos: 3,
ExpectedCPos: 5,
},
}
for i, test := range tests {
u := new(UnicodeT)
u.Set(new(Instance), []rune(test.Value))
u.SetRunePos(test.Start)
u.SetCellPos(test.CellPos)
rPos := u.RunePos()
cPos := u.CellPos()
if rPos != test.ExpectedRPos || cPos != test.ExpectedCPos {
t.Errorf("Unexpected position in test %d", i)
t.Logf(" Value: '%s'", test.Value)
t.Logf(" Start: %d", test.Start)
t.Logf(" SetCellPos: %d", test.CellPos)
t.Logf(" exp rPos: %d", test.ExpectedRPos)
t.Logf(" act rPos: %d", rPos)
t.Logf(" exp cPos: %d", test.ExpectedCPos)
t.Logf(" act cPos: %d", cPos)
}
}
}