    def test_ansi_terminal_parser_delete(self):
        """
        Check AnsiTerminalParser delete operations work as expected.
        """
        parser = AnsiTerminalParser()

        # Delete to end of line
        parser.reset("abcde\x08\x08\x08\x1B[K", None)
        tokens = parser.parse()
        self.assertEqual(next(tokens), (0, Parser.DISPLAY_TEXT, "a"))
        self.assertEqual(next(tokens), (1, Parser.DISPLAY_TEXT, "b"))
        self.assertEqual(next(tokens), (2, Parser.DISPLAY_TEXT, "c"))
        self.assertEqual(next(tokens), (3, Parser.DISPLAY_TEXT, "d"))
        self.assertEqual(next(tokens), (4, Parser.DISPLAY_TEXT, "e"))
        self.assertEqual(next(tokens), (5, Parser.MOVE_RELATIVE, (-1, 0)))
        self.assertEqual(next(tokens), (5, Parser.MOVE_RELATIVE, (-1, 0)))
        self.assertEqual(next(tokens), (5, Parser.MOVE_RELATIVE, (-1, 0)))
        self.assertEqual(next(tokens), (5, Parser.DELETE_LINE, 0))
        with self.assertRaises(StopIteration):
            next(tokens)

        # Delete to start of line
        parser.reset("abcde\x1B[1K", None)
        tokens = parser.parse()
        self.assertEqual(next(tokens), (0, Parser.DISPLAY_TEXT, "a"))
        self.assertEqual(next(tokens), (1, Parser.DISPLAY_TEXT, "b"))
        self.assertEqual(next(tokens), (2, Parser.DISPLAY_TEXT, "c"))
        self.assertEqual(next(tokens), (3, Parser.DISPLAY_TEXT, "d"))
        self.assertEqual(next(tokens), (4, Parser.DISPLAY_TEXT, "e"))
        self.assertEqual(next(tokens), (5, Parser.DELETE_LINE, 1))
        with self.assertRaises(StopIteration):
            next(tokens)

        # Delete line
        parser.reset("abcde\x1B[2K", None)
        tokens = parser.parse()
        self.assertEqual(next(tokens), (0, Parser.DISPLAY_TEXT, "a"))
        self.assertEqual(next(tokens), (1, Parser.DISPLAY_TEXT, "b"))
        self.assertEqual(next(tokens), (2, Parser.DISPLAY_TEXT, "c"))
        self.assertEqual(next(tokens), (3, Parser.DISPLAY_TEXT, "d"))
        self.assertEqual(next(tokens), (4, Parser.DISPLAY_TEXT, "e"))
        self.assertEqual(next(tokens), (5, Parser.DELETE_LINE, 2))
        with self.assertRaises(StopIteration):
            next(tokens)

        # Delete char
        parser.reset("abcde\x08\x08\x08\x1B[P", None)
        tokens = parser.parse()
        self.assertEqual(next(tokens), (0, Parser.DISPLAY_TEXT, "a"))
        self.assertEqual(next(tokens), (1, Parser.DISPLAY_TEXT, "b"))
        self.assertEqual(next(tokens), (2, Parser.DISPLAY_TEXT, "c"))
        self.assertEqual(next(tokens), (3, Parser.DISPLAY_TEXT, "d"))
        self.assertEqual(next(tokens), (4, Parser.DISPLAY_TEXT, "e"))
        self.assertEqual(next(tokens), (5, Parser.MOVE_RELATIVE, (-1, 0)))
        self.assertEqual(next(tokens), (5, Parser.MOVE_RELATIVE, (-1, 0)))
        self.assertEqual(next(tokens), (5, Parser.MOVE_RELATIVE, (-1, 0)))
        self.assertEqual(next(tokens), (5, Parser.DELETE_CHARS, 1))
        with self.assertRaises(StopIteration):
            next(tokens)
Check AnsiTerminalParser delete operations work as expected.
tests/test_parsers.py