chars_spec.lua 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local Screen = require('test.functional.ui.screen')
  4. local clear, command = n.clear, n.command
  5. local pcall_err = t.pcall_err
  6. local eval = n.eval
  7. local eq = t.eq
  8. local insert = n.insert
  9. local feed = n.feed
  10. local api = n.api
  11. describe("'fillchars'", function()
  12. local screen
  13. before_each(function()
  14. clear()
  15. screen = Screen.new(25, 5)
  16. end)
  17. describe('"eob" flag', function()
  18. it("uses '~' by default", function()
  19. eq('', eval('&fillchars'))
  20. screen:expect([[
  21. ^ |
  22. {1:~ }|*3
  23. |
  24. ]])
  25. end)
  26. it('supports whitespace', function()
  27. screen:expect([[
  28. ^ |
  29. {1:~ }|*3
  30. |
  31. ]])
  32. command('set fillchars=eob:\\ ')
  33. screen:expect([[
  34. ^ |
  35. {1: }|*3
  36. |
  37. ]])
  38. end)
  39. it('supports multibyte char', function()
  40. command('set fillchars=eob:ñ')
  41. screen:expect([[
  42. ^ |
  43. {1:ñ }|*3
  44. |
  45. ]])
  46. end)
  47. it('supports composing multibyte char', function()
  48. command('set fillchars=eob:å̲')
  49. screen:expect([[
  50. ^ |
  51. {1:å̲ }|*3
  52. |
  53. ]])
  54. end)
  55. it('handles invalid values', function()
  56. eq(
  57. 'Vim(set):E1511: Wrong number of characters for field "eob": fillchars=eob:',
  58. pcall_err(command, 'set fillchars=eob:') -- empty string
  59. )
  60. eq(
  61. 'Vim(set):E1512: Wrong character width for field "eob": fillchars=eob:馬',
  62. pcall_err(command, 'set fillchars=eob:馬') -- doublewidth char
  63. )
  64. eq(
  65. 'Vim(set):E1511: Wrong number of characters for field "eob": fillchars=eob:xy',
  66. pcall_err(command, 'set fillchars=eob:xy') -- two ascii chars
  67. )
  68. eq(
  69. 'Vim(set):E1512: Wrong character width for field "eob": fillchars=eob:<ff>',
  70. pcall_err(command, 'set fillchars=eob:\255') -- invalid UTF-8
  71. )
  72. end)
  73. end)
  74. it('"diff" flag', function()
  75. screen:try_resize(45, 8)
  76. screen:set_default_attr_ids({
  77. [1] = { background = Screen.colors.Grey, foreground = Screen.colors.DarkBlue },
  78. [2] = { background = Screen.colors.LightCyan1, bold = true, foreground = Screen.colors.Blue1 },
  79. [3] = { background = Screen.colors.LightBlue },
  80. [4] = { reverse = true },
  81. [5] = { reverse = true, bold = true },
  82. })
  83. command('set fillchars=diff:…')
  84. insert('a\nb\nc\nd\ne')
  85. command('vnew')
  86. insert('a\nd\ne\nf')
  87. command('windo diffthis')
  88. screen:expect([[
  89. {1: }a │{1: }a |
  90. {1: }{2:……………………………………………………}│{1: }{3:b }|
  91. {1: }{2:……………………………………………………}│{1: }{3:c }|
  92. {1: }d │{1: }d |
  93. {1: }e │{1: }^e |
  94. {1: }{3:f }│{1: }{2:……………………………………………………}|
  95. {4:[No Name] [+] }{5:[No Name] [+] }|
  96. |
  97. ]])
  98. end)
  99. it('has global value', function()
  100. screen:try_resize(50, 5)
  101. insert('foo\nbar')
  102. command('set laststatus=0')
  103. command('1,2fold')
  104. command('vsplit')
  105. command('set fillchars=fold:x')
  106. screen:expect([[
  107. {13:^+-- 2 lines: fooxxxxxxxx}│{13:+-- 2 lines: fooxxxxxxx}|
  108. {1:~ }│{1:~ }|*3
  109. |
  110. ]])
  111. end)
  112. it('has window-local value', function()
  113. screen:try_resize(50, 5)
  114. insert('foo\nbar')
  115. command('set laststatus=0')
  116. command('1,2fold')
  117. command('vsplit')
  118. command('setl fillchars=fold:x')
  119. screen:expect([[
  120. {13:^+-- 2 lines: fooxxxxxxxx}│{13:+-- 2 lines: foo·······}|
  121. {1:~ }│{1:~ }|*3
  122. |
  123. ]])
  124. end)
  125. it('using :set clears window-local value', function()
  126. screen:try_resize(50, 5)
  127. insert('foo\nbar')
  128. command('set laststatus=0')
  129. command('setl fillchars=fold:x')
  130. command('1,2fold')
  131. command('vsplit')
  132. command('set fillchars&')
  133. screen:expect([[
  134. {13:^+-- 2 lines: foo········}│{13:+-- 2 lines: fooxxxxxxx}|
  135. {1:~ }│{1:~ }|*3
  136. |
  137. ]])
  138. end)
  139. end)
  140. describe("'listchars'", function()
  141. local screen
  142. before_each(function()
  143. clear()
  144. screen = Screen.new(50, 5)
  145. end)
  146. it('has global value', function()
  147. feed('i<tab><tab><tab><esc>')
  148. command('set list laststatus=0')
  149. command('vsplit')
  150. command('set listchars=tab:<->')
  151. screen:expect([[
  152. {1:<------><------>^<------>} │{1:<------><------><------>}|
  153. {1:~ }│{1:~ }|*3
  154. |
  155. ]])
  156. end)
  157. it('has window-local value', function()
  158. feed('i<tab><tab><tab><esc>')
  159. command('set list laststatus=0')
  160. command('setl listchars=tab:<->')
  161. command('vsplit')
  162. command('setl listchars<')
  163. screen:expect([[
  164. {1:> > ^> } │{1:<------><------><------>}|
  165. {1:~ }│{1:~ }|*3
  166. |
  167. ]])
  168. end)
  169. it('using :set clears window-local value', function()
  170. feed('i<tab><tab><tab><esc>')
  171. command('set list laststatus=0')
  172. command('setl listchars=tab:<->')
  173. command('vsplit')
  174. command('set listchars=tab:>-,eol:$')
  175. screen:expect([[
  176. {1:>------->-------^>-------$}│{1:<------><------><------>}|
  177. {1:~ }│{1:~ }|*3
  178. |
  179. ]])
  180. end)
  181. it('supports composing chars', function()
  182. screen:set_default_attr_ids {
  183. [1] = { foreground = Screen.colors.Blue1, bold = true },
  184. }
  185. feed('i<tab><tab><tab>x<esc>')
  186. command('set list laststatus=0')
  187. -- tricky: the tab value forms three separate one-cell chars,
  188. -- thus it should be accepted despite being a mess.
  189. command('set listchars=tab:d̞̄̃̒̉̎ò́̌̌̂̐l̞̀̄̆̌̚,eol:å̲')
  190. screen:expect([[
  191. {1:d̞̄̃̒̉̎ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐l̞̀̄̆̌̚d̞̄̃̒̉̎ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐l̞̀̄̆̌̚d̞̄̃̒̉̎ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐l̞̀̄̆̌̚}^x{1:å̲} |
  192. {1:~ }|*3
  193. |
  194. ]])
  195. api.nvim__invalidate_glyph_cache()
  196. screen:_reset()
  197. screen:expect([[
  198. {1:d̞̄̃̒̉̎ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐l̞̀̄̆̌̚d̞̄̃̒̉̎ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐l̞̀̄̆̌̚d̞̄̃̒̉̎ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐l̞̀̄̆̌̚}^x{1:å̲} |
  199. {1:~ }|*3
  200. |
  201. ]])
  202. end)
  203. end)