multibyte_spec.lua 6.9 KB

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