summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShougo Matsushita <Shougo.Matsu@gmail.com>2016-06-07 20:35:47 +0900
committerShougo Matsushita <Shougo.Matsu@gmail.com>2016-06-07 20:35:47 +0900
commit37984680ad80a126f833828fbcb7ac3e3cc796d2 (patch)
treee0db879cf3709a946d9400c2aaba6b31f099f81b
parent87c01d4de5e984bd95c6c3d51a9054d619e97e8f (diff)
downloaddeoplete.nvim-37984680ad80a126f833828fbcb7ac3e3cc796d2.zip
Fix bytepos2charpos()
-rw-r--r--rplugin/python3/deoplete/tests/test_util.py13
-rw-r--r--rplugin/python3/deoplete/util.py2
2 files changed, 14 insertions, 1 deletions
diff --git a/rplugin/python3/deoplete/tests/test_util.py b/rplugin/python3/deoplete/tests/test_util.py
new file mode 100644
index 0000000..f9aee02
--- /dev/null
+++ b/rplugin/python3/deoplete/tests/test_util.py
@@ -0,0 +1,13 @@
+from unittest import TestCase
+from nose.tools import eq_
+from deoplete.util import (
+ bytepos2charpos, charpos2bytepos)
+
+
+class UtilTestCase(TestCase):
+
+ def test_pos(self):
+ eq_(bytepos2charpos('utf-8', 'foo bar', 3), 3)
+ eq_(bytepos2charpos('utf-8', 'あああ', 3), 1)
+ eq_(charpos2bytepos('utf-8', 'foo bar', 3), 3)
+ eq_(charpos2bytepos('utf-8', 'あああ', 3), 9)
diff --git a/rplugin/python3/deoplete/util.py b/rplugin/python3/deoplete/util.py
index b913594..486612a 100644
--- a/rplugin/python3/deoplete/util.py
+++ b/rplugin/python3/deoplete/util.py
@@ -73,7 +73,7 @@ def charpos2bytepos(encoding, input, pos):
def bytepos2charpos(encoding, input, pos):
- return len(str(bytes(input[: pos], encoding)))
+ return len(bytes(input, encoding)[: pos].decode(encoding))
def get_custom(custom, source_name, key, default):