From ef011c914dcf6061af7b30c85db53336594cab81 Mon Sep 17 00:00:00 2001 From: hut Date: Thu, 8 Apr 2010 01:26:27 +0200 Subject: tc_newkey: added 2 failing test cases. Fix it! --- test/tc_newkeys.py | 66 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 53 insertions(+), 13 deletions(-) (limited to 'test') diff --git a/test/tc_newkeys.py b/test/tc_newkeys.py index a79ba83f..fc17aeda 100644 --- a/test/tc_newkeys.py +++ b/test/tc_newkeys.py @@ -500,35 +500,75 @@ class Test(PressTestCase): buffer = KeyBuffer(None, None) press = self._mkpress(buffer) - kmc = KeyManager(buffer, ['foo', 'bar']) + keymanager = KeyManager(buffer, ['foo', 'bar']) - map = kmc.get_context('foo') + map = keymanager.get_context('foo') map('a', func) map('b', func) - map = kmc.get_context('bar') + map = keymanager.get_context('bar') map('c', func) map('', getdown) - kmc.map('directions', 'j', dir=Direction(down=1)) + keymanager.map('directions', 'j', dir=Direction(down=1)) - kmc.use_context('foo') + keymanager.use_context('foo') self.assertEqual(5, press('a')) self.assertEqual(5, press('b')) self.assertPressFails(buffer, 'c') - kmc.use_context('bar') + keymanager.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') + keymanager.use_context('foo') + keymanager.use_context('foo') + keymanager.use_context('foo') + keymanager.use_context('bar') + keymanager.use_context('foo') + keymanager.use_context('bar') + keymanager.use_context('bar') self.assertEqual(1, press('j')) + def test_alias_to_direction(self): + def func(arg): + return arg.direction.down() + + km = KeyMap() + directions = KeyMap() + kb = KeyBuffer(km, directions) + press = self._mkpress(kb) + + km.map('', func) + directions.map('j', dir=Direction(down=42)) + self.assertEqual(42, press('j')) + + km.map('o', alias='j') + self.assertEqual(42, press('o')) + + def test_both_directory_and_any_key(self): + def func(arg): + return arg.direction.down() + def func2(arg): + return "yay" + + km = KeyMap() + directions = KeyMap() + kb = KeyBuffer(km, directions) + press = self._mkpress(kb) + + km.map('abc', func) + directions.map('j', dir=Direction(down=42)) + self.assertEqual(42, press('abcj')) + + km.unmap('abc') + + km.map('abc', func2) + self.assertEqual("yay", press('abcd')) + + km.map('abc', func) + + km.map('abc', func2) + self.assertEqual("yay", press('abcd')) if __name__ == '__main__': main() -- cgit 1.4.1-2-gfad0