Beispiel #1
0
    def test_passive_action(self):
        km = KeyMap()
        directions = KeyMap()
        kb = KeyBuffer(km, directions)

        def n(value):
            """return n or value"""
            def fnc(arg=None):
                if arg is None or arg.n is None:
                    return value
                return arg.n

            return fnc

        km.map('ppp', n(5))
        km.map('pp<bg>', n(8))
        km.map('pp<dir>', n(2))
        directions.map('j', dir=Direction(down=1))

        press = self._mkpress(kb, km)
        self.assertEqual(5, press('ppp'))
        self.assertEqual(3, press('3ppp'))

        self.assertEqual(2, press('ppj'))

        kb.clear()
        match = simulate_press(kb, 'pp')
        args = CommandArgs(0, 0, kb)
        self.assert_(match)
        self.assert_(match.function)
        self.assertEqual(8, match.function(args))
Beispiel #2
0
	def test_passive_action(self):
		km = KeyMap()
		directions = KeyMap()
		kb = KeyBuffer(km, directions)
		def n(value):
			"""return n or value"""
			def fnc(arg=None):
				if arg is None or arg.n is None:
					return value
				return arg.n
			return fnc

		km.map('ppp', n(5))
		km.map('pp<bg>', n(8))
		km.map('pp<dir>', n(2))
		directions.map('j', dir=Direction(down=1))

		press = self._mkpress(kb, km)
		self.assertEqual(5, press('ppp'))
		self.assertEqual(3, press('3ppp'))

		self.assertEqual(2, press('ppj'))

		kb.clear()
		match = simulate_press(kb, 'pp')
		args = CommandArgs(0, 0, kb)
		self.assert_(match)
		self.assert_(match.function)
		self.assertEqual(8, match.function(args))
Beispiel #3
0
    def test_corruptions(self):
        km = KeyMap()
        directions = KeyMap()
        kb = KeyBuffer(km, directions)
        press = self._mkpress(kb, km)
        directions.map('j', dir=Direction(down=1))
        directions.map('k', dir=Direction(down=-1))
        km.map('xxx', lambda _: 1)

        self.assertEqual(1, press('xxx'))

        # corrupt the tree
        tup = tuple(parse_keybinding('xxx'))
        x = ord('x')
        km._tree[x][x][x] = "Boo"

        self.assertPressFails(kb, 'xxy')
        self.assertPressFails(kb, 'xzy')
        self.assertPressIncomplete(kb, 'xx')
        self.assertPressIncomplete(kb, 'x')
        if not sys.flags.optimize:  # asserts are ignored with python -O
            self.assertRaises(AssertionError, simulate_press, kb, 'xxx')
        kb.clear()
Beispiel #4
0
	def test_corruptions(self):
		km = KeyMap()
		directions = KeyMap()
		kb = KeyBuffer(km, directions)
		press = self._mkpress(kb, km)
		directions.map('j', dir=Direction(down=1))
		directions.map('k', dir=Direction(down=-1))
		km.map('xxx', lambda _: 1)

		self.assertEqual(1, press('xxx'))

		# corrupt the tree
		tup = tuple(parse_keybinding('xxx'))
		x = ord('x')
		km._tree[x][x][x] = "Boo"

		self.assertPressFails(kb, 'xxy')
		self.assertPressFails(kb, 'xzy')
		self.assertPressIncomplete(kb, 'xx')
		self.assertPressIncomplete(kb, 'x')
		if not sys.flags.optimize:  # asserts are ignored with python -O
			self.assertRaises(AssertionError, simulate_press, kb, 'xxx')
		kb.clear()