Compare objects with :set with multiple values

This commit is contained in:
Florian Bruhin 2017-09-25 21:10:52 +02:00
parent 1086e31f28
commit 38038df703
2 changed files with 18 additions and 3 deletions

View File

@ -275,14 +275,17 @@ class ConfigCommands:
# Use the next valid value from values, or the first if the current
# value does not appear in the list
old_value = self._config.get_str(option)
old_value = self._config.get_obj(option, mutable=False)
opt = self._config.get_opt(option)
values = [opt.typ.from_str(val) for val in values]
try:
idx = values.index(str(old_value))
idx = values.index(old_value)
idx = (idx + 1) % len(values)
value = values[idx]
except ValueError:
value = values[0]
self._config.set_str(option, value, save_yaml=not temp)
self._config.set_obj(option, value, save_yaml=not temp)
@contextlib.contextmanager
def _handle_config_error(self):

View File

@ -439,6 +439,18 @@ class TestSetConfigCommand:
assert config_stub.get(opt) == expected
assert config_stub._yaml[opt] == expected
def test_cycling_different_representation(self, commands, config_stub):
"""When using a different representation, cycling should work.
For example, we use [foo] which is represented as ["foo"].
"""
opt = 'qt_args'
config_stub.set_obj(opt, ['foo'])
commands.set(0, opt, '[foo]', '[bar]')
assert config_stub.get(opt) == ['bar']
commands.set(0, opt, '[foo]', '[bar]')
assert config_stub.get(opt) == ['foo']
class TestBindConfigCommand: