From 38038df70379a7ae14e58bbf9641de0309ea26a7 Mon Sep 17 00:00:00 2001
From: Florian Bruhin <git@the-compiler.org>
Date: Mon, 25 Sep 2017 21:10:52 +0200
Subject: [PATCH] Compare objects with :set with multiple values

---
 qutebrowser/config/config.py     |  9 ++++++---
 tests/unit/config/test_config.py | 12 ++++++++++++
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/qutebrowser/config/config.py b/qutebrowser/config/config.py
index 8d93a2344..c7826aef2 100644
--- a/qutebrowser/config/config.py
+++ b/qutebrowser/config/config.py
@@ -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):
diff --git a/tests/unit/config/test_config.py b/tests/unit/config/test_config.py
index 24c6814b5..949064bc9 100644
--- a/tests/unit/config/test_config.py
+++ b/tests/unit/config/test_config.py
@@ -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: