|
1 | 1 | import unittest |
| 2 | +from itertools import islice |
| 3 | + |
2 | 4 | from bpython import repl |
3 | 5 |
|
4 | 6 |
|
@@ -52,7 +54,80 @@ def test_forward(self): |
52 | 54 | self.history.forward() |
53 | 55 | self.assertEqual(self.history.forward(), '#999') |
54 | 56 |
|
| 57 | + def test_append(self): |
| 58 | + self.history.append('print "foo\n"\n') |
| 59 | + self.history.append('\n') |
| 60 | + |
| 61 | + self.assertEqual(self.history.back(), 'print "foo\n"') |
| 62 | + |
| 63 | + def test_enter(self): |
| 64 | + self.history.enter('#lastnumber!') |
| 65 | + |
| 66 | + self.assertEqual(self.history.back(), '#999') |
| 67 | + self.assertEqual(self.history.forward(), '#lastnumber!') |
| 68 | + |
| 69 | + def test_reset(self): |
| 70 | + self.history.enter('#lastnumber!') |
| 71 | + self.history.reset() |
| 72 | + |
| 73 | + self.assertEqual(self.history.back(), '#999') |
| 74 | + self.assertEqual(self.history.forward(), '') |
| 75 | + |
| 76 | + |
| 77 | +class TestMatchesIterator(unittest.TestCase): |
| 78 | + |
| 79 | + def setUp(self): |
| 80 | + self.matches = ['bobby', 'bobbies', 'bobberina'] |
| 81 | + self.matches_iterator = repl.MatchesIterator(current_word='bob', |
| 82 | + matches=self.matches) |
| 83 | + |
| 84 | + def test_next(self): |
| 85 | + self.assertEqual(self.matches_iterator.next(), self.matches[0]) |
| 86 | + |
| 87 | + for x in range(len(self.matches) - 1): |
| 88 | + self.matches_iterator.next() |
| 89 | + |
| 90 | + self.assertEqual(self.matches_iterator.next(), self.matches[0]) |
| 91 | + self.assertEqual(self.matches_iterator.next(), self. matches[1]) |
| 92 | + self.assertNotEqual(self.matches_iterator.next(), self.matches[1]) |
| 93 | + |
| 94 | + def test_previous(self): |
| 95 | + self.assertEqual(self.matches_iterator.previous(), self.matches[2]) |
| 96 | + |
| 97 | + for x in range(len(self.matches) - 1): |
| 98 | + self.matches_iterator.previous() |
| 99 | + |
| 100 | + self.assertNotEqual(self.matches_iterator.previous(), self.matches[0]) |
| 101 | + self.assertEqual(self.matches_iterator.previous(), self.matches[1]) |
| 102 | + self.assertEqual(self.matches_iterator.previous(), self.matches[0]) |
| 103 | + |
| 104 | + def test_nonzero(self): |
| 105 | + """self.matches_iterator should be False at start, |
| 106 | + then True once we active a match. |
| 107 | + """ |
| 108 | + self.assertFalse(self.matches_iterator) |
| 109 | + self.matches_iterator.next() |
| 110 | + self.assertTrue(self.matches_iterator) |
| 111 | + |
| 112 | + def test_iter(self): |
| 113 | + slice = islice(self.matches_iterator, 0, 9) |
| 114 | + self.assertEqual(list(slice), self.matches * 3) |
| 115 | + |
| 116 | + def test_current(self): |
| 117 | + self.assertRaises(ValueError, self.matches_iterator.current) |
| 118 | + self.matches_iterator.next() |
| 119 | + self.assertEqual(self.matches_iterator.current(), self.matches[0]) |
| 120 | + |
| 121 | + def test_update(self): |
| 122 | + slice = islice(self.matches_iterator, 0, 3) |
| 123 | + self.assertEqual(list(slice), self.matches) |
| 124 | + |
| 125 | + newmatches = ['string', 'str', 'set'] |
| 126 | + self.matches_iterator.update('s', newmatches) |
55 | 127 |
|
| 128 | + newslice = islice(newmatches, 0, 3) |
| 129 | + self.assertNotEqual(list(slice), self.matches) |
| 130 | + self.assertEqual(list(newslice), newmatches) |
56 | 131 |
|
57 | 132 |
|
58 | 133 | if __name__ == '__main__': |
|
0 commit comments