summary refs log tree commit diff stats
path: root/test/tc_newkeys.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/tc_newkeys.py')
-rw-r--r--test/tc_newkeys.py39
1 files changed, 38 insertions, 1 deletions
diff --git a/test/tc_newkeys.py b/test/tc_newkeys.py
index c953e88b..b1cb42fb 100644
--- a/test/tc_newkeys.py
+++ b/test/tc_newkeys.py
@@ -24,7 +24,7 @@ import sys
 
 class PressTestCase(TestCase):
 	"""Some useful methods for the actual test"""
-	def _mkpress(self, keybuffer, keymap):
+	def _mkpress(self, keybuffer, _=0):
 		def press(keys):
 			keybuffer.clear()
 			match = keybuffer.simulate_press(keys)
@@ -492,5 +492,42 @@ class Test(PressTestCase):
 		s.replace('Y')
 		self.assertNotEqual(t._tree, u._tree)
 
+	def test_keymap_with_context(self):
+		def func(arg):
+			return 5
+		def getdown(arg):
+			return arg.direction.down()
+
+		buffer = KeyBuffer(None, None)
+		press = self._mkpress(buffer)
+		kmc = KeyManager(buffer, ['foo', 'bar'])
+
+		map = kmc.get_context('foo')
+		map('a', func)
+		map('b', func)
+		map = kmc.get_context('bar')
+		map('c', func)
+		map('<dir>', getdown)
+
+		kmc.map('directions', 'j', dir=Direction(down=1))
+
+		kmc.use_context('foo')
+		self.assertEqual(5, press('a'))
+		self.assertEqual(5, press('b'))
+		self.assertPressFails(buffer, 'c')
+
+		kmc.use_context('bar')
+		self.assertPressFails(buffer, 'a')
+		self.assertPressFails(buffer, 'b')
+		self.assertEqual(5, press('c'))
+		self.assertEqual(1, press('j'))
+		kmc.use_context('foo')
+		kmc.use_context('foo')
+		kmc.use_context('foo')
+		kmc.use_context('bar')
+		kmc.use_context('foo')
+		kmc.use_context('bar')
+		kmc.use_context('bar')
+		self.assertEqual(1, press('j'))
 
 if __name__ == '__main__': main()
suckless/dwm/commit/config.arg.h?h=5.3&id=a73a88280681acdab047bd11a9ba77d97d6a0b72'>a73a882 ^
292ccc4 ^
ce04a66 ^
8c334ee ^
24d91e3 ^
950a1ab ^
80bf2aa ^
24d91e3 ^

292ccc4 ^
ce04a66 ^
19da197 ^


19da197 ^


ce04a66 ^








a73a882 ^



d6a6eca ^
e21d93b ^



a73a882 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54