Example #1
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(), "")
Example #2
0
 def test_createWithLines(self):
     """
     Verify that a history object can be created with an initial set of
     lines.
     """
     h = History(["a", "b"])
     self.assertEqual(h.allLines(), ["a", "b"])
Example #3
0
 def test_allLinesWhenEmpty(self):
     """
     Verify that retrieving all lines at once from an empty history object
     returns an empty list.
     """
     h = History()
     self.assertEqual(h.allLines(), [])
Example #4
0
 def test_addLineWhenEmpty(self):
     """
     Verify that a line added to an empty history object results in that
     line being included in the list returned by C{allLines}.
     """
     s = "hello world"
     h = History([s])
     self.assertEqual(h.allLines(), [s])
Example #5
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(), "")
Example #6
0
 def test_addLineAtEnd(self):
     """
     Verify that, by default, a line added to a history object is added
     after any existing lines.
     """
     s1 = "hello"
     s2 = "world"
     h = History([s1])
     h.addLine(s2)
     self.assertEqual(h.allLines(), [s1, s2])
Example #7
0
 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(), "")
Example #8
0
 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(), "")
Example #9
0
 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(), "")
Example #10
0
 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)
Example #11
0
 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)
Example #12
0
 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(), "")
Example #13
0
    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)
Example #14
0
 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])