blob: 11045c852e905f6bd6ffda3fdb7d240aea2ef0af [file] [log] [blame]
Ronald Oussoren9f20d9d2009-09-20 14:18:15 +00001"""
2Very minimal unittests for parts of the readline module.
3
4These tests were added to check that the libedit emulation on OSX and
5the "real" readline have the same interface for history manipulation. That's
6why the tests cover only a small subset of the interface.
7"""
8import unittest
Mark Dickinson828b3982009-10-26 11:59:30 +00009from test.test_support import run_unittest, import_module
Ronald Oussoren9f20d9d2009-09-20 14:18:15 +000010
Mark Dickinson828b3982009-10-26 11:59:30 +000011# Skip tests if there is no readline module
12readline = import_module('readline')
Ronald Oussoren9f20d9d2009-09-20 14:18:15 +000013
14class TestHistoryManipulation (unittest.TestCase):
15 def testHistoryUpdates(self):
16 readline.clear_history()
17
18 readline.add_history("first line")
19 readline.add_history("second line")
20
21 self.assertEqual(readline.get_history_item(0), None)
22 self.assertEqual(readline.get_history_item(1), "first line")
23 self.assertEqual(readline.get_history_item(2), "second line")
24
25 readline.replace_history_item(0, "replaced line")
26 self.assertEqual(readline.get_history_item(0), None)
27 self.assertEqual(readline.get_history_item(1), "replaced line")
28 self.assertEqual(readline.get_history_item(2), "second line")
29
30 self.assertEqual(readline.get_current_history_length(), 2)
31
32 readline.remove_history_item(0)
33 self.assertEqual(readline.get_history_item(0), None)
34 self.assertEqual(readline.get_history_item(1), "second line")
35
36 self.assertEqual(readline.get_current_history_length(), 1)
37
38
39def test_main():
40 run_unittest(TestHistoryManipulation)
41
42if __name__ == "__main__":
43 test_main()