tui.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/env python
  2. # License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
  3. from . import BaseTest
  4. class TestTUI(BaseTest):
  5. def test_line_edit(self):
  6. from kittens.tui.line_edit import LineEdit
  7. le = LineEdit()
  8. le.on_text('abcd', False)
  9. self.ae(le.cursor_pos, 4)
  10. for i in range(5):
  11. self.assertTrue(le.left()) if i < 4 else self.assertFalse(le.left())
  12. self.ae(le.cursor_pos, max(0, 3 - i))
  13. self.ae(le.pending_bell, True)
  14. le.clear()
  15. le.on_text('abcd', False), le.home()
  16. self.ae(le.cursor_pos, 0)
  17. for i in range(5):
  18. self.assertTrue(le.right()) if i < 4 else self.assertFalse(le.right())
  19. self.ae(le.cursor_pos, min(4, i + 1))
  20. self.ae(le.pending_bell, True)
  21. le.clear()
  22. le.on_text('abcd', False)
  23. self.ae(le.current_input, 'abcd')
  24. self.ae(le.cursor_pos, 4)
  25. self.ae(le.split_at_cursor(), ('abcd', ''))
  26. le.backspace()
  27. self.ae(le.current_input, 'abc')
  28. self.ae(le.cursor_pos, 3)
  29. self.assertFalse(le.pending_bell)
  30. le.backspace(num=2)
  31. self.ae(le.current_input, 'a')
  32. self.ae(le.cursor_pos, 1)
  33. self.assertFalse(le.pending_bell)
  34. le.backspace(num=2)
  35. self.ae(le.current_input, '')
  36. self.ae(le.cursor_pos, 0)
  37. le.backspace()
  38. self.assertTrue(le.pending_bell)
  39. def test_multiprocessing_spawn(self):
  40. from kitty.multiprocessing import test_spawn
  41. test_spawn()