robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
26.9 KiB795 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3local Screen = require('test.functional.ui.screen')
4
5local describe, it, before_each = t.describe, t.it, t.before_each
6local eq = t.eq
7local feed = n.feed
8local clear = n.clear
9local api = n.api
10local fn = n.fn
11local source = n.source
12local exec_capture = n.exec_capture
13local dedent = t.dedent
14local command = n.command
15
16local screen
17
18-- Bug in input() handling: :redraw! will erase the whole prompt up until
19-- user types something. It exists in Vim as well, so using `h<BS>` as
20-- a workaround.
21local function redraw_input()
22  feed('{REDRAW}h<BS>')
23end
24
25before_each(function()
26  clear()
27  screen = Screen.new(40, 8)
28  source([[
29    highlight RBP1 guibg=Red
30    highlight RBP2 guibg=Yellow
31    highlight RBP3 guibg=Green
32    highlight RBP4 guibg=Blue
33    let g:NUM_LVLS = 4
34    function Redraw()
35      mode
36      return "\<Ignore>"
37    endfunction
38    let g:id = ''
39    cnoremap <expr> {REDRAW} Redraw()
40    function DoPrompt(do_return) abort
41      let id = g:id
42      let Cb = g:Nvim_color_input{g:id}
43      let out = input({'prompt': ':', 'highlight': Cb})
44      let g:out{id} = out
45      return (a:do_return ? out : "\<Ignore>")
46    endfunction
47    nnoremap <expr> {PROMPT} DoPrompt(0)
48    cnoremap <expr> {PROMPT} DoPrompt(1)
49    function RainBowParens(cmdline)
50      let ret = []
51      let i = 0
52      let lvl = 0
53      while i < len(a:cmdline)
54        if a:cmdline[i] is# '('
55          call add(ret, [i, i + 1, 'RBP' . ((lvl % g:NUM_LVLS) + 1)])
56          let lvl += 1
57        elseif a:cmdline[i] is# ')'
58          let lvl -= 1
59          call add(ret, [i, i + 1, 'RBP' . ((lvl % g:NUM_LVLS) + 1)])
60        endif
61        let i += 1
62      endwhile
63      return ret
64    endfunction
65    function SplitMultibyteStart(cmdline)
66      let ret = []
67      let i = 0
68      while i < len(a:cmdline)
69        let char = nr2char(char2nr(a:cmdline[i:]))
70        if a:cmdline[i:i +  len(char) - 1] is# char
71          if len(char) > 1
72            call add(ret, [i + 1, i + len(char), 'RBP2'])
73          endif
74          let i += len(char)
75        else
76          let i += 1
77        endif
78      endwhile
79      return ret
80    endfunction
81    function SplitMultibyteEnd(cmdline)
82      let ret = []
83      let i = 0
84      while i < len(a:cmdline)
85        let char = nr2char(char2nr(a:cmdline[i:]))
86        if a:cmdline[i:i +  len(char) - 1] is# char
87          if len(char) > 1
88            call add(ret, [i, i + 1, 'RBP1'])
89          endif
90          let i += len(char)
91        else
92          let i += 1
93        endif
94      endwhile
95      return ret
96    endfunction
97    function Echoing(cmdline)
98      echo 'HERE'
99      return v:_null_list
100    endfunction
101    function Echoning(cmdline)
102      echon 'HERE'
103      return v:_null_list
104    endfunction
105    function Echomsging(cmdline)
106      echomsg 'HERE'
107      return v:_null_list
108    endfunction
109    function Echoerring(cmdline)
110      echoerr 'HERE'
111      return v:_null_list
112    endfunction
113    function Redrawing(cmdline)
114      redraw!
115      return v:_null_list
116    endfunction
117    function Throwing(cmdline)
118      throw "ABC"
119      return v:_null_list
120    endfunction
121    function Halting(cmdline)
122      while 1
123      endwhile
124    endfunction
125    function ReturningGlobal(cmdline)
126      return g:callback_return
127    endfunction
128    function ReturningGlobal2(cmdline)
129      return g:callback_return[:len(a:cmdline)-1]
130    endfunction
131    function ReturningGlobalN(n, cmdline)
132      return g:callback_return{a:n}
133    endfunction
134    let g:recording_calls = []
135    function Recording(cmdline)
136      call add(g:recording_calls, a:cmdline)
137      return []
138    endfunction
139  ]])
140  screen:set_default_attr_ids({
141    RBP1 = { background = Screen.colors.Red },
142    RBP2 = { background = Screen.colors.Yellow },
143    RBP3 = { background = Screen.colors.Green },
144    RBP4 = { background = Screen.colors.Blue },
145    EOB = { bold = true, foreground = Screen.colors.Blue1 },
146    ERR = { foreground = Screen.colors.Grey100, background = Screen.colors.Red },
147    SK = { foreground = Screen.colors.Blue },
148    PE = { bold = true, foreground = Screen.colors.SeaGreen4 },
149    NUM = { foreground = Screen.colors.Blue2 },
150    NPAR = { foreground = Screen.colors.Yellow },
151    SQ = { foreground = Screen.colors.Blue3 },
152    SB = { foreground = Screen.colors.Blue4 },
153    E = { foreground = Screen.colors.Red, background = Screen.colors.Blue },
154    M = { bold = true },
155    MSEP = { bold = true, reverse = true },
156  })
157end)
158
159local function set_color_cb(funcname, callback_return, id)
160  api.nvim_set_var('id', id or '')
161  if id and id ~= '' and fn.exists('*' .. funcname .. 'N') == 1 then
162    command(('let g:Nvim_color_input%s = {cmdline -> %sN(%s, cmdline)}'):format(id, funcname, id))
163    if callback_return then
164      api.nvim_set_var('callback_return' .. id, callback_return)
165    end
166  else
167    api.nvim_set_var('Nvim_color_input', funcname)
168    if callback_return then
169      api.nvim_set_var('callback_return', callback_return)
170    end
171  end
172end
173local function start_prompt(text)
174  feed('{PROMPT}' .. (text or ''))
175end
176
177describe('Command-line coloring', function()
178  it('works', function()
179    set_color_cb('RainBowParens')
180    api.nvim_set_option_value('more', false, {})
181    start_prompt()
182    screen:expect([[
183                                              |
184      {EOB:~                                       }|*6
185      :^                                       |
186    ]])
187    feed('e')
188    screen:expect([[
189                                              |
190      {EOB:~                                       }|*6
191      :e^                                      |
192    ]])
193    feed('cho ')
194    screen:expect([[
195                                              |
196      {EOB:~                                       }|*6
197      :echo ^                                  |
198    ]])
199    feed('(')
200    screen:expect([[
201                                              |
202      {EOB:~                                       }|*6
203      :echo {RBP1:(}^                                 |
204    ]])
205    feed('(')
206    screen:expect([[
207                                              |
208      {EOB:~                                       }|*6
209      :echo {RBP1:(}{RBP2:(}^                                |
210    ]])
211    feed('42')
212    screen:expect([[
213                                              |
214      {EOB:~                                       }|*6
215      :echo {RBP1:(}{RBP2:(}42^                              |
216    ]])
217    feed('))')
218    screen:expect([[
219                                              |
220      {EOB:~                                       }|*6
221      :echo {RBP1:(}{RBP2:(}42{RBP2:)}{RBP1:)}^                            |
222    ]])
223    feed('<BS>')
224    screen:expect([[
225                                              |
226      {EOB:~                                       }|*6
227      :echo {RBP1:(}{RBP2:(}42{RBP2:)}^                             |
228    ]])
229    redraw_input()
230    screen:expect {
231      grid = [[
232                                              |
233      {EOB:~                                       }|*6
234      :echo {RBP1:(}{RBP2:(}42{RBP2:)}^                             |
235    ]],
236      reset = true,
237    }
238  end)
239  for _, func_part in ipairs({ '', 'n', 'msg' }) do
240    it('disables :echo' .. func_part .. ' messages', function()
241      set_color_cb('Echo' .. func_part .. 'ing')
242      start_prompt('echo')
243      screen:expect([[
244                                                |
245        {EOB:~                                       }|*6
246        :echo^                                   |
247      ]])
248    end)
249  end
250  it('does the right thing when hl start appears to split multibyte char', function()
251    set_color_cb('SplitMultibyteStart')
252    start_prompt('echo "«')
253    screen:expect {
254      grid = [[
255                                              |
256      {EOB:~                                       }|*2
257      {MSEP:                                        }|
258      :echo "                                 |
259      {ERR:E5405: Chunk 0 start 7 splits multibyte }|
260      {ERR:character}                               |
261      :echo "«^                                |
262    ]],
263    }
264    feed('»')
265    screen:expect([[
266                                              |
267      {EOB:~                                       }|*2
268      {MSEP:                                        }|
269      :echo "                                 |
270      {ERR:E5405: Chunk 0 start 7 splits multibyte }|
271      {ERR:character}                               |
272      :echo "«»^                               |
273    ]])
274  end)
275  it('does the right thing when hl end appears to split multibyte char', function()
276    set_color_cb('SplitMultibyteEnd')
277    start_prompt('echo "«')
278    screen:expect([[
279                                              |
280      {EOB:~                                       }|*2
281      {MSEP:                                        }|
282      :echo "                                 |
283      {ERR:E5406: Chunk 0 end 7 splits multibyte ch}|
284      {ERR:aracter}                                 |
285      :echo "«^                                |
286    ]])
287  end)
288  it('does the right thing when erroring', function()
289    set_color_cb('Echoerring')
290    start_prompt('e')
291    screen:expect([[
292                                              |
293      {EOB:~                                       }|
294      {MSEP:                                        }|
295      :                                       |
296      {ERR:E5407: Callback has thrown an exception:}|
297      {ERR: function DoPrompt[3]..Echoerring, line }|
298      {ERR:1: Vim(echoerr):HERE}                    |
299      :e^                                      |
300    ]])
301  end)
302  it('silences :echo', function()
303    set_color_cb('Echoing')
304    start_prompt('e')
305    screen:expect([[
306                                              |
307      {EOB:~                                       }|*6
308      :e^                                      |
309    ]])
310    eq('', exec_capture('messages'))
311  end)
312  it('silences :echon', function()
313    set_color_cb('Echoning')
314    start_prompt('e')
315    screen:expect([[
316                                              |
317      {EOB:~                                       }|*6
318      :e^                                      |
319    ]])
320    eq('', exec_capture('messages'))
321  end)
322  it('silences :echomsg', function()
323    set_color_cb('Echomsging')
324    start_prompt('e')
325    screen:expect([[
326                                              |
327      {EOB:~                                       }|*6
328      :e^                                      |
329    ]])
330    eq('', exec_capture('messages'))
331  end)
332  it('does the right thing when throwing', function()
333    set_color_cb('Throwing')
334    start_prompt('e')
335    screen:expect([[
336                                              |
337      {EOB:~                                       }|
338      {MSEP:                                        }|
339      :                                       |
340      {ERR:E5407: Callback has thrown an exception:}|
341      {ERR: function DoPrompt[3]..Throwing, line 1:}|
342      {ERR: ABC}                                    |
343      :e^                                      |
344    ]])
345  end)
346  it('stops executing callback after a number of errors', function()
347    set_color_cb('SplitMultibyteStart')
348    start_prompt('let x = "«»«»«»«»«»"')
349    screen:expect([[
350                                              |
351      {EOB:~                                       }|*2
352      {MSEP:                                        }|
353      :let x = "                              |
354      {ERR:E5405: Chunk 0 start 10 splits multibyte}|
355      {ERR: character}                              |
356      :let x = "«»«»«»«»«»"^                   |
357    ]])
358    feed('\n')
359    screen:expect([[
360      ^                                        |
361      {EOB:~                                       }|*6
362                                              |
363    ]])
364    feed('\n')
365    eq('let x = "«»«»«»«»«»"', api.nvim_get_var('out'))
366    local msg = '\nE5405: Chunk 0 start 10 splits multibyte character'
367    eq(msg:rep(1), fn.execute('messages'))
368  end)
369  it('allows interrupting callback with <C-c>', function()
370    set_color_cb('Halting')
371    start_prompt('echo 42')
372    screen:expect([[
373      ^                                        |
374      {EOB:~                                       }|*6
375                                              |
376    ]])
377    screen:sleep(500)
378    feed('<C-c>')
379    screen:expect([[
380                                              |
381      {EOB:~                                       }|*2
382      {MSEP:                                        }|
383      :                                       |
384      {ERR:E5407: Callback has thrown an exception:}|
385      {ERR: Keyboard interrupt}                     |
386      :echo 42^                                |
387    ]])
388    redraw_input()
389    screen:expect([[
390                                              |
391      {EOB:~                                       }|*6
392      :echo 42^                                |
393    ]])
394    feed('\n')
395    screen:expect([[
396      ^                                        |
397      {EOB:~                                       }|*6
398      :echo 42                                |
399    ]])
400    feed('\n')
401    eq('echo 42', api.nvim_get_var('out'))
402    feed('<C-c>')
403    screen:expect([[
404      ^                                        |
405      {EOB:~                                       }|*6
406      Type  :qa  and pre...nter> to exit Nvim |
407    ]])
408  end)
409  it('works fine with NUL, NL, CR', function()
410    set_color_cb('RainBowParens')
411    start_prompt('echo ("<C-v><CR><C-v><Nul><C-v><NL>")')
412    screen:expect([[
413                                              |
414      {EOB:~                                       }|*6
415      :echo {RBP1:(}"{SK:^M^@^@}"{RBP1:)}^                        |
416    ]])
417  end)
418  it('errors out when callback returns something wrong', function()
419    command('cnoremap + ++')
420    set_color_cb('ReturningGlobal', '')
421    start_prompt('#')
422    screen:expect([[
423                                              |
424      {EOB:~                                       }|*3
425      {MSEP:                                        }|
426      :                                       |
427      {ERR:E5400: Callback should return list}      |
428      :#^                                      |
429    ]])
430
431    feed('<CR><CR><CR>')
432    set_color_cb('ReturningGlobal', { { 0, 1, 'Normal' }, 42 })
433    start_prompt('#')
434    screen:expect([[
435                                              |
436      {EOB:~                                       }|*3
437      {MSEP:                                        }|
438      :                                       |
439      {ERR:E5401: List item 1 is not a List}        |
440      :#^                                      |
441    ]])
442
443    feed('<CR><CR><CR>')
444    set_color_cb('ReturningGlobal2', { { 0, 1, 'Normal' }, { 1 } })
445    start_prompt('+')
446    screen:expect([[
447                                              |
448      {EOB:~                                       }|*2
449      {MSEP:                                        }|
450      :+                                      |
451      {ERR:E5402: List item 1 has incorrect length:}|
452      {ERR: 1 /= 3}                                 |
453      :++^                                     |
454    ]])
455
456    feed('<CR><CR><CR>')
457    set_color_cb('ReturningGlobal2', { { 0, 1, 'Normal' }, { 2, 3, 'Normal' } })
458    start_prompt('+')
459    screen:expect([[
460                                              |
461      {EOB:~                                       }|*2
462      {MSEP:                                        }|
463      :+                                      |
464      {ERR:E5403: Chunk 1 start 2 not in range [1, }|
465      {ERR:2)}                                      |
466      :++^                                     |
467    ]])
468
469    feed('<CR><CR><CR>')
470    set_color_cb('ReturningGlobal2', { { 0, 1, 'Normal' }, { 1, 3, 'Normal' } })
471    start_prompt('+')
472    screen:expect([[
473                                              |
474      {EOB:~                                       }|*3
475      {MSEP:                                        }|
476      :+                                      |
477      {ERR:E5404: Chunk 1 end 3 not in range (1, 2]}|
478      :++^                                     |
479    ]])
480  end)
481  it('does not error out when called from a errored out cycle', function()
482    set_color_cb('ReturningGlobal', { { 0, 1, 'Normal' } })
483    feed(dedent([[
484      :set regexpengine=2
485      :for pat in [' \ze*', ' \zs*']
486      :  try
487      :    let l = matchlist('x x', pat)
488      :    $put =input({'prompt':'>','highlight':'ReturningGlobal'})
489      :
490      :    $put ='E888 NOT detected for ' . pat
491      :  catch
492      :    $put =input({'prompt':'>','highlight':'ReturningGlobal'})
493      :
494      :    $put ='E888 detected for ' . pat
495      :  endtry
496      :endfor
497      :
498      :
499      :
500      :
501      :
502      :
503    ]]))
504    eq(
505      { '', ':', 'E888 detected for  \\ze*', ':', 'E888 detected for  \\zs*' },
506      api.nvim_buf_get_lines(0, 0, -1, false)
507    )
508    eq('', fn.execute('messages'))
509  end)
510  it('allows nesting input()s', function()
511    set_color_cb('ReturningGlobal', { { 0, 1, 'RBP1' } }, '')
512    start_prompt('1')
513    screen:expect([[
514                                              |
515      {EOB:~                                       }|*6
516      :{RBP1:1}^                                      |
517    ]])
518
519    set_color_cb('ReturningGlobal', { { 0, 1, 'RBP2' } }, '1')
520    start_prompt('2')
521    screen:expect([[
522                                              |
523      {EOB:~                                       }|*6
524      :{RBP2:2}^                                      |
525    ]])
526
527    set_color_cb('ReturningGlobal', { { 0, 1, 'RBP3' } }, '2')
528    start_prompt('3')
529    screen:expect([[
530                                              |
531      {EOB:~                                       }|*6
532      :{RBP3:3}^                                      |
533    ]])
534
535    set_color_cb('ReturningGlobal', { { 0, 1, 'RBP4' } }, '3')
536    start_prompt('4')
537    screen:expect([[
538                                              |
539      {EOB:~                                       }|*6
540      :{RBP4:4}^                                      |
541    ]])
542
543    feed('<CR>')
544    screen:expect([[
545                                              |
546      {EOB:~                                       }|*6
547      :{RBP3:3}4^                                     |
548    ]])
549    feed('<CR>')
550    screen:expect([[
551                                              |
552      {EOB:~                                       }|*6
553      :{RBP2:2}34^                                    |
554    ]])
555    feed('<CR>')
556    screen:expect([[
557                                              |
558      {EOB:~                                       }|*6
559      :{RBP1:1}234^                                   |
560    ]])
561    feed('<CR><CR><C-l>')
562    screen:expect([[
563      ^                                        |
564      {EOB:~                                       }|*6
565                                              |
566    ]])
567    eq('1234', api.nvim_get_var('out'))
568    eq('234', api.nvim_get_var('out1'))
569    eq('34', api.nvim_get_var('out2'))
570    eq('4', api.nvim_get_var('out3'))
571    eq(0, fn.exists('g:out4'))
572  end)
573  it('runs callback with the same data only once', function()
574    local function new_recording_calls(...)
575      eq({ ... }, api.nvim_get_var('recording_calls'))
576      api.nvim_set_var('recording_calls', {})
577    end
578    set_color_cb('Recording')
579    start_prompt('')
580    -- Regression test. Disambiguation:
581    --
582    --     new_recording_calls(expected_result) -- (actual_before_fix)
583    --
584    feed('a')
585    new_recording_calls('a') -- ('a', 'a')
586    feed('b')
587    new_recording_calls('ab') -- ('a', 'ab', 'ab')
588    feed('c')
589    new_recording_calls('abc') -- ('ab', 'abc', 'abc')
590    feed('<BS>')
591    new_recording_calls('ab') -- ('abc', 'ab', 'ab')
592    feed('<BS>')
593    new_recording_calls('a') -- ('ab', 'a', 'a')
594    feed('<BS>')
595    new_recording_calls() -- ('a')
596    feed('<CR><CR>')
597    eq('', api.nvim_get_var('out'))
598  end)
599  it('does not crash when callback has caught not-a-editor-command exception', function()
600    source([[
601      function CaughtExc(cmdline) abort
602        try
603          gibberish
604        catch
605          " Do nothing
606        endtry
607        return []
608      endfunction
609    ]])
610    set_color_cb('CaughtExc')
611    start_prompt('1')
612    eq(1, api.nvim_eval('1'))
613  end)
614end)
615describe('Ex commands coloring', function()
616  it('works', function()
617    api.nvim_set_var('Nvim_color_cmdline', 'RainBowParens')
618    feed(':echo (((1)))')
619    screen:expect([[
620                                              |
621      {EOB:~                                       }|*6
622      :echo {RBP1:(}{RBP2:(}{RBP3:(}1{RBP3:)}{RBP2:)}{RBP1:)}^                           |
623    ]])
624  end)
625  it('still executes command-line even if errored out', function()
626    api.nvim_set_var('Nvim_color_cmdline', 'SplitMultibyteStart')
627    feed(':let x = "«"\n')
628    eq('«', api.nvim_get_var('x'))
629    local msg = 'E5405: Chunk 0 start 10 splits multibyte character'
630    eq('\n' .. msg, fn.execute('messages'))
631  end)
632  it('does not error out when called from a errored out cycle', function()
633    -- Apparently when there is a cycle in which one of the commands errors out
634    -- this error may be caught by color_cmdline before it is presented to the
635    -- user.
636    feed(dedent([[
637      :set regexpengine=2
638      :for pat in [' \ze*', ' \zs*']
639      :  try
640      :    let l = matchlist('x x', pat)
641      :    $put ='E888 NOT detected for ' . pat
642      :  catch
643      :    $put ='E888 detected for ' . pat
644      :  endtry
645      :endfor
646    ]]))
647    eq(
648      { '', 'E888 detected for  \\ze*', 'E888 detected for  \\zs*' },
649      api.nvim_buf_get_lines(0, 0, -1, false)
650    )
651    eq('', fn.execute('messages'))
652  end)
653  it('does not crash when using `n` in debug mode', function()
654    feed(':debug execute "echo 1"\n')
655    screen:expect([[
656                                              |
657      {EOB:~                                       }|*2
658      {MSEP:                                        }|
659      Entering Debug mode.  Type "cont" to con|
660      tinue.                                  |
661      cmd: execute "echo 1"                   |
662      >^                                       |
663    ]])
664    feed('n\n')
665    screen:expect([[
666                                              |
667      {MSEP:                                        }|
668      Entering Debug mode.  Type "cont" to con|
669      tinue.                                  |
670      cmd: execute "echo 1"                   |
671      >n                                      |
672      1                                       |
673      {PE:Press ENTER or type command to continue}^ |
674    ]])
675    feed('\n')
676    screen:expect([[
677      ^                                        |
678      {EOB:~                                       }|*6
679                                              |
680    ]])
681  end)
682  it('mapping error does not cancel prompt', function()
683    command("cnoremap <expr> x execute('throw 42')[-1]")
684    feed(':#x')
685    screen:expect([[
686                                              |
687      {EOB:~                                       }|*2
688      {MSEP:                                        }|
689      :#                                      |
690      {ERR:Error in :}                              |
691      {ERR:E605: Exception not caught: 42}          |
692      :#^                                      |
693    ]])
694    feed('<CR>')
695    screen:expect([[
696                                              |
697      {EOB:~                                       }|
698      {MSEP:                                        }|
699      :#                                      |
700      {ERR:Error in :}                              |
701      {ERR:E605: Exception not caught: 42}          |
702      {ERR:E749: Empty buffer}                      |
703      {PE:Press ENTER or type command to continue}^ |
704    ]])
705    feed('<CR>')
706    eq('Error in :\nE605: Exception not caught: 42\nE749: Empty buffer', exec_capture('messages'))
707  end)
708  it('errors out when failing to get callback', function()
709    api.nvim_set_var('Nvim_color_cmdline', 42)
710    feed(':#')
711    screen:expect([[
712                                              |
713      {EOB:~                                       }|
714      {MSEP:                                        }|
715      :                                       |
716      {ERR:E5408: Unable to get g:Nvim_color_cmdlin}|
717      {ERR:e callback: Vim:E6000: Argument is not a}|
718      {ERR: function or function name}              |
719      :#^                                      |
720    ]])
721  end)
722end)
723describe('Expressions coloring support', function()
724  it('works', function()
725    command('hi clear NvimNumber')
726    command('hi clear NvimNestingParenthesis')
727    command('hi NvimNumber guifg=Blue2')
728    command('hi NvimNestingParenthesis guifg=Yellow')
729    feed(':echo <C-r>=(((1)))')
730    screen:expect([[
731                                              |
732      {EOB:~                                       }|*6
733      ={NPAR:(((}{NUM:1}{NPAR:)))}^                                |
734    ]])
735  end)
736  it('does not use Nvim_color_expr', function()
737    api.nvim_set_var('Nvim_color_expr', 42)
738    -- Used to error out due to failing to get callback.
739    command('hi clear NvimNumber')
740    command('hi NvimNumber guifg=Blue2')
741    feed(':<C-r>=1')
742    screen:expect([[
743                                              |
744      {EOB:~                                       }|*6
745      ={NUM:1}^                                      |
746    ]])
747  end)
748  it('works correctly with non-ASCII and control characters', function()
749    command('hi clear NvimStringBody')
750    command('hi clear NvimStringQuote')
751    command('hi clear NvimInvalid')
752    command('hi NvimStringQuote guifg=Blue3')
753    command('hi NvimStringBody guifg=Blue4')
754    command('hi NvimInvalid guifg=Red guibg=Blue')
755    feed('i<C-r>="«»"«»')
756    screen:expect([[
757                                              |
758      {EOB:~                                       }|*6
759      ={SQ:"}{SB:«»}{SQ:"}{E:«»}^                                 |
760    ]])
761    feed('<C-c>')
762    screen:expect([[
763      ^                                        |
764      {EOB:~                                       }|*6
765      {M:-- INSERT --}                            |
766    ]])
767    feed('<Esc>')
768    screen:expect([[
769      ^                                        |
770      {EOB:~                                       }|*6
771                                              |
772    ]])
773    feed(':<C-\\>e"<C-v><C-x>"<C-v><C-x>')
774    -- TODO(ZyX-I): Parser highlighting should not override special character
775    --              highlighting.
776    screen:expect([[
777                                              |
778      {EOB:~                                       }|*6
779      ={SQ:"}{SB:^X}{SQ:"}{ERR:^X}^                                 |
780    ]])
781    feed('<C-c>')
782    screen:expect([[
783                                              |
784      {EOB:~                                       }|*6
785      :^                                       |
786    ]])
787    fn.setreg('a', { '\192' })
788    feed('<C-r>="<C-r><C-r>a"<C-r><C-r>a"foo"')
789    screen:expect([[
790                                              |
791      {EOB:~                                       }|*6
792      ={SQ:"}{SB:<c0>}{SQ:"}{E:<c0>"}{SB:foo}{E:"}^                        |
793    ]])
794  end)
795end)