pastetoggle_spec.lua 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local clear = helpers.clear
  3. local feed = helpers.feed
  4. local command = helpers.command
  5. local eq = helpers.eq
  6. local expect = helpers.expect
  7. local eval = helpers.eval
  8. local insert = helpers.insert
  9. local meths = helpers.meths
  10. local sleep = helpers.sleep
  11. describe("'pastetoggle' option", function()
  12. before_each(clear)
  13. it("toggles 'paste'", function()
  14. command('set pastetoggle=a')
  15. eq(0, eval('&paste'))
  16. feed('a')
  17. -- Need another key so that the vgetorpeek() function returns.
  18. feed('j')
  19. eq(1, eval('&paste'))
  20. end)
  21. describe("multiple key 'pastetoggle'", function()
  22. before_each(function()
  23. eq(0, eval('&paste'))
  24. command('set timeoutlen=1 ttimeoutlen=10000')
  25. end)
  26. it('is waited for when chars are typed', function()
  27. local pastetoggle = 'lllll'
  28. command('set pastetoggle=' .. pastetoggle)
  29. feed(pastetoggle:sub(0, 2))
  30. -- sleep() for long enough that vgetorpeek() is gotten into, but short
  31. -- enough that ttimeoutlen is not reached.
  32. sleep(200)
  33. feed(pastetoggle:sub(3, -1))
  34. -- Need another key so that the vgetorpeek() function returns.
  35. feed('j')
  36. eq(1, eval('&paste'))
  37. end)
  38. it('is not waited for when there are no typed chars after mapped chars', function()
  39. command('set pastetoggle=abc')
  40. command('imap d a')
  41. meths.feedkeys('id', 't', true)
  42. -- sleep() for long enough that vgetorpeek() is gotten into, but short
  43. -- enough that ttimeoutlen is not reached.
  44. sleep(200)
  45. feed('bc')
  46. -- Need another key so that the vgetorpeek() function returns.
  47. feed('j')
  48. -- 'ttimeoutlen' should NOT apply
  49. eq(0, eval('&paste'))
  50. end)
  51. it('is waited for when there are typed chars after mapped chars', function()
  52. command('set pastetoggle=abc')
  53. command('imap d a')
  54. meths.feedkeys('idb', 't', true)
  55. -- sleep() for long enough that vgetorpeek() is gotten into, but short
  56. -- enough that ttimeoutlen is not reached.
  57. sleep(200)
  58. feed('c')
  59. -- Need another key so that the vgetorpeek() function returns.
  60. feed('j')
  61. -- 'ttimeoutlen' should apply
  62. eq(1, eval('&paste'))
  63. end)
  64. it('is waited for when there are typed chars after noremapped chars', function()
  65. command('set pastetoggle=abc')
  66. command('inoremap d a')
  67. meths.feedkeys('idb', 't', true)
  68. -- sleep() for long enough that vgetorpeek() is gotten into, but short
  69. -- enough that ttimeoutlen is not reached.
  70. sleep(200)
  71. feed('c')
  72. -- Need another key so that the vgetorpeek() function returns.
  73. feed('j')
  74. -- 'ttimeoutlen' should apply
  75. eq(1, eval('&paste'))
  76. end)
  77. end)
  78. it('does not interfere with character-find', function()
  79. insert('foo,bar')
  80. feed('0')
  81. command('set pastetoggle=,sp')
  82. feed('dt,')
  83. expect(',bar')
  84. end)
  85. end)