summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--Makefile3
-rw-r--r--ranger/ext/keybinding_parser.py20
2 files changed, 18 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index 109d9f2a..0a79142e 100644
--- a/Makefile
+++ b/Makefile
@@ -14,6 +14,7 @@ SETUPOPTS ?= '--record=install_log.txt'
 DOCDIR ?= doc/pydoc
 DESTDIR ?= /
 PYOPTIMIZE ?= 1
+FILTER ?= .
 
 CWD = $(shell pwd)
 
@@ -60,7 +61,7 @@ doc: cleandoc
 	find . -name \*.html -exec sed -i 's|'$(CWD)'|../..|g' -- {} \;
 
 test:
-	@for FILE in $(shell grep -IHm 1 doctest -r ranger | cut -d: -f1); do \
+	@for FILE in $(shell grep -IHm 1 doctest -r ranger | grep $(FILTER) | cut -d: -f1); do \
 		echo "Testing $$FILE..."; \
 		RANGER_DOCTEST=1 PYTHONPATH=".:"$$PYTHONPATH ${PYTHON} $$FILE; \
 	done
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()