diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py index 7d69fd006..9d00aa5fc 100644 --- a/qutebrowser/config/configtypes.py +++ b/qutebrowser/config/configtypes.py @@ -236,10 +236,11 @@ class String(BaseType): minlen: Minimum length (inclusive). maxlen: Maximum length (inclusive). forbidden: Forbidden chars in the string. + _completions: completions to be used, or None """ def __init__(self, minlen=None, maxlen=None, forbidden=None, - none_ok=False): + none_ok=False, completions=None): super().__init__(none_ok) if minlen is not None and minlen < 1: raise ValueError("minlen ({}) needs to be >= 1!".format(minlen)) @@ -251,6 +252,7 @@ class String(BaseType): self.minlen = minlen self.maxlen = maxlen self.forbidden = forbidden + self._completions = completions def validate(self, value): self._basic_validation(value) @@ -267,6 +269,9 @@ class String(BaseType): raise configexc.ValidationError(value, "must be at most {} chars " "long!".format(self.maxlen)) + def complete(self): + return self._completions + class List(BaseType): diff --git a/tests/unit/config/test_configtypes.py b/tests/unit/config/test_configtypes.py index 6db89a2b2..b7ddcedb4 100644 --- a/tests/unit/config/test_configtypes.py +++ b/tests/unit/config/test_configtypes.py @@ -334,6 +334,14 @@ class TestString: def test_transform(self, klass): assert klass().transform('foobar') == 'foobar' + @pytest.mark.parametrize('value', [ + None, + ['one', 'two'], + [('1', 'one'), ('2', 'two')], + ]) + def test_complete(self, klass, value): + assert klass(completions=value).complete() == value + class TestList: