def test_DECBI_Scrolls(self): strings = [ "abcde", "fghij", "klmno", "pqrst", "uvwxy" ] y = 3 for s in strings: esccmd.CUP(Point(2, y)) escio.Write(s) y += 1 esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(3, 5) esccmd.DECSTBM(4, 6) esccmd.CUP(Point(3, 5)) esccmd.DECBI() AssertScreenCharsInRectEqual(Rect(2, 3, 6, 7), [ "abcde", "f" + blank() + "ghj", "k" + blank() + "lmo", "p" + blank() + "qrt", "uvwxy" ])
def test_ICH_ExplicitParam(self): """Test ICH with explicit parameter. """ esccmd.CUP(Point(1, 1)) AssertEQ(GetCursorPosition().x(), 1) escio.Write("abcdefg") esccmd.CUP(Point(2, 1)) AssertEQ(GetCursorPosition().x(), 2) esccmd.ICH(2) AssertScreenCharsInRectEqual(Rect(1, 1, 9, 1), [ "a" + blank() + blank() + "bcdefg"])
def test_ICH_ExplicitParam(self): """Test ICH with explicit parameter. """ esccmd.CUP(Point(1, 1)) AssertEQ(GetCursorPosition().x(), 1) escio.Write("abcdefg") esccmd.CUP(Point(2, 1)) AssertEQ(GetCursorPosition().x(), 2) esccmd.ICH(2) AssertScreenCharsInRectEqual(Rect(1, 1, 9, 1), ["a" + blank() + blank() + "bcdefg"])
def test_DECIC_DefaultParam(self): """ Test DECIC with default parameter """ esccmd.CUP(Point(1, 1)) AssertEQ(GetCursorPosition().x(), 1) escio.Write("abcdefg" + CR + LF + "ABCDEFG") esccmd.CUP(Point(2, 1)) AssertEQ(GetCursorPosition().x(), 2) esccmd.DECIC() AssertScreenCharsInRectEqual(Rect( 1, 1, 8, 2), ["a" + blank() + "bcdefg", "A" + blank() + "BCDEFG"])
def test_DECIC_DefaultParam(self): """ Test DECIC with default parameter """ esccmd.CUP(Point(1, 1)) AssertEQ(GetCursorPosition().x(), 1) escio.Write("abcdefg" + CR + LF + "ABCDEFG") esccmd.CUP(Point(2, 1)) AssertEQ(GetCursorPosition().x(), 2) esccmd.DECIC() AssertScreenCharsInRectEqual(Rect(1, 1, 8, 2), [ "a" + blank() + "bcdefg", "A" + blank() + "BCDEFG" ])
def test_DECIC_ExplicitParam(self): """Test DECIC with explicit parameter. Also verifies lines above and below the cursor are affected.""" esccmd.CUP(Point(1, 1)) AssertEQ(GetCursorPosition().x(), 1) escio.Write("abcdefg" + CR + LF + "ABCDEFG" + CR + LF + "zyxwvut") esccmd.CUP(Point(2, 2)) AssertEQ(GetCursorPosition().x(), 2) esccmd.DECIC(2) AssertScreenCharsInRectEqual(Rect(1, 1, 9, 3), [ "a" + blank() * 2 + "bcdefg", "A" + blank() * 2 + "BCDEFG", "z" + blank() * 2 + "yxwvut" ])
def test_DECSED_1_WithScrollRegion_Protection(self): """Erase after cursor with a scroll region present. The scroll region is ignored.""" esccmd.DECSCA(1) self.prepare_wide() # Write an X at 1,1 without protection esccmd.DECSCA(0) esccmd.CUP(Point(1, 1)) escio.Write("X") # Set margins esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(2, 4) esccmd.DECSTBM(2, 3) # Position cursor and do DECSED 1 esccmd.CUP(Point(3, 2)) esccmd.DECSED(1) # Remove margins esccmd.DECRESET(esccmd.DECLRMM) esccmd.DECSTBM() AssertScreenCharsInRectEqual(Rect(1, 1, 5, 3), [blank() + "bcde", "fghij", "klmno"])
def test_DECIC_ScrollEntirelyOffRightEdge(self): """Test DECIC behavior when pushing text off the right edge. """ width = GetScreenSize().width() esccmd.CUP(Point(1, 1)) escio.Write("x" * width) esccmd.CUP(Point(1, 2)) escio.Write("x" * width) esccmd.CUP(Point(1, 1)) esccmd.DECIC(width) expectedLine = blank() * width AssertScreenCharsInRectEqual(Rect(1, 1, width, 2), [expectedLine, expectedLine]) # Ensure there is no wrap-around. AssertScreenCharsInRectEqual(Rect(1, 2, 1, 3), [blank(), blank()])
def test_DECSERA_doesNotRespectISOProtect(self): """DECSERA does not respect ISO protection.""" escio.Write("a") esccmd.SPA() escio.Write("b") esccmd.EPA() esccmd.DECSERA(1, 1, 1, 2) AssertScreenCharsInRectEqual(Rect(1, 1, 2, 1), [ esc.blank() * 2 ])
def test_DECSEL_doesNotRespectISOProtect(self): """DECSEL does not respect ISO protection.""" escio.Write("a") esccmd.SPA() escio.Write("b") esccmd.EPA() esccmd.DECSEL(2) AssertScreenCharsInRectEqual(Rect(1, 1, 2, 1), [blank() * 2])
def test_DECIC_ScrollOffRightEdge(self): """Test DECIC behavior when pushing text off the right edge. """ 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.DECIC() AssertScreenCharsInRectEqual( Rect(startX, 1, width, 2), ["a" + blank() + "bcdef", "A" + blank() + "BCDEF"]) # Ensure there is no wrap-around. AssertScreenCharsInRectEqual(Rect(1, 2, 1, 3), [NUL, NUL])
def test_DECIC_ScrollEntirelyOffRightEdge(self): """Test DECIC behavior when pushing text off the right edge. """ width = GetScreenSize().width() esccmd.CUP(Point(1, 1)) escio.Write("x" * width) esccmd.CUP(Point(1, 2)) escio.Write("x" * width) esccmd.CUP(Point(1, 1)) esccmd.DECIC(width) expectedLine = blank() * width AssertScreenCharsInRectEqual(Rect(1, 1, width, 2), [ expectedLine, expectedLine ]) # Ensure there is no wrap-around. AssertScreenCharsInRectEqual(Rect(1, 2, 1, 3), [ blank(), blank() ])
def test_DECIC_ScrollOffRightEdge(self): """Test DECIC behavior when pushing text off the right edge. """ 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.DECIC() AssertScreenCharsInRectEqual(Rect(startX, 1, width, 2), [ "a" + blank() + "bcdef", "A" + blank() + "BCDEF" ]) # Ensure there is no wrap-around. AssertScreenCharsInRectEqual(Rect(1, 2, 1, 3), [ NUL, NUL ])
def test_ED_1(self): """Erase before cursor.""" self.prepare() esccmd.ED(1) AssertScreenCharsInRectEqual( Rect(1, 1, 3, 5), [NUL * 3, NUL * 3, blank() * 2 + "d", NUL * 3, "e" + NUL * 2])
def test_DECBI_WholeScreenScrolls(self): """The spec is confusing and contradictory. It first says "If the cursor is at the left margin, then all screen data within the margin moves one column to the right" and then says "DECBI is not affected by the margins." I don't know what they could mean by the second part.""" escio.Write("x") esccmd.CUP(Point(1, 1)) esccmd.DECBI() AssertScreenCharsInRectEqual(Rect(1, 1, 2, 1), [ blank() + "x" ])
def test_ECH_doesNotRespectDECPRotection(self): """ECH should not respect DECSCA.""" escio.Write("a") escio.Write("b") esccmd.DECSCA(1) escio.Write("c") esccmd.DECSCA(0) esccmd.CUP(Point(1, 1)) esccmd.ECH(3) AssertScreenCharsInRectEqual(Rect(1, 1, 3, 1), [blank() * 3])
def test_ECH_OutsideScrollRegion(self): """ECH ignores the scroll region when the cursor is outside it""" escio.Write("abcdefg") esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(2, 4) esccmd.CUP(Point(1, 1)) esccmd.ECH(4) esccmd.DECRESET(esccmd.DECLRMM) AssertScreenCharsInRectEqual(Rect(1, 1, 7, 1), [blank() * 4 + "efg"])
def test_ED_1(self): """Erase before cursor.""" self.prepare() esccmd.ED(1) AssertScreenCharsInRectEqual(Rect(1, 1, 3, 5), [ NUL * 3, NUL * 3, blank() * 2 + "d", NUL * 3, "e" + NUL * 2 ])
def test_EL_respectsISOProtection(self): """EL respects SPA/EPA.""" escio.Write("a") escio.Write("b") esccmd.SPA() escio.Write("c") esccmd.EPA() esccmd.CUP(Point(1, 1)) esccmd.EL(2) AssertScreenCharsInRectEqual(Rect(1, 1, 3, 1), [blank() * 2 + "c"])
def test_DECSED_1(self): """Erase before cursor.""" self.prepare() esccmd.DECSED(1) AssertScreenCharsInRectEqual(Rect(1, 1, 3, 5), [ empty() * 3, empty() * 3, blank() * 2 + "d", empty() * 3, "e" + empty() * 2 ])
def characters(self, point, count): if self._always_return_blank: return esc.blank() * count s = "" data = self.data() for i in xrange(count): p = Point(point.x() + i, point.y()) if p.y() >= len(data): s += esc.blank() continue line = data[p.y() - 1] if p.x() >= len(line): s += esc.blank() continue if point.y() % 2 == 1: s += line[p.x() - 1] else: s += esc.blank() return s
def test_ECH_OutsideScrollRegion(self): """ECH ignores the scroll region when the cursor is outside it""" escio.Write("abcdefg") esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(2, 4) esccmd.CUP(Point(1, 1)) esccmd.ECH(4) esccmd.DECRESET(esccmd.DECLRMM) AssertScreenCharsInRectEqual(Rect(1, 1, 7, 1), [ blank() * 4 + "efg" ]);
def test_EL_respectsISOProtection(self): """EL respects SPA/EPA.""" escio.Write("a") escio.Write("b") esccmd.SPA() escio.Write("c") esccmd.EPA() esccmd.CUP(Point(1, 1)) esccmd.EL(2) AssertScreenCharsInRectEqual(Rect(1, 1, 3, 1), [ blank() * 2 + "c" ])
def test_ECH_doesNotRespectDECPRotection(self): """ECH should not respect DECSCA.""" escio.Write("a") escio.Write("b") esccmd.DECSCA(1) escio.Write("c") esccmd.DECSCA(0) esccmd.CUP(Point(1, 1)) esccmd.ECH(3) AssertScreenCharsInRectEqual(Rect(1, 1, 3, 1), [ blank() * 3 ])
def test_DECBI_WholeScreenScrolls(self): """Test DECBI (back-index) when the cursor is before the left-margin, but at the left edge of the screen. Refer to DEC STD 070, which says if the cursor is outside the margins, at the left edge of the page (which xterm equates with its screen), the command is ignored.""" escio.Write("x") esccmd.CUP(Point(1, 1)) esccmd.DECBI() AssertScreenCharsInRectEqual(Rect(1, 1, 2, 1), [blank() + "x"])
def test_DECIC_CursorWithinTopBottom(self): """DECIC should only affect rows inside region.""" esccmd.DECSTBM() esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(1, 20) # Write four lines. The middle two will be in the scroll region. esccmd.CUP(Point(1, 1)) escio.Write("abcdefg" + CR + LF + "ABCDEFG" + CR + LF + "zyxwvut" + CR + LF + "ZYXWVUT") # Define a scroll region. Place the cursor in it. Insert a column. esccmd.DECSTBM(2, 3) esccmd.CUP(Point(2, 2)) esccmd.DECIC(2) # Remove scroll region and see if it worked. esccmd.DECSTBM() esccmd.DECRESET(esccmd.DECLRMM) AssertScreenCharsInRectEqual(Rect(1, 1, 9, 4), [ "abcdefg" + NUL * 2, "A" + blank() * 2 + "BCDEFG", "z" + blank() * 2 + "yxwvut", "ZYXWVUT" + NUL * 2 ])
def test_ED_1_WithScrollRegion(self): """Erase before cursor with a scroll region present. The scroll region is ignored.""" self.prepare_wide() esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(2, 4) esccmd.DECSTBM(2, 3) esccmd.CUP(Point(3, 2)) esccmd.ED(1) esccmd.DECRESET(esccmd.DECLRMM) esccmd.DECSTBM() AssertScreenCharsInRectEqual(Rect( 1, 1, 5, 3), [NUL * 5, blank() * 3 + "ij", "klmno"])
def test_DECSEL_2_Protection(self): """All letters are protected so nothing should happen.""" esccmd.DECSCA(1) self.prepare() # Write an X at 1,1 without protection esccmd.DECSCA(0) esccmd.CUP(Point(1, 1)) escio.Write("X") esccmd.DECSEL(2) AssertScreenCharsInRectEqual(Rect(1, 1, 10, 1), [ blank() + "bcdefghij" ])
def test_DECSEL_2_Protection(self): """All letters are protected so nothing should happen.""" esccmd.DECSCA(1) self.prepare() # Write an X at 1,1 without protection esccmd.DECSCA(0) esccmd.CUP(Point(1, 1)) escio.Write("X") esccmd.DECSEL(2) AssertScreenCharsInRectEqual(Rect(1, 1, 10, 1), [blank() + "bcdefghij"])
def test_DECIC_ScrollOffRightMarginInScrollRegion(self): """Test DECIC when cursor is within the scroll region.""" esccmd.CUP(Point(1, 1)) s = "abcdefg" escio.Write(s) esccmd.CUP(Point(1, 2)) escio.Write(s.upper()) # Set margin: from columns 2 to 5 esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(2, 5) # Position cursor inside margins esccmd.CUP(Point(3, 1)) # Insert blank esccmd.DECIC() # Ensure the 'e' gets dropped. esccmd.DECRESET(esccmd.DECLRMM) AssertScreenCharsInRectEqual( Rect(1, 1, len(s), 2), ["ab" + blank() + "cdfg", "AB" + blank() + "CDFG"])
def test_ED_1_WithScrollRegion(self): """Erase before cursor with a scroll region present. The scroll region is ignored.""" self.prepare_wide() esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(2, 4) esccmd.DECSTBM(2, 3) esccmd.CUP(Point(3, 2)) esccmd.ED(1) esccmd.DECRESET(esccmd.DECLRMM) esccmd.DECSTBM() AssertScreenCharsInRectEqual(Rect(1, 1, 5, 3), [ NUL * 5, blank() * 3 + "ij", "klmno" ])
def test_ICH_ScrollOffRightEdge(self): """Test ICH behavior when pushing text off the right edge. """ width = GetScreenSize().width() s = "abcdefg" startX = width - len(s) + 1 esccmd.CUP(Point(startX, 1)) escio.Write(s) esccmd.CUP(Point(startX + 1, 1)) esccmd.ICH() AssertScreenCharsInRectEqual(Rect(startX, 1, width, 1), ["a" + blank() + "bcdef"]) # Ensure there is no wrap-around. AssertScreenCharsInRectEqual(Rect(1, 2, 1, 2), [empty()])
def test_DECIC_ScrollOffRightMarginInScrollRegion(self): """Test DECIC when cursor is within the scroll region.""" esccmd.CUP(Point(1, 1)) s = "abcdefg" escio.Write(s) esccmd.CUP(Point(1, 2)) escio.Write(s.upper()) # Set margin: from columns 2 to 5 esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(2, 5) # Position cursor inside margins esccmd.CUP(Point(3, 1)) # Insert blank esccmd.DECIC() # Ensure the 'e' gets dropped. esccmd.DECRESET(esccmd.DECLRMM) AssertScreenCharsInRectEqual(Rect(1, 1, len(s), 2), [ "ab" + blank() + "cdfg", "AB" + blank() + "CDFG" ])
def test_S8C1T_SPA_EPA(self): """There is no test for SPA and EPA (it's in the erasure tests, like DECSED) so the test for 8 bit controls goes here.""" escio.use8BitControls = True escio.Write(S8C1T) escio.Write("a") escio.Write("b") esccmd.SPA() escio.Write("c") esccmd.EPA() escio.Write(S7C1T) escio.use8BitControls = False esccmd.CUP(Point(1, 1)) esccmd.ECH(3) AssertScreenCharsInRectEqual(Rect(1, 1, 3, 1), [blank() * 2 + "c"])
def test_S8C1T_SPA_EPA(self): """There is no test for SPA and EPA (it's in the erasure tests, like DECSED) so the test for 8 bit controls goes here.""" escio.use8BitControls = True escio.Write(S8C1T) escio.Write("a") escio.Write("b") esccmd.SPA() escio.Write("c") esccmd.EPA() escio.Write(S7C1T) escio.use8BitControls = False esccmd.CUP(Point(1, 1)) esccmd.ECH(3) AssertScreenCharsInRectEqual(Rect(1, 1, 3, 1), [ blank() * 2 + "c" ])
def test_DECSED_2_WithScrollRegion_Protection(self): """Erase whole screen with a scroll region present. The scroll region is ignored.""" esccmd.DECSCA(1) self.prepare_wide() # Write an X at 1,1 without protection esccmd.DECSCA(0) esccmd.CUP(Point(1, 1)) escio.Write("X") esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(2, 4) esccmd.DECSTBM(2, 3) esccmd.CUP(Point(3, 2)) esccmd.DECSED(2) esccmd.DECRESET(esccmd.DECLRMM) esccmd.DECSTBM() AssertScreenCharsInRectEqual(Rect(1, 1, 5, 3), [blank() + "bcde", "fghij", "klmno"])
def characters(self, point, count): return esc.blank() * count
def test_ECH_ExplicitParam(self): """Should erase N characters starting at the cursor.""" escio.Write("abc") esccmd.CUP(Point(1, 1)) esccmd.ECH(2) AssertScreenCharsInRectEqual(Rect(1, 1, 3, 1), [blank() * 2 + "c"])
def test_DECSEL_1(self): """Should erase to left of cursor.""" self.prepare() esccmd.DECSEL(1) AssertScreenCharsInRectEqual(Rect(1, 1, 10, 1), [5 * blank() + "fghij"])
def test_ECH_DefaultParam(self): """Should erase the character under the cursor.""" escio.Write("abc") esccmd.CUP(Point(1, 1)) esccmd.ECH() AssertScreenCharsInRectEqual(Rect(1, 1, 3, 1), [blank() + "bc"])
def test_ECH_ExplicitParam(self): """Should erase N characters starting at the cursor.""" escio.Write("abc") esccmd.CUP(Point(1, 1)) esccmd.ECH(2) AssertScreenCharsInRectEqual(Rect(1, 1, 3, 1), [ blank() * 2 + "c" ]);
def test_ECH_DefaultParam(self): """Should erase the character under the cursor.""" escio.Write("abc") esccmd.CUP(Point(1, 1)) esccmd.ECH() AssertScreenCharsInRectEqual(Rect(1, 1, 3, 1), [ blank() + "bc" ]);
def test_EL_1(self): """Should erase to left of cursor.""" self.prepare() esccmd.EL(1) AssertScreenCharsInRectEqual(Rect(1, 1, 10, 1), [ 5 * blank() + "fghij" ])