aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/testdir/test_makeencoding.py
diff options
context:
space:
mode:
authorJames McCoy <jamessan@jamessan.com>2017-12-16 21:50:20 -0500
committerJames McCoy <jamessan@jamessan.com>2017-12-17 11:20:28 -0500
commitc162bc629440afaf8910f1a29f1dfdb03f898101 (patch)
tree2233cf781d1c08795755eb8d04bd9732d158ba5b /src/nvim/testdir/test_makeencoding.py
parentbe53c209c0e0ccff0053fac82f2d8e1c9a40427f (diff)
downloadrneovim-c162bc629440afaf8910f1a29f1dfdb03f898101.tar.gz
rneovim-c162bc629440afaf8910f1a29f1dfdb03f898101.tar.bz2
rneovim-c162bc629440afaf8910f1a29f1dfdb03f898101.zip
vim-patch:8.0.0420: text garbled when the system encoding differs from 'encoding'
Problem: When running :make the output may be in the system encoding, different from 'encoding'. Solution: Add the 'makeencoding' option. (Ken Takata) https://github.com/vim/vim/commit/2c7292dc5bbf155fe2192d417363b8c085759cad
Diffstat (limited to 'src/nvim/testdir/test_makeencoding.py')
-rw-r--r--src/nvim/testdir/test_makeencoding.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/nvim/testdir/test_makeencoding.py b/src/nvim/testdir/test_makeencoding.py
new file mode 100644
index 0000000000..041edadc0a
--- /dev/null
+++ b/src/nvim/testdir/test_makeencoding.py
@@ -0,0 +1,67 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+# Test program for :make, :grep and :cgetfile.
+
+from __future__ import print_function, unicode_literals
+import locale
+import io
+import sys
+
+def set_output_encoding(enc=None):
+ """Set the encoding of stdout and stderr
+
+ arguments:
+ enc -- Encoding name.
+ If omitted, locale.getpreferredencoding() is used.
+ """
+ if enc is None:
+ enc = locale.getpreferredencoding()
+
+ def get_text_writer(fo, **kwargs):
+ kw = dict(kwargs)
+ kw.setdefault('errors', 'backslashreplace') # use \uXXXX style
+ kw.setdefault('closefd', False)
+
+ if sys.version_info[0] < 3:
+ # Work around for Python 2.x
+ # New line conversion isn't needed here. Done in somewhere else.
+ writer = io.open(fo.fileno(), mode='w', newline='', **kw)
+ write = writer.write # save the original write() function
+ enc = locale.getpreferredencoding()
+ def convwrite(s):
+ if isinstance(s, bytes):
+ write(s.decode(enc)) # convert to unistr
+ else:
+ write(s)
+ try:
+ writer.flush() # needed on Windows
+ except IOError:
+ pass
+ writer.write = convwrite
+ else:
+ writer = io.open(fo.fileno(), mode='w', **kw)
+ return writer
+
+ sys.stdout = get_text_writer(sys.stdout, encoding=enc)
+ sys.stderr = get_text_writer(sys.stderr, encoding=enc)
+
+
+def main():
+ enc = 'utf-8'
+ if len(sys.argv) > 1:
+ enc = sys.argv[1]
+ set_output_encoding(enc)
+
+ message_tbl = {
+ 'utf-8': 'ÀÈÌÒÙ こんにちは 你好',
+ 'latin1': 'ÀÈÌÒÙ',
+ 'cp932': 'こんにちは',
+ 'cp936': '你好',
+ }
+
+ print('Xfoobar.c(10) : %s (%s)' % (message_tbl[enc], enc))
+
+
+if __name__ == "__main__":
+ main()