当前位置: 首页>>代码示例>>Python>>正文


Python Buffer.cursor_down方法代码示例

本文整理汇总了Python中prompt_toolkit.buffer.Buffer.cursor_down方法的典型用法代码示例。如果您正苦于以下问题:Python Buffer.cursor_down方法的具体用法?Python Buffer.cursor_down怎么用?Python Buffer.cursor_down使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在prompt_toolkit.buffer.Buffer的用法示例。


在下文中一共展示了Buffer.cursor_down方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: BufferTest

# 需要导入模块: from prompt_toolkit.buffer import Buffer [as 别名]
# 或者: from prompt_toolkit.buffer.Buffer import cursor_down [as 别名]
class BufferTest(unittest.TestCase):
    def setUp(self):
        self.buffer = Buffer()

    def test_initial(self):
        self.assertEqual(self.buffer.text, '')
        self.assertEqual(self.buffer.cursor_position, 0)

    def test_insert_text(self):
        self.buffer.insert_text('some_text')
        self.assertEqual(self.buffer.text, 'some_text')
        self.assertEqual(self.buffer.cursor_position, len('some_text'))

    def test_cursor_movement(self):
        self.buffer.insert_text('some_text')
        self.buffer.cursor_left()
        self.buffer.cursor_left()
        self.buffer.cursor_left()
        self.buffer.cursor_right()
        self.buffer.insert_text('A')

        self.assertEqual(self.buffer.text, 'some_teAxt')
        self.assertEqual(self.buffer.cursor_position, len('some_teA'))

    def test_backspace(self):
        self.buffer.insert_text('some_text')
        self.buffer.cursor_left()
        self.buffer.cursor_left()
        self.buffer.delete_before_cursor()

        self.assertEqual(self.buffer.text, 'some_txt')
        self.assertEqual(self.buffer.cursor_position, len('some_t'))

    def test_cursor_up(self):
        # Cursor up to a line thats longer.
        self.buffer.insert_text('long line1\nline2')
        self.buffer.cursor_up()

        self.assertEqual(self.buffer.document.cursor_position, 5)

        # Going up when already at the top.
        self.buffer.cursor_up()
        self.assertEqual(self.buffer.document.cursor_position, 5)

        # Going up to a line that's shorter.
        self.buffer.reset()
        self.buffer.insert_text('line1\nlong line2')

        self.buffer.cursor_up()
        self.assertEqual(self.buffer.document.cursor_position, 5)

    def test_cursor_down(self):
        self.buffer.insert_text('line1\nline2')
        self.buffer.cursor_position = 3

        # Normally going down
        self.buffer.cursor_down()
        self.assertEqual(self.buffer.document.cursor_position, len('line1\nlin'))

        # Going down to a line that's storter.
        self.buffer.reset()
        self.buffer.insert_text('long line1\na\nb')
        self.buffer.cursor_position = 3

        self.buffer.cursor_down()
        self.assertEqual(self.buffer.document.cursor_position, len('long line1\na'))

    def test_join_next_line(self):
        self.buffer.insert_text('line1\nline2\nline3')
        self.buffer.cursor_up()
        self.buffer.join_next_line()

        self.assertEqual(self.buffer.text, 'line1\nline2 line3')

        # Test when there is no '\n' in the text
        self.buffer.reset()
        self.buffer.insert_text('line1')
        self.buffer.cursor_position = 0
        self.buffer.join_next_line()

        self.assertEqual(self.buffer.text, 'line1')

    def test_newline(self):
        self.buffer.insert_text('hello world')
        self.buffer.newline()

        self.assertEqual(self.buffer.text, 'hello world\n')

    def test_swap_characters_before_cursor(self):
        self.buffer.insert_text('hello world')
        self.buffer.cursor_left()
        self.buffer.cursor_left()
        self.buffer.swap_characters_before_cursor()

        self.assertEqual(self.buffer.text, 'hello wrold')
开发者ID:abspoel,项目名称:python-prompt-toolkit,代码行数:97,代码来源:__init__.py


注:本文中的prompt_toolkit.buffer.Buffer.cursor_down方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。