def test_previousLineWithTwoLines(self): """ Verify that when the history object is positioned somewhere in the middle, C{previousLine} returns the previous line. """ s1 = "hello" s2 = "world" h = History([s1, s2]) self.assertEqual(h.previousLine(), s2) self.assertEqual(h.previousLine(), s1) self.assertEqual(h.previousLine(), "")
def test_resetPosition(self): """ Verify that the position in the history object can be set to the end using the C{resetPosition} method. """ s = "hello" h = History() h.addLine(s) h.previousLine() h.resetPosition() self.assertEqual(h.nextLine(), "")
def test_addLineInMiddle(self): """ Verify that even if the history object is not positioned at the end, C{addLine} adds the line to the end. """ s1 = "hello" s2 = "world" s3 = "goodbye" h = History([s1, s2]) h.previousLine() h.addLine(s3) self.assertEqual(h.allLines(), [s1, s2, s3])
def test_nextLine(self): """ Verify that C-n replaces the current input buffer with the next line from the input history. """ s = 'hello world' self.widget.buffer = s history = History(['first', 'second', 'last']) history.previousLine() history.previousLine() self.widget.setInputHistory(history) self.widget.keystrokeReceived('\x0e', None) self.assertEqual(self.widget.buffer, 'last') self.assertEqual(self.widget.cursor, 0)
def test_previousLineWithNoLines(self): """ Verify that retrieving the previous line from an empty history object returns an empty string. """ h = History() self.assertEqual(h.previousLine(), "")
def test_nextLineTwice(self): """ Verify that C-n twice in a row results in the 2nd to first line from the input history being placed in the input buffer. """ s = 'hello world' self.widget.buffer = s history = History(['first', 'second', 'last']) history.previousLine() history.previousLine() history.previousLine() self.widget.setInputHistory(history) self.widget.keystrokeReceived('\x0e', None) self.widget.keystrokeReceived('\x0e', None) self.assertEqual(self.widget.buffer, 'last') self.assertEqual(self.widget.cursor, 0)
def test_previousLineWithOneLine(self): """ Verify that when there is a line in the history object, C{previousLine} returns it. """ s = "hello" h = History([s]) self.assertEqual(h.previousLine(), s) self.assertEqual(h.previousLine(), "")
def test_nextLineWithOneLine(self): """ Verify that when positioned at the beginning and containing only one line, the history object's C{nextLine} method returns an empty string. """ s = "hello" h = History([s]) while h.previousLine(): pass self.assertEqual(h.nextLine(), "")
def test_historyPositionResetByReturn(self): """ Verify that C{'\r'} resets the history position to the end. """ s1 = "hello" s2 = "world" s3 = "goodbye" history = History([s1, s2, s3]) self.widget.setInputHistory(history) self.widget.keystrokeReceived('\x10', None) # put s3 up self.widget.keystrokeReceived('\x10', None) # put s2 up self.widget.keystrokeReceived('\r', None) # submit s2 # s2 should be the previous line now, since it was added to the input # history and the input history position was reset. self.assertEqual(history.previousLine(), s2) # Followed by s3, s2, and s1 self.assertEqual(history.previousLine(), s3) self.assertEqual(history.previousLine(), s2) self.assertEqual(history.previousLine(), s1)
def test_nextLineWithTwoLines(self): """ Verify that when a history object contains two lines and is positioned at the beginning, C{nextLine} first returns the second line and then returns an empty string. """ s1 = "hello" s2 = "world" h = History([s1, s2]) while h.previousLine(): pass self.assertEqual(h.nextLine(), s2) self.assertEqual(h.nextLine(), "")