本文整理汇总了Python中prompt_toolkit.buffer.Buffer.delete_before_cursor方法的典型用法代码示例。如果您正苦于以下问题:Python Buffer.delete_before_cursor方法的具体用法?Python Buffer.delete_before_cursor怎么用?Python Buffer.delete_before_cursor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prompt_toolkit.buffer.Buffer
的用法示例。
在下文中一共展示了Buffer.delete_before_cursor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BufferTest
# 需要导入模块: from prompt_toolkit.buffer import Buffer [as 别名]
# 或者: from prompt_toolkit.buffer.Buffer import delete_before_cursor [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')