Debian Codegraph @

tests/test-encoding.t

raw
1 Test character encoding
2
3 $ hg init t
4 $ cd t
5
6 we need a repo with some legacy latin-1 changesets
7
8 $ hg unbundle "$TESTDIR/bundles/legacy-encoding.hg"
9 adding changesets
10 adding manifests
11 adding file changes
12 added 2 changesets with 2 changes to 1 files
13 new changesets 1e78a93102a3:0e5b7e3f9c4a (2 drafts)
14 (run 'hg update' to get a working copy)
15 $ hg co
16 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
17 $ "$PYTHON" << EOF
18 > f = open('latin-1', 'wb'); f.write(b"latin-1 e' encoded: \xe9"); f.close()
19 > f = open('utf-8', 'wb'); f.write(b"utf-8 e' encoded: \xc3\xa9"); f.close()
20 > f = open('latin-1-tag', 'wb'); f.write(b"\xe9"); f.close()
21 > EOF
22
23 should fail with encoding error
24
25 $ echo "plain old ascii" > a
26 $ hg st
27 M a
28 ? latin-1
29 ? latin-1-tag
30 ? utf-8
31 $ HGENCODING=ascii hg ci -l latin-1
32 transaction abort!
33 rollback completed
34 abort: decoding near ' encoded: \xe9': 'ascii' codec can't decode byte 0xe9 in position 20: ordinal not in range(128)! (esc)
35 [255]
36
37 these should work
38
39 $ echo "latin-1" > a
40 $ HGENCODING=latin-1 hg ci -l latin-1
41 $ echo "utf-8" > a
42 $ HGENCODING=utf-8 hg ci -l utf-8
43 $ HGENCODING=latin-1 hg tag `cat latin-1-tag`
44 $ HGENCODING=latin-1 hg branch `cat latin-1-tag`
45 marked working directory as branch \xe9 (esc)
46 (branches are permanent and global, did you want a bookmark?)
47 $ HGENCODING=latin-1 hg ci -m 'latin1 branch'
48 $ hg -q rollback
49 $ HGENCODING=latin-1 hg branch
50 \xe9 (esc)
51 $ HGENCODING=latin-1 hg ci -m 'latin1 branch'
52 $ rm .hg/branch
53
54 hg log (ascii)
55
56 $ hg --encoding ascii log
57 changeset: 5:a52c0692f24a
58 branch: ?
59 tag: tip
60 user: test
61 date: Thu Jan 01 00:00:00 1970 +0000
62 summary: latin1 branch
63
64 changeset: 4:94db611b4196
65 user: test
66 date: Thu Jan 01 00:00:00 1970 +0000
67 summary: Added tag ? for changeset ca661e7520de
68
69 changeset: 3:ca661e7520de
70 tag: ?
71 user: test
72 date: Thu Jan 01 00:00:00 1970 +0000
73 summary: utf-8 e' encoded: ?
74
75 changeset: 2:650c6f3d55dd
76 user: test
77 date: Thu Jan 01 00:00:00 1970 +0000
78 summary: latin-1 e' encoded: ?
79
80 changeset: 1:0e5b7e3f9c4a
81 user: test
82 date: Mon Jan 12 13:46:40 1970 +0000
83 summary: koi8-r: ????? = u'\u0440\u0442\u0443\u0442\u044c'
84
85 changeset: 0:1e78a93102a3
86 user: test
87 date: Mon Jan 12 13:46:40 1970 +0000
88 summary: latin-1 e': ? = u'\xe9'
89
90
91 hg log (latin-1)
92
93 $ hg --encoding latin-1 log
94 changeset: 5:a52c0692f24a
95 branch: \xe9 (esc)
96 tag: tip
97 user: test
98 date: Thu Jan 01 00:00:00 1970 +0000
99 summary: latin1 branch
100
101 changeset: 4:94db611b4196
102 user: test
103 date: Thu Jan 01 00:00:00 1970 +0000
104 summary: Added tag \xe9 for changeset ca661e7520de (esc)
105
106 changeset: 3:ca661e7520de
107 tag: \xe9 (esc)
108 user: test
109 date: Thu Jan 01 00:00:00 1970 +0000
110 summary: utf-8 e' encoded: \xe9 (esc)
111
112 changeset: 2:650c6f3d55dd
113 user: test
114 date: Thu Jan 01 00:00:00 1970 +0000
115 summary: latin-1 e' encoded: \xe9 (esc)
116
117 changeset: 1:0e5b7e3f9c4a
118 user: test
119 date: Mon Jan 12 13:46:40 1970 +0000
120 summary: koi8-r: \xd2\xd4\xd5\xd4\xd8 = u'\\u0440\\u0442\\u0443\\u0442\\u044c' (esc)
121
122 changeset: 0:1e78a93102a3
123 user: test
124 date: Mon Jan 12 13:46:40 1970 +0000
125 summary: latin-1 e': \xe9 = u'\\xe9' (esc)
126
127
128 hg log (utf-8)
129
130 $ hg --encoding utf-8 log
131 changeset: 5:a52c0692f24a
132 branch: \xc3\xa9 (esc)
133 tag: tip
134 user: test
135 date: Thu Jan 01 00:00:00 1970 +0000
136 summary: latin1 branch
137
138 changeset: 4:94db611b4196
139 user: test
140 date: Thu Jan 01 00:00:00 1970 +0000
141 summary: Added tag \xc3\xa9 for changeset ca661e7520de (esc)
142
143 changeset: 3:ca661e7520de
144 tag: \xc3\xa9 (esc)
145 user: test
146 date: Thu Jan 01 00:00:00 1970 +0000
147 summary: utf-8 e' encoded: \xc3\xa9 (esc)
148
149 changeset: 2:650c6f3d55dd
150 user: test
151 date: Thu Jan 01 00:00:00 1970 +0000
152 summary: latin-1 e' encoded: \xc3\xa9 (esc)
153
154 changeset: 1:0e5b7e3f9c4a
155 user: test
156 date: Mon Jan 12 13:46:40 1970 +0000
157 summary: koi8-r: \xc3\x92\xc3\x94\xc3\x95\xc3\x94\xc3\x98 = u'\\u0440\\u0442\\u0443\\u0442\\u044c' (esc)
158
159 changeset: 0:1e78a93102a3
160 user: test
161 date: Mon Jan 12 13:46:40 1970 +0000
162 summary: latin-1 e': \xc3\xa9 = u'\\xe9' (esc)
163
164
165 hg tags (ascii)
166
167 $ HGENCODING=ascii hg tags
168 tip 5:a52c0692f24a
169 ? 3:ca661e7520de
170
171 hg tags (latin-1)
172
173 $ HGENCODING=latin-1 hg tags
174 tip 5:a52c0692f24a
175 \xe9 3:ca661e7520de (esc)
176
177 hg tags (utf-8)
178
179 $ HGENCODING=utf-8 hg tags
180 tip 5:a52c0692f24a
181 \xc3\xa9 3:ca661e7520de (esc)
182
183 hg tags (JSON)
184
185 $ hg tags -Tjson
186 [
187 {
188 "node": "a52c0692f24ad921c0a31e1736e7635a8b23b670",
189 "rev": 5,
190 "tag": "tip",
191 "type": ""
192 },
193 {
194 "node": "ca661e7520dec3f5438a63590c350bebadb04989",
195 "rev": 3,
196 "tag": "\xc3\xa9", (esc)
197 "type": ""
198 }
199 ]
200
201 hg branches (ascii)
202
203 $ HGENCODING=ascii hg branches
204 ? 5:a52c0692f24a
205 default 4:94db611b4196 (inactive)
206
207 hg branches (latin-1)
208
209 $ HGENCODING=latin-1 hg branches
210 \xe9 5:a52c0692f24a (esc)
211 default 4:94db611b4196 (inactive)
212
213 hg branches (utf-8)
214
215 $ HGENCODING=utf-8 hg branches
216 \xc3\xa9 5:a52c0692f24a (esc)
217 default 4:94db611b4196 (inactive)
218 $ echo '[ui]' >> .hg/hgrc
219 $ echo 'fallbackencoding = koi8-r' >> .hg/hgrc
220
221 hg log (utf-8)
222
223 $ HGENCODING=utf-8 hg log
224 changeset: 5:a52c0692f24a
225 branch: \xc3\xa9 (esc)
226 tag: tip
227 user: test
228 date: Thu Jan 01 00:00:00 1970 +0000
229 summary: latin1 branch
230
231 changeset: 4:94db611b4196
232 user: test
233 date: Thu Jan 01 00:00:00 1970 +0000
234 summary: Added tag \xc3\xa9 for changeset ca661e7520de (esc)
235
236 changeset: 3:ca661e7520de
237 tag: \xc3\xa9 (esc)
238 user: test
239 date: Thu Jan 01 00:00:00 1970 +0000
240 summary: utf-8 e' encoded: \xc3\xa9 (esc)
241
242 changeset: 2:650c6f3d55dd
243 user: test
244 date: Thu Jan 01 00:00:00 1970 +0000
245 summary: latin-1 e' encoded: \xc3\xa9 (esc)
246
247 changeset: 1:0e5b7e3f9c4a
248 user: test
249 date: Mon Jan 12 13:46:40 1970 +0000
250 summary: koi8-r: \xd1\x80\xd1\x82\xd1\x83\xd1\x82\xd1\x8c = u'\\u0440\\u0442\\u0443\\u0442\\u044c' (esc)
251
252 changeset: 0:1e78a93102a3
253 user: test
254 date: Mon Jan 12 13:46:40 1970 +0000
255 summary: latin-1 e': \xd0\x98 = u'\\xe9' (esc)
256
257
258 hg log (dolphin)
259
260 $ HGENCODING=dolphin hg log
261 abort: unknown encoding: dolphin
262 (please check your locale settings)
263 [255]
264 $ HGENCODING=ascii hg branch `cat latin-1-tag`
265 abort: decoding near '\xe9': 'ascii' codec can't decode byte 0xe9 in position 0: ordinal not in range(128)! (esc)
266 [255]
267 $ cp latin-1-tag .hg/branch
268 $ HGENCODING=latin-1 hg ci -m 'auto-promote legacy name'
269
270 Test roundtrip encoding of lookup tables when not using UTF-8 (issue2763)
271
272 $ HGENCODING=latin-1 hg up `cat latin-1-tag`
273 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
274
275 $ cd ..
276
277 Test roundtrip encoding/decoding of utf8b for generated data
278
279 #if hypothesis
280
281 >>> import hypothesishelpers
282 >>> from mercurial import encoding
283 >>> hypothesishelpers.roundtrips(hypothesishelpers.st.binary(),
284 ... encoding.fromutf8b, encoding.toutf8b)
285 Round trip OK
286
287 #endif