From 8b31117faf71bb1cf0da026134759376f5f825d5 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Sat, 10 Nov 2012 19:55:56 +0100 Subject: [PATCH] Add a test for multi-byte string source --- jedi/_compatibility.py | 9 +++++++++ test/regression.py | 14 +++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/jedi/_compatibility.py b/jedi/_compatibility.py index 11bd1f89..d7015268 100644 --- a/jedi/_compatibility.py +++ b/jedi/_compatibility.py @@ -60,6 +60,15 @@ try: except NameError: unicode = str +if is_py3k: + utf8 = lambda s: s +else: + utf8 = lambda s: s.decode('utf-8') + +utf8.__doc__ = """ +Decode a raw string into unicode object. Do nothing in Python 3. +""" + # exec function if is_py3k: def exec_function(source, global_map): diff --git a/test/regression.py b/test/regression.py index 3e7d0f61..c8b98d66 100755 --- a/test/regression.py +++ b/test/regression.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +# -*- coding: utf-8 -*- import os import sys import unittest @@ -10,7 +11,7 @@ sys.path.append(abspath(dirname(abspath(__file__)) + '/../jedi')) os.chdir(os.path.dirname(os.path.abspath(__file__)) + '/../jedi') sys.path.append('.') -from _compatibility import is_py25 +from _compatibility import is_py25, utf8 import api #api.set_debug_function(api.debug.print_to_stdout) @@ -206,6 +207,17 @@ class TestRegression(Base): else: assert len(self.complete(s)) + def test_multibyte_script(self): + """ `jedi.Script` must accept multi-byte string source. """ + try: + code = unicode("import datetime; datetime.d") + comment = utf8("# multi-byte comment あいうえお") + s = (unicode('%s\n%s') % (code, comment)).encode('utf-8') + except NameError: + pass # python 3 has no unicode method + else: + assert len(self.complete(s, (1, len(code)))) + def test_os_nowait(self): """ github issue #45 """ s = self.complete("import os; os.P_")