summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-04-07 03:28:52 +0200
committerhut <hut@lavabit.com>2010-04-07 03:28:52 +0200
commit54ea4a29b7e95431df3d33aa1ffea1ad8c5ee321 (patch)
tree9bd3556d1136b90fe8f550a0e86878b42d411b2d
parent7a2665c23f381b08a3237384b49f3a585fbf4b30 (diff)
downloadranger-54ea4a29b7e95431df3d33aa1ffea1ad8c5ee321.tar.gz
dc_direction: added test_move()
-rw-r--r--ranger/ext/direction.py15
-rw-r--r--test/tc_direction.py9
2 files changed, 22 insertions, 2 deletions
diff --git a/ranger/ext/direction.py b/ranger/ext/direction.py
index 2f9e1d96..417f3add 100644
--- a/ranger/ext/direction.py
+++ b/ranger/ext/direction.py
@@ -104,8 +104,19 @@ class Direction(dict):
 			if key in self:
 				self[key] = n
 
-	def move(self, direction, override=0, minimum=0, maximum=9999,
-			current=0, pagesize=10, offset=0):
+	def move(self, direction, override=None, minimum=0, maximum=9999,
+			current=0, pagesize=1, offset=0):
+		"""
+		Calculates the new position in a given boundary.
+
+		Example:
+		d = Direction(pages=True)
+		d.move(direction=3) # = 3
+		d.move(direction=3, current=2) # = 5
+		d.move(direction=3, pagesize=5) # = 15
+		d.move(direction=3, pagesize=5, maximum=10) # = 10
+		d.move(direction=9, override=2) # = 18
+		"""
 		pos = direction
 		if override is not None:
 			if self.absolute():
diff --git a/test/tc_direction.py b/test/tc_direction.py
index f6b1392f..f1078b2d 100644
--- a/test/tc_direction.py
+++ b/test/tc_direction.py
@@ -65,6 +65,15 @@ class TestDirections(unittest.TestCase):
 		self.assertEqual(-7, Direction.left(dct))
 		self.assertEqual(3, Direction.up(dct))
 
+	def test_move(self):
+		d = Direction(pages=True)
+		self.assertEqual(3, d.move(direction=3))
+		self.assertEqual(5, d.move(direction=3, current=2))
+		self.assertEqual(15, d.move(direction=3, pagesize=5))
+		self.assertEqual(10, d.move(direction=3, pagesize=5, maximum=10))
+		self.assertEqual(18, d.move(direction=9, override=2))
+		d2 = Direction(absolute=True)
+		self.assertEqual(5, d2.move(direction=9, override=5))
 
 if __name__ == '__main__':
 	unittest.main()