diff options
author | Shougo Matsushita <Shougo.Matsu@gmail.com> | 2016-06-08 20:16:07 +0900 |
---|---|---|
committer | Shougo Matsushita <Shougo.Matsu@gmail.com> | 2016-06-08 20:16:07 +0900 |
commit | a11dc12777dc7266322b38938626994a262eda6f (patch) | |
tree | ad804d2d806bc20ba451834b82ea63b779b6d430 | |
parent | b381df3d05c64c6ef00795764d4139056b314d7d (diff) | |
download | deoplete.nvim-a11dc12777dc7266322b38938626994a262eda6f.zip |
Fix get_custom()
-rw-r--r-- | rplugin/python3/deoplete/tests/test_util.py | 9 | ||||
-rw-r--r-- | rplugin/python3/deoplete/util.py | 8 |
2 files changed, 14 insertions, 3 deletions
diff --git a/rplugin/python3/deoplete/tests/test_util.py b/rplugin/python3/deoplete/tests/test_util.py index f9aee02..a3c035f 100644 --- a/rplugin/python3/deoplete/tests/test_util.py +++ b/rplugin/python3/deoplete/tests/test_util.py @@ -1,7 +1,7 @@ from unittest import TestCase from nose.tools import eq_ from deoplete.util import ( - bytepos2charpos, charpos2bytepos) + bytepos2charpos, charpos2bytepos, get_custom) class UtilTestCase(TestCase): @@ -11,3 +11,10 @@ class UtilTestCase(TestCase): eq_(bytepos2charpos('utf-8', 'あああ', 3), 1) eq_(charpos2bytepos('utf-8', 'foo bar', 3), 3) eq_(charpos2bytepos('utf-8', 'あああ', 3), 9) + + def test_custom(self): + custom = {'_': {'mark': ''}, 'java': {'converters': []}} + eq_(get_custom(custom, 'java', 'mark', 'foobar'), '') + eq_(get_custom(custom, 'java', 'converters', 'foobar'), []) + eq_(get_custom(custom, 'foo', 'mark', 'foobar'), '') + eq_(get_custom(custom, 'foo', 'converters', 'foobar'), 'foobar') diff --git a/rplugin/python3/deoplete/util.py b/rplugin/python3/deoplete/util.py index 486612a..576bd1c 100644 --- a/rplugin/python3/deoplete/util.py +++ b/rplugin/python3/deoplete/util.py @@ -79,8 +79,12 @@ def bytepos2charpos(encoding, input, pos): def get_custom(custom, source_name, key, default): if source_name not in custom: return get_custom(custom, '_', key, default) - return (custom[source_name][key] - if key in custom[source_name] else default) + elif key in custom[source_name]: + return custom[source_name][key] + elif key in custom['_']: + return custom['_'][key] + else: + return default def get_syn_name(vim): |