sapling/tests/test-encoding.t
Jun Wu 210bf49f5e clidispatch: replace Dispatcher with CommandTable
Summary:
The `Dispatcher` provides lots of features but its internal state only contains
the command table. Replace it with `CommandTable` and make the methods free
functions.

This makes function dependencies more cleaner, for example things like "locating
a repo", "getting the args" etc. won't require a `Dispatcher`.

A side effect of this change is the non-utf8 command line arguments are no longer
supported. This is already broken since our hg wrapper (accidentally) enforced
utf-8 command line. Therefore related tests are removed.

Reviewed By: sfilipco

Differential Revision: D16796395

fbshipit-source-id: a793ce7b8befe7caf62405c582fc932eb3daa099
2019-08-21 12:16:35 -07:00

191 lines
4.7 KiB
Perl

Test character encoding
$ hg init t
$ cd t
we need a repo with some legacy latin-1 changesets
$ hg unbundle "$TESTDIR/bundles/legacy-encoding.hg"
adding changesets
adding manifests
adding file changes
added 2 changesets with 2 changes to 1 files
new changesets 1e78a93102a3:0e5b7e3f9c4a
$ hg co
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ $PYTHON << EOF
> f = file('latin-1', 'w'); f.write("latin-1 e' encoded: \xe9"); f.close()
> f = file('utf-8', 'w'); f.write("utf-8 e' encoded: \xc3\xa9"); f.close()
> f = file('latin-1-tag', 'w'); f.write("\xe9"); f.close()
> EOF
should fail with encoding error
$ echo "plain old ascii" > a
$ hg st
M a
? latin-1
? latin-1-tag
? utf-8
$ HGENCODING=ascii hg ci -l latin-1
transaction abort!
rollback completed
abort: decoding near ' encoded: \xe9': 'ascii' codec can't decode byte 0xe9 in position 20: ordinal not in range(128)! (esc)
[255]
these should work
$ echo "latin-1" > a
$ HGENCODING=latin-1 hg ci -l latin-1
$ echo "utf-8" > a
$ HGENCODING=utf-8 hg ci -l utf-8
hg log (ascii)
$ hg --encoding ascii log
changeset: 3:ca661e7520de
tag: tip
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: utf-8 e' encoded: ?
changeset: 2:650c6f3d55dd
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: latin-1 e' encoded: ?
changeset: 1:0e5b7e3f9c4a
user: test
date: Mon Jan 12 13:46:40 1970 +0000
summary: koi8-r: ????? = u'\u0440\u0442\u0443\u0442\u044c'
changeset: 0:1e78a93102a3
user: test
date: Mon Jan 12 13:46:40 1970 +0000
summary: latin-1 e': ? = u'\xe9'
hg log (latin-1)
$ hg --encoding latin-1 log
changeset: 3:ca661e7520de
tag: tip
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: utf-8 e' encoded: \xe9 (esc)
changeset: 2:650c6f3d55dd
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: latin-1 e' encoded: \xe9 (esc)
changeset: 1:0e5b7e3f9c4a
user: test
date: Mon Jan 12 13:46:40 1970 +0000
summary: koi8-r: \xd2\xd4\xd5\xd4\xd8 = u'\\u0440\\u0442\\u0443\\u0442\\u044c' (esc)
changeset: 0:1e78a93102a3
user: test
date: Mon Jan 12 13:46:40 1970 +0000
summary: latin-1 e': \xe9 = u'\\xe9' (esc)
hg log (utf-8)
$ hg --encoding utf-8 log
changeset: 3:ca661e7520de
tag: tip
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: utf-8 e' encoded: \xc3\xa9 (esc)
changeset: 2:650c6f3d55dd
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: latin-1 e' encoded: \xc3\xa9 (esc)
changeset: 1:0e5b7e3f9c4a
user: test
date: Mon Jan 12 13:46:40 1970 +0000
summary: koi8-r: \xc3\x92\xc3\x94\xc3\x95\xc3\x94\xc3\x98 = u'\\u0440\\u0442\\u0443\\u0442\\u044c' (esc)
changeset: 0:1e78a93102a3
user: test
date: Mon Jan 12 13:46:40 1970 +0000
summary: latin-1 e': \xc3\xa9 = u'\\xe9' (esc)
hg tags (ascii)
$ HGENCODING=ascii hg tags
tip 3:ca661e7520de
hg tags (latin-1)
$ HGENCODING=latin-1 hg tags
tip 3:ca661e7520de
hg tags (utf-8)
$ HGENCODING=utf-8 hg tags
tip 3:ca661e7520de
hg tags (JSON)
$ hg tags -Tjson
[
{
"node": "ca661e7520dec3f5438a63590c350bebadb04989",
"rev": 3,
"tag": "tip",
"type": ""
}
]
hg log (utf-8)
$ HGENCODING=utf-8 hg log
changeset: 3:ca661e7520de
tag: tip
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: utf-8 e' encoded: \xc3\xa9 (esc)
changeset: 2:650c6f3d55dd
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: latin-1 e' encoded: \xc3\xa9 (esc)
changeset: 1:0e5b7e3f9c4a
user: test
date: Mon Jan 12 13:46:40 1970 +0000
summary: koi8-r: \xc3\x92\xc3\x94\xc3\x95\xc3\x94\xc3\x98 = u'\\u0440\\u0442\\u0443\\u0442\\u044c' (esc)
changeset: 0:1e78a93102a3
user: test
date: Mon Jan 12 13:46:40 1970 +0000
summary: latin-1 e': \xc3\xa9 = u'\\xe9' (esc)
hg log (dolphin)
$ HGENCODING=dolphin hg log
abort: unknown encoding: dolphin
(please check your locale settings)
[255]
$ cp latin-1-tag .hg/branch
$ HGENCODING=latin-1 hg ci -m 'auto-promote legacy name'
$ cd ..
Test roundtrip encoding/decoding of utf8b for generated data
#if hypothesis
>>> from hypothesishelpers import *
>>> from edenscm.mercurial import encoding
>>> roundtrips(st.binary(), encoding.fromutf8b, encoding.toutf8b)
Round trip OK
#endif