From a11dc12777dc7266322b38938626994a262eda6f Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Wed, 8 Jun 2016 20:16:07 +0900 Subject: Fix get_custom() --- rplugin/python3/deoplete/tests/test_util.py | 9 ++++++++- 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): -- cgit v1.2.3