multibyte_spec.lua 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local Screen = require('test.functional.ui.screen')
  3. local clear = helpers.clear
  4. local command = helpers.command
  5. local feed = helpers.feed
  6. local feed_command = helpers.feed_command
  7. local insert = helpers.insert
  8. local funcs = helpers.funcs
  9. describe("multibyte rendering", function()
  10. local screen
  11. before_each(function()
  12. clear()
  13. screen = Screen.new(60, 6)
  14. screen:attach({rgb=true})
  15. screen:set_default_attr_ids({
  16. [1] = {bold = true, foreground = Screen.colors.Blue1},
  17. [2] = {background = Screen.colors.WebGray},
  18. [3] = {background = Screen.colors.LightMagenta},
  19. [4] = {bold = true},
  20. })
  21. end)
  22. it("works with composed char at start of line", function()
  23. insert([[
  24. ̊
  25. x]])
  26. feed("gg")
  27. -- verify the modifier infact is alone
  28. feed_command("ascii")
  29. screen:expect([[
  30. ^ ̊ |
  31. x |
  32. {1:~ }|
  33. {1:~ }|
  34. {1:~ }|
  35. < ̊> 778, Hex 030a, Octal 1412 |
  36. ]])
  37. -- a char inserted before will spontaneously merge with it
  38. feed("ia<esc>")
  39. feed_command("ascii")
  40. screen:expect([[
  41. ^å |
  42. x |
  43. {1:~ }|
  44. {1:~ }|
  45. {1:~ }|
  46. <a> 97, Hex 61, Octal 141 < ̊> 778, Hex 030a, Octal 1412 |
  47. ]])
  48. end)
  49. it('works with doublewidth char at end of line', function()
  50. feed('58a <esc>a馬<esc>')
  51. screen:expect([[
  52. ^馬|
  53. {1:~ }|
  54. {1:~ }|
  55. {1:~ }|
  56. {1:~ }|
  57. |
  58. ]])
  59. feed('i <esc>')
  60. screen:expect([[
  61. ^ {1:>}|
  62. 馬 |
  63. {1:~ }|
  64. {1:~ }|
  65. {1:~ }|
  66. |
  67. ]])
  68. feed('l')
  69. screen:expect([[
  70. {1:>}|
  71. ^馬 |
  72. {1:~ }|
  73. {1:~ }|
  74. {1:~ }|
  75. |
  76. ]])
  77. end)
  78. it('clears left half of double-width char when right half is overdrawn', function()
  79. feed('o-馬<esc>ggiab ')
  80. screen:expect([[
  81. ab ^ |
  82. -馬 |
  83. {1:~ }|
  84. {1:~ }|
  85. {1:~ }|
  86. {4:-- INSERT --} |
  87. ]])
  88. -- check double-with char is temporarily hidden when overlapped
  89. funcs.complete(4, {'xx', 'yy'})
  90. screen:expect([[
  91. ab xx^ |
  92. - {2: xx } |
  93. {1:~ }{3: yy }{1: }|
  94. {1:~ }|
  95. {1:~ }|
  96. {4:-- INSERT --} |
  97. ]])
  98. -- check it is properly restored
  99. feed('z')
  100. screen:expect([[
  101. ab xxz^ |
  102. -馬 |
  103. {1:~ }|
  104. {1:~ }|
  105. {1:~ }|
  106. {4:-- INSERT --} |
  107. ]])
  108. end)
  109. end)
  110. describe('multibyte rendering: statusline', function()
  111. local screen
  112. before_each(function()
  113. clear()
  114. screen = Screen.new(40, 4)
  115. screen:set_default_attr_ids({
  116. [1] = {bold = true, foreground = Screen.colors.Blue1},
  117. [2] = {bold = true, reverse = true},
  118. })
  119. screen:attach()
  120. command('set laststatus=2')
  121. end)
  122. it('last char shows (multibyte)', function()
  123. command('set statusline=你好')
  124. screen:expect([[
  125. ^ |
  126. {1:~ }|
  127. {2:你好 }|
  128. |
  129. ]])
  130. end)
  131. it('last char shows (single byte)', function()
  132. command('set statusline=abc')
  133. screen:expect([[
  134. ^ |
  135. {1:~ }|
  136. {2:abc }|
  137. |
  138. ]])
  139. end)
  140. it('unicode control points', function()
  141. command('set statusline=Ÿ')
  142. screen:expect([[
  143. ^ |
  144. {1:~ }|
  145. {2:<9f> }|
  146. |
  147. ]])
  148. end)
  149. it('MAX_MCO (6) unicode combination points', function()
  150. command('set statusline=o̸⃯ᷰ⃐⃧⃝')
  151. -- o + U+1DF0 + U+20EF + U+0338 + U+20D0 + U+20E7 + U+20DD
  152. screen:expect([[
  153. ^ |
  154. {1:~ }|
  155. {2:o̸⃯ᷰ⃐⃧⃝ }|
  156. |
  157. ]])
  158. end)
  159. it('non-printable followed by MAX_MCO unicode combination points', function()
  160. command('set statusline=Ÿ̸⃯ᷰ⃐⃧⃝')
  161. -- U+9F + U+1DF0 + U+20EF + U+0338 + U+20D0 + U+20E7 + U+20DD
  162. screen:expect([[
  163. ^ |
  164. {1:~ }|
  165. {2:<9f><1df0><20ef><0338><20d0><20e7><20dd>}|
  166. |
  167. ]])
  168. end)
  169. it('hidden group %( %) does not cause invalid unicode', function()
  170. command("let &statusline = '%#StatColorHi2#%(✓%#StatColorHi2#%) Q≡'")
  171. screen:expect{grid=[[
  172. ^ |
  173. {1:~ }|
  174. {2: Q≡ }|
  175. |
  176. ]]}
  177. end)
  178. end)