listchars_spec.lua 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. -- Tests for 'listchars' display with 'list' and :list.
  2. local helpers = require('test.functional.helpers')(after_each)
  3. local feed, insert, source = helpers.feed, helpers.insert, helpers.source
  4. local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect
  5. -- luacheck: ignore 621 (Indentation)
  6. describe("'listchars'", function()
  7. before_each(function()
  8. clear()
  9. feed_command('set listchars&vi')
  10. end)
  11. -- luacheck: ignore 613 (Trailing whitespace in a string)
  12. it("works with 'list'", function()
  13. source([[
  14. function GetScreenCharsForLine(lnum)
  15. return join(map(range(1, virtcol('$')), 'nr2char(screenchar(a:lnum, v:val))'), '')
  16. endfunction
  17. nnoremap <expr> GG ":call add(g:lines, GetScreenCharsForLine(".screenrow()."))\<CR>"
  18. ]])
  19. insert([[
  20. start:
  21. aa
  22. bb
  23. cccc
  24. dd ee
  25. ]])
  26. feed_command('let g:lines = []')
  27. -- Set up 'listchars', switch on 'list', and use the "GG" mapping to record
  28. -- what the buffer lines look like.
  29. feed_command('set listchars+=tab:>-,space:.,trail:<')
  30. feed_command('set list')
  31. feed_command('/^start:/')
  32. feed_command('normal! jzt')
  33. feed('GG<cr>')
  34. feed('GG<cr>')
  35. feed('GG<cr>')
  36. feed('GG<cr>')
  37. feed('GGH')
  38. -- Repeat without displaying "trail" spaces.
  39. feed_command('set listchars-=trail:<')
  40. feed('GG<cr>')
  41. feed('GG<cr>')
  42. feed('GG<cr>')
  43. feed('GG<cr>')
  44. feed('GG')
  45. -- Delete the buffer contents and :put the collected lines.
  46. feed_command('%d')
  47. feed_command('put =g:lines', '1d')
  48. -- Assert buffer contents.
  49. expect([[
  50. >-------aa>-----$
  51. ..bb>---<<$
  52. ...cccc><$
  53. dd........ee<<>-$
  54. <$
  55. >-------aa>-----$
  56. ..bb>---..$
  57. ...cccc>.$
  58. dd........ee..>-$
  59. .$]])
  60. end)
  61. it('works with :list', function()
  62. insert([[
  63. start:
  64. fff
  65. gg
  66. h
  67. iii ]])
  68. -- Set up 'listchars', switch 'list' *off* (:list must show the 'listchars'
  69. -- even when 'list' is off), then run :list and collect the output.
  70. feed_command('set listchars+=tab:>-,space:.,trail:<')
  71. feed_command('set nolist')
  72. feed_command('/^start:/')
  73. feed_command('redir! => g:lines')
  74. feed_command('+1,$list')
  75. feed_command('redir END')
  76. -- Delete the buffer contents and :put the collected lines.
  77. feed_command('%d')
  78. feed_command('put =g:lines', '1d')
  79. -- Assert buffer contents.
  80. expect([[
  81. ..fff>--<<$
  82. >-------gg>-----$
  83. .....h>-$
  84. iii<<<<><<$]])
  85. end)
  86. end)