def test_CNL_ExplicitParam(self): """CNL moves the cursor down by the passed-in number of lines.""" esccmd.CUP(Point(6, 3)) esccmd.CNL(2) position = GetCursorPosition() AssertEQ(position.x(), 1) AssertEQ(position.y(), 5)
def test_CNL_DefaultParam(self): """CNL moves the cursor down 1 with no parameter given.""" esccmd.CUP(Point(5, 3)) esccmd.CNL() position = GetCursorPosition() AssertEQ(position.x(), 1) AssertEQ(position.y(), 4)
def test_NEL_Basic(self): """Next Line moves the cursor down one line and to the start of the next line.""" esccmd.CUP(Point(5, 3)) esccmd.NEL() position = GetCursorPosition() AssertEQ(position.x(), 1) AssertEQ(position.y(), 4)
def prepare(self): """Sets the screen up as abcde fghij klmno pqrst uvwxy With the cursor on the 'h'.""" lines = ["abcde", "fghij", "klmno", "pqrst", "uvwxy"] for i in xrange(len(lines)): y = i + 1 line = lines[i] esccmd.CUP(Point(1, y)) escio.Write(line) esccmd.CUP(Point(3, 2))
def test_SaveRestoreCursor_WorksInLRM(self, shouldWork=True): """Subclasses may cause shouldWork to be set to false.""" esccmd.CUP(Point(2, 3)) self.saveCursor() esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(1, 10) esccmd.CUP(Point(5, 6)) self.saveCursor() esccmd.CUP(Point(4, 5)) self.restoreCursor() if shouldWork: AssertEQ(GetCursorPosition(), Point(5, 6)) else: AssertEQ(GetCursorPosition(), Point(2, 3))
def test_IND_Basic(self): """Index moves the cursor down one line.""" esccmd.CUP(Point(5, 3)) esccmd.IND() position = GetCursorPosition() AssertEQ(position.x(), 5) AssertEQ(position.y(), 4)
def test_CHA_ZeroParam(self): """CHA moves as far left as possible when given a zero parameter.""" esccmd.CUP(Point(5, 3)) esccmd.CHA(0) position = GetCursorPosition() AssertEQ(position.x(), 1) AssertEQ(position.y(), 3)
def test_SM_IRM(self): """Turn on insert mode.""" escio.Write("abc") esccmd.CUP(Point(1, 1)) esccmd.SM(esccmd.IRM) escio.Write("X") AssertScreenCharsInRectEqual(Rect(1, 1, 4, 1), ["Xabc"])
def test_HPR_DefaultParams(self): """With no params, HPR moves right by 1.""" esccmd.CUP(Point(6, 1)) esccmd.HPR() position = GetCursorPosition() AssertEQ(position.x(), 7)
def test_CHA_ExplicitParam(self): """CHA moves to specified column of active line.""" esccmd.CUP(Point(5, 3)) esccmd.CHA(10) position = GetCursorPosition() AssertEQ(position.x(), 10) AssertEQ(position.y(), 3)
def test_HPR_IgnoresOriginMode(self): """HPR continues to work in origin mode.""" # Set a scroll region. esccmd.DECSTBM(6, 11) esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(5, 10) # Enter origin mode esccmd.DECSET(esccmd.DECOM) # Move to center of region esccmd.CUP(Point(2, 2)) escio.Write('X') # Move right by 2 esccmd.HPR(2) escio.Write('Y') # Exit origin mode esccmd.DECRESET(esccmd.DECOM) # Reset margins esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSTBM() # See what happened AssertScreenCharsInRectEqual(Rect(5, 7, 9, 7), [empty() + "X" + empty() * 2 + "Y"])
def test_DECSET_DECAWM_NoLineWrapOnTabWithLeftRightMargin(self): esccmd.DECSET(esccmd.DECAWM) esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_CHARS, 24, 80) esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(10, 20) # Move to origin and tab thrice. Should stop at right margin. AssertEQ(GetCursorPosition(), Point(1, 1)) escio.Write(TAB) AssertEQ(GetCursorPosition(), Point(9, 1)) escio.Write(TAB) AssertEQ(GetCursorPosition(), Point(17, 1)) escio.Write(TAB) AssertEQ(GetCursorPosition(), Point(20, 1)) escio.Write(TAB) AssertEQ(GetCursorPosition(), Point(20, 1))
def test_DECSET_DECAWM(self): """Auto-wrap mode.""" size = GetScreenSize() esccmd.CUP(Point(size.width() - 1, 1)) esccmd.DECSET(esccmd.DECAWM) escio.Write("abc") AssertScreenCharsInRectEqual(Rect(1, 2, 1, 2), ["c"]) esccmd.CUP(Point(size.width() - 1, 1)) esccmd.DECRESET(esccmd.DECAWM) escio.Write("ABC") AssertScreenCharsInRectEqual( Rect(size.width() - 1, 1, size.width(), 1), ["AC"]) AssertScreenCharsInRectEqual(Rect(1, 2, 1, 2), ["c"])
def test_VPR_DefaultParams(self): """With no params, VPR moves right by 1.""" esccmd.CUP(Point(1, 6)) esccmd.VPR() position = GetCursorPosition() AssertEQ(position.y(), 7)
def test_CHA_DefaultParam(self): """CHA moves to first column of active line by default.""" esccmd.CUP(Point(5, 3)) esccmd.CHA() position = GetCursorPosition() AssertEQ(position.x(), 1) AssertEQ(position.y(), 3)
def test_DECSET_DECLRMM_ModeNotResetByDECSTR(self): esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSTR() esccmd.DECSLRM(2, 4) esccmd.CUP(Point(3, 3)) escio.Write("abc") AssertEQ(GetCursorPosition().x(), 3)
def test_HVP_ZeroIsTreatedAsOne(self): """Zero args are treated as 1.""" esccmd.HVP(Point(6, 3)) esccmd.HVP(col=0, row=0) position = GetCursorPosition() AssertEQ(position.x(), 1) AssertEQ(position.y(), 1)
def test_CUB_DefaultParam(self): """CUB moves the cursor left 1 with no parameter given.""" esccmd.CUP(Point(5, 3)) esccmd.CUB() position = GetCursorPosition() AssertEQ(position.x(), 4) AssertEQ(position.y(), 3)
def GetWindowPosition(): """Returns a Point giving the window's origin in screen pixels.""" esccmd.XTERM_WINOPS(esccmd.WINOP_REPORT_WINDOW_POSITION) params = escio.ReadCSI("t") AssertTrue(params[0] == 3) AssertTrue(len(params) >= 3) return Point(params[1], params[2])
def test_DECSTR_DECOM(self): # Define a scroll region esccmd.DECSTBM(3, 4) # Turn on origin mode esccmd.DECSET(esccmd.DECOM) # Perform soft reset esccmd.DECSTR() # Define scroll region again esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(3, 4) esccmd.DECSTBM(4, 5) # Move to 1,1 (or 3,4 if origin mode is still on) and write an X esccmd.CUP(Point(1, 1)) escio.Write("X") # Turn off origin mode esccmd.DECRESET(esccmd.DECOM) # Make sure the X was at 1, 1, implying origin mode was off. esccmd.DECSTBM() esccmd.DECRESET(esccmd.DECLRMM) AssertScreenCharsInRectEqual(Rect( 1, 1, 3, 4), ["X" + NUL * 2, NUL * 3, NUL * 3, NUL * 3])
def test_DECDC_DeleteAll(self): """Test DECDC behavior when deleting more columns than are available.""" width = GetScreenSize().width() s = "abcdefg" startX = width - len(s) + 1 esccmd.CUP(Point(startX, 1)) escio.Write(s) esccmd.CUP(Point(startX, 2)) escio.Write(s.upper()) esccmd.CUP(Point(startX + 1, 1)) esccmd.DECDC(width + 10) AssertScreenCharsInRectEqual(Rect(startX, 1, width, 2), ["a" + empty() * 6, "A" + empty() * 6]) # Ensure there is no wrap-around. AssertScreenCharsInRectEqual(Rect(1, 2, 1, 3), [empty(), empty()])
def test_RI_Basic(self): """Reverse index moves the cursor up one line.""" esccmd.CUP(Point(5, 3)) esccmd.RI() position = GetCursorPosition() AssertEQ(position.x(), 5) AssertEQ(position.y(), 2)
def test_CUU_DefaultParam(self): """CUU moves the cursor up 1 with no parameter given.""" esccmd.CUP(Point(5, 3)) esccmd.CUU() position = GetCursorPosition() AssertEQ(position.x(), 5) AssertEQ(position.y(), 2)
def test_FF_Basic(self): """FF moves the cursor down one line.""" esccmd.CUP(Point(5, 3)) escio.Write(FF) position = GetCursorPosition() AssertEQ(position.x(), 5) AssertEQ(position.y(), 4)
def prepare_wide(self): """Sets up the display as: abcde fghij klmno With the cursor on the 'h'. """ esccmd.CUP(Point(1, 1)) escio.Write("abcde") esccmd.CUP(Point(1, 2)) escio.Write("fghij") esccmd.CUP(Point(1, 3)) escio.Write("klmno") esccmd.CUP(Point(2, 3))
def test_VPR_IgnoresOriginMode(self): """VPR continues to work in origin mode.""" # Set a scroll region. esccmd.DECSTBM(6, 11) esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(5, 10) # Enter origin mode esccmd.DECSET(esccmd.DECOM) # Move to center of region esccmd.CUP(Point(2, 2)) escio.Write('X') # Move down by 2 esccmd.VPR(2) escio.Write('Y') # Exit origin mode esccmd.DECRESET(esccmd.DECOM) # Reset margins esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSTBM() # See what happened AssertScreenCharsInRectEqual(Rect(6, 7, 7, 9), ['X' + NUL, NUL * 2, NUL + 'Y'])
def test_DECSET_DECLRMM_ModeResetByDECSTR(self): """ DEC STD 070 says DECSTR resets left/right mode.""" esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSTR() esccmd.DECSLRM(2, 4) esccmd.CUP(Point(3, 3)) escio.Write("abc") AssertEQ(GetCursorPosition().x(), 6)
def test_DECSET_ReverseWraparound_Multi(self): size = GetScreenSize() esccmd.CUP(Point(size.width() - 1, 1)) escio.Write("abcd") esccmd.DECSET(esccmd.ReverseWraparound) esccmd.DECSET(esccmd.DECAWM) esccmd.CUB(4) AssertEQ(GetCursorPosition().x(), size.width() - 1)
def test_DECSET_ReverseWraparound_RequiresDECAWM(self): """Reverse wraparound only works if DECAWM is set.""" # iTerm2 turns reverse wraparound on by default, while xterm does not. esccmd.CUP(Point(1, 2)) esccmd.DECSET(esccmd.ReverseWraparound) esccmd.DECRESET(esccmd.DECAWM) escio.Write(BS) AssertEQ(GetCursorPosition().x(), 1)
def test_CHA_OutOfBoundsLarge(self): """CHA moves as far as possible when given a too-large parameter.""" esccmd.CUP(Point(5, 3)) esccmd.CHA(9999) position = GetCursorPosition() width = GetScreenSize().width() AssertEQ(position.x(), width) AssertEQ(position.y(), 3)