about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lepus.uberspace.de>2014-02-03 16:33:46 +0100
committerhut <hut@lepus.uberspace.de>2014-02-03 16:33:46 +0100
commit80a7914a3fa737b7dd05af43d9347dc654db6064 (patch)
treeeafb31f9bee2fbd150af431259771f0824093b0d
parentf473be92d270654c67e0eb4fc8c17a5be99e29b2 (diff)
downloadranger-80a7914a3fa737b7dd05af43d9347dc654db6064.tar.gz
ext.keybinding_parser: added doctests
-rw-r--r--ranger/ext/keybinding_parser.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/ranger/ext/keybinding_parser.py b/ranger/ext/keybinding_parser.py
index 0519f69f..d7b24be3 100644
--- a/ranger/ext/keybinding_parser.py
+++ b/ranger/ext/keybinding_parser.py
@@ -63,10 +63,18 @@ reversed_special_keys = dict((v, k) for k, v in special_keys.items())
 def parse_keybinding(obj):
     """Translate a keybinding to a sequence of integers
 
-    Example:
-    lol<CR>   =>   (ord('l'), ord('o'), ord('l'), ord('\\n'))
-              =>   (108, 111, 108, 10)
-    x<A-Left> =>   (120, (27, curses.KEY_LEFT))
+    >>> tuple(parse_keybinding("lol<CR>"))
+    (108, 111, 108, 10)
+
+    >>> out = tuple(parse_keybinding("x<A-Left>"))
+    >>> out  # it's kind of dumb that you cant test for constants...
+    (120, 9003, 260)
+    >>> out[0] == ord('x')
+    True
+    >>> out[1] == ALT_KEY
+    True
+    >>> out[2] == curses.KEY_LEFT
+    True
     """
     assert isinstance(obj, (tuple, int, str))
     if isinstance(obj, tuple):
@@ -249,3 +257,7 @@ class KeyBuffer(object):
 
     def __str__(self):
         return "".join(key_to_string(c) for c in self.keys)
+
+if __name__ == '__main__':
+    import doctest
+    doctest.testmod()