example_spec.lua 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. -- To run this test:
  2. -- TEST_FILE=test/functional/example_spec.lua make functionaltest
  3. local t = require('test.testutil')
  4. local n = require('test.functional.testnvim')()
  5. local Screen = require('test.functional.ui.screen')
  6. local clear = n.clear
  7. local command = n.command
  8. local eq = t.eq
  9. local feed = n.feed
  10. describe('example', function()
  11. local screen
  12. before_each(function()
  13. clear()
  14. screen = Screen.new(20, 5)
  15. screen:set_default_attr_ids({
  16. [0] = { bold = true, foreground = Screen.colors.Blue },
  17. [1] = { bold = true, foreground = Screen.colors.Brown },
  18. })
  19. end)
  20. it('screen test', function()
  21. -- Do some stuff.
  22. feed('iline1<cr>line2<esc>')
  23. -- For debugging only: prints the current screen.
  24. -- screen:snapshot_util()
  25. -- Assert the expected state.
  26. screen:expect([[
  27. line1 |
  28. line^2 |
  29. {0:~ }|
  30. {0:~ }|
  31. |
  32. ]])
  33. end)
  34. it('override UI event-handler', function()
  35. -- Example: override the "tabline_update" UI event handler.
  36. --
  37. -- screen.lua defines default handlers for UI events, but tests
  38. -- may sometimes want to override a handler.
  39. -- The UI must declare that it wants to handle the UI events.
  40. -- For this example, we enable `ext_tabline`:
  41. screen:detach()
  42. screen = Screen.new(25, 5, { rgb = true, ext_tabline = true })
  43. -- From ":help ui" we find that `tabline_update` receives `curtab` and
  44. -- `tabs` objects. So we declare the UI handler like this:
  45. local event_tabs, event_curtab
  46. function screen:_handle_tabline_update(curtab, tabs)
  47. event_curtab, event_tabs = curtab, tabs
  48. end
  49. -- Create a tabpage...
  50. command('tabedit foo')
  51. -- Use screen:expect{condition=…} to check the result.
  52. screen:expect {
  53. condition = function()
  54. eq(2, event_curtab)
  55. eq({
  56. { tab = 1, name = '[No Name]' },
  57. { tab = 2, name = 'foo' },
  58. }, event_tabs)
  59. end,
  60. }
  61. end)
  62. end)