robin/laufey

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

Justin M. KeyesMerge #41114 from epithet/default-ruler-as-expressiondab5fab948

master
39.1 KiB1021 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 set_session, clear, assert_alive = n.set_session, n.clear, n.assert_alive
7local feed, command = n.feed, n.command
8local exec, exec_lua = n.exec, n.exec_lua
9local insert = n.insert
10local eq = t.eq
11local fn, api = n.fn, n.api
12
13describe('screen', function()
14  local screen
15  local nvim_argv = {
16    n.nvim_prog,
17    '-u',
18    'NONE',
19    '-i',
20    'NONE',
21    '-n',
22    '--cmd',
23    'set shortmess+=I background=light noswapfile belloff= noshowcmd noruler',
24    '--cmd',
25    'colorscheme vim',
26    '--embed',
27  }
28
29  before_each(function()
30    local screen_nvim = n.new_session(false, { args = nvim_argv, merge = false })
31    set_session(screen_nvim)
32    screen = Screen.new()
33  end)
34
35  it('default initial screen', function()
36    screen:expect([[
37      ^                                                     |
38      {1:~                                                    }|*11
39      {3:[No Name]                                            }|
40                                                           |
41    ]])
42  end)
43end)
44
45local function screen_tests(linegrid)
46  local screen
47
48  before_each(function()
49    clear()
50    screen = Screen.new(53, 14, { rgb = true, ext_linegrid = linegrid })
51    screen:add_extra_attr_ids({
52      [100] = {
53        background = Screen.colors.LightGrey,
54        underline = true,
55        bold = true,
56        foreground = Screen.colors.Fuchsia,
57      },
58      [101] = { bold = true, foreground = Screen.colors.Magenta1 },
59    })
60  end)
61
62  describe('bell/visual bell', function()
63    it('is forwarded to the UI', function()
64      feed('<left>')
65      screen:expect(function()
66        eq(true, screen.bell)
67        eq(false, screen.visual_bell)
68      end)
69      screen.bell = false
70      command('set visualbell')
71      feed('<left>')
72      screen:expect(function()
73        eq(true, screen.visual_bell)
74        eq(false, screen.bell)
75      end)
76    end)
77  end)
78
79  describe(':set title', function()
80    it('is forwarded to the UI', function()
81      local expected = 'test-title'
82      command('set titlestring=' .. expected)
83      command('set title')
84      screen:expect(function()
85        eq(expected, screen.title)
86      end)
87      screen:detach()
88      screen.title = nil
89      screen:attach()
90      screen:expect(function()
91        eq(expected, screen.title)
92      end)
93    end)
94  end)
95
96  describe(':set icon', function()
97    it('is forwarded to the UI', function()
98      local expected = 'test-icon'
99      command('set iconstring=' .. expected)
100      command('set icon')
101      screen:expect(function()
102        eq(expected, screen.icon)
103      end)
104      screen:detach()
105      screen.icon = nil
106      screen:attach()
107      screen:expect(function()
108        eq(expected, screen.icon)
109      end)
110    end)
111  end)
112
113  describe('statusline', function()
114    it('is redrawn after <c-l>', function()
115      command('set laststatus=2')
116      screen:expect([[
117        ^                                                     |
118        {1:~                                                    }|*11
119        {3:[No Name]                                            }|
120                                                             |
121      ]])
122
123      feed('<c-l>')
124      screen:expect {
125        grid = [[
126        ^                                                     |
127        {1:~                                                    }|*11
128        {3:[No Name]                                            }|
129                                                             |
130      ]],
131        reset = true,
132      }
133
134      command('split')
135      screen:expect([[
136        ^                                                     |
137        {1:~                                                    }|*5
138        {3:[No Name]                                            }|
139                                                             |
140        {1:~                                                    }|*4
141        {2:[No Name]                                            }|
142                                                             |
143      ]])
144
145      feed('<c-l>')
146      screen:expect {
147        grid = [[
148        ^                                                     |
149        {1:~                                                    }|*5
150        {3:[No Name]                                            }|
151                                                             |
152        {1:~                                                    }|*4
153        {2:[No Name]                                            }|
154                                                             |
155      ]],
156        reset = true,
157      }
158    end)
159  end)
160
161  describe('window', function()
162    describe('split', function()
163      it('horizontal', function()
164        command('sp')
165        screen:expect([[
166          ^                                                     |
167          {1:~                                                    }|*5
168          {3:[No Name]                                            }|
169                                                               |
170          {1:~                                                    }|*4
171          {2:[No Name]                                            }|
172                                                               |
173        ]])
174      end)
175
176      it('horizontal and resize', function()
177        command('sp')
178        command('resize 8')
179        screen:expect([[
180          ^                                                     |
181          {1:~                                                    }|*7
182          {3:[No Name]                                            }|
183                                                               |
184          {1:~                                                    }|*2
185          {2:[No Name]                                            }|
186                                                               |
187        ]])
188      end)
189
190      it('horizontal and vertical', function()
191        command('sp')
192        command('vsp')
193        command('vsp')
194        screen:expect([[
195          ^                    │                │               |
196          {1:~                   }│{1:~               }│{1:~              }|*5
197          {3:[No Name]            }{2:[No Name]        [No Name]      }|
198                                                               |
199          {1:~                                                    }|*4
200          {2:[No Name]                                            }|
201                                                               |
202        ]])
203        insert('hello')
204        screen:expect([[
205          hell^o               │hello           │hello          |
206          {1:~                   }│{1:~               }│{1:~              }|*5
207          {3:[No Name] [+]        }{2:[No Name] [+]    [No Name] [+]  }|
208          hello                                                |
209          {1:~                                                    }|*4
210          {2:[No Name] [+]                                        }|
211                                                               |
212        ]])
213      end)
214    end)
215  end)
216
217  describe('tabs', function()
218    it('tabnew creates a new buffer', function()
219      command('sp')
220      command('vsp')
221      command('vsp')
222      insert('hello')
223      screen:expect([[
224        hell^o               │hello           │hello          |
225        {1:~                   }│{1:~               }│{1:~              }|*5
226        {3:[No Name] [+]        }{2:[No Name] [+]    [No Name] [+]  }|
227        hello                                                |
228        {1:~                                                    }|*4
229        {2:[No Name] [+]                                        }|
230                                                             |
231      ]])
232      command('tabnew')
233      insert('hello2')
234      feed('h')
235      screen:expect([[
236        {24: }{100:4}{24:+ [No Name] }{5: + [No Name] }{2:                         }{24:X}|
237        hell^o2                                               |
238        {1:~                                                    }|*11
239                                                             |
240      ]])
241      command('tabprevious')
242      screen:expect([[
243        {5: }{101:4}{5:+ [No Name] }{24: + [No Name] }{2:                         }{24:X}|
244        hell^o               │hello           │hello          |
245        {1:~                   }│{1:~               }│{1:~              }|*5
246        {3:[No Name] [+]        }{2:[No Name] [+]    [No Name] [+]  }|
247        hello                                                |
248        {1:~                                                    }|*3
249        {2:[No Name] [+]                                        }|
250                                                             |
251      ]])
252    end)
253
254    it('tabline is redrawn after messages', function()
255      command('tabnew')
256      screen:expect([[
257        {24: [No Name] }{5: [No Name] }{2:                              }{24:X}|
258        ^                                                     |
259        {1:~                                                    }|*11
260                                                             |
261      ]])
262
263      feed(':echo "' .. string.rep('x\\n', 11) .. '"<cr>')
264      screen:expect([[
265        {3:                                                     }|
266        x                                                    |*11
267                                                             |
268        {6:Press ENTER or type command to continue}^              |
269      ]])
270
271      feed('<cr>')
272      screen:expect([[
273        {24: [No Name] }{5: [No Name] }{2:                              }{24:X}|
274        ^                                                     |
275        {1:~                                                    }|*11
276                                                             |
277      ]])
278
279      feed(':echo "' .. string.rep('x\\n', 12) .. '"<cr>')
280      screen:expect([[
281        x                                                    |*12
282                                                             |
283        {6:Press ENTER or type command to continue}^              |
284      ]])
285
286      feed('<cr>')
287      screen:expect([[
288        {24: [No Name] }{5: [No Name] }{2:                              }{24:X}|
289        ^                                                     |
290        {1:~                                                    }|*11
291                                                             |
292      ]])
293    end)
294
295    it('redraws properly with :tab split right after scroll', function()
296      feed('15Ofoo<esc>15Obar<esc>gg')
297
298      command('vsplit')
299      screen:expect([[
300        ^foo                       │foo                       |
301        foo                       │foo                       |*11
302        {3:[No Name] [+]              }{2:[No Name] [+]             }|
303                                                             |
304      ]])
305
306      feed('<PageDown>')
307      screen:expect([[
308        ^foo                       │foo                       |
309        foo                       │foo                       |*3
310        bar                       │foo                       |*8
311        {3:[No Name] [+]              }{2:[No Name] [+]             }|
312                                                             |
313      ]])
314      command('tab split')
315      screen:expect([[
316        {24: }{100:2}{24:+ [No Name] }{5: + [No Name] }{2:                         }{24:X}|
317        ^foo                                                  |
318        foo                                                  |*3
319        bar                                                  |*8
320                                                             |
321      ]])
322    end)
323
324    it('redraws unvisited tab #9152', function()
325      insert('hello')
326      -- create a tab without visiting it
327      command('tabnew|tabnext')
328      screen:expect([[
329        {5: + [No Name] }{24: [No Name] }{2:                            }{24:X}|
330        hell^o                                                |
331        {1:~                                                    }|*11
332                                                             |
333      ]])
334
335      feed('gT')
336      screen:expect([[
337        {24: + [No Name] }{5: [No Name] }{2:                            }{24:X}|
338        ^                                                     |
339        {1:~                                                    }|*11
340                                                             |
341      ]])
342    end)
343  end)
344
345  describe('insert mode', function()
346    it('move to next line with <cr>', function()
347      feed('iline 1<cr>line 2<cr>')
348      screen:expect([[
349        line 1                                               |
350        line 2                                               |
351        ^                                                     |
352        {1:~                                                    }|*10
353        {5:-- INSERT --}                                         |
354      ]])
355    end)
356  end)
357
358  describe('normal mode', function()
359    -- https://code.google.com/p/vim/issues/detail?id=339
360    it("setting 'ruler' doesn't reset the preferred column", function()
361      command('set virtualedit=')
362      feed('i0123456<cr>789<esc>kllj')
363      command('set ruler')
364      feed('k')
365      screen:expect([[
366        0123^456                                              |
367        789                                                  |
368        {1:~                                                    }|*11
369                                           1,5            All|
370      ]])
371    end)
372  end)
373
374  describe('command mode', function()
375    it('typing commands', function()
376      feed(':ls')
377      screen:expect([[
378                                                             |
379        {1:~                                                    }|*12
380        :ls^                                                  |
381      ]])
382    end)
383
384    it('execute command with multi-line output', function()
385      feed(':ls<cr>')
386      screen:expect([[
387                                                             |
388        {1:~                                                    }|*9
389        {3:                                                     }|
390        :ls                                                  |
391          1 %a   "[No Name]"                    line 1       |
392        {6:Press ENTER or type command to continue}^              |
393      ]])
394      feed('<cr>') --  skip the "Press ENTER..." state or tests will hang
395    end)
396  end)
397
398  describe('scrolling and clearing', function()
399    before_each(function()
400      insert([[
401      Inserting
402      text
403      with
404      many
405      lines
406      to
407      test
408      scrolling
409      and
410      clearing
411      in
412      split
413      windows
414      ]])
415      command('sp')
416      command('vsp')
417      command('vsp')
418      screen:expect([[
419        and                 │and             │and            |
420        clearing            │clearing        │clearing       |
421        in                  │in              │in             |
422        split               │split           │split          |
423        windows             │windows         │windows        |
424        ^                    │                │               |
425        {3:[No Name] [+]        }{2:[No Name] [+]    [No Name] [+]  }|
426        clearing                                             |
427        in                                                   |
428        split                                                |
429        windows                                              |
430                                                             |
431        {2:[No Name] [+]                                        }|
432                                                             |
433      ]])
434    end)
435
436    it('only affects the current scroll region', function()
437      feed('6k')
438      screen:expect([[
439        ^scrolling           │and             │and            |
440        and                 │clearing        │clearing       |
441        clearing            │in              │in             |
442        in                  │split           │split          |
443        split               │windows         │windows        |
444        windows             │                │               |
445        {3:[No Name] [+]        }{2:[No Name] [+]    [No Name] [+]  }|
446        clearing                                             |
447        in                                                   |
448        split                                                |
449        windows                                              |
450                                                             |
451        {2:[No Name] [+]                                        }|
452                                                             |
453      ]])
454      feed('<c-w>l')
455      screen:expect([[
456        scrolling           │and                 │and        |
457        and                 │clearing            │clearing   |
458        clearing            │in                  │in         |
459        in                  │split               │split      |
460        split               │windows             │windows    |
461        windows             │^                    │           |
462        {2:[No Name] [+]        }{3:[No Name] [+]        }{2:<Name] [+] }|
463        clearing                                             |
464        in                                                   |
465        split                                                |
466        windows                                              |
467                                                             |
468        {2:[No Name] [+]                                        }|
469                                                             |
470      ]])
471      feed('gg')
472      screen:expect([[
473        scrolling           │^Inserting           │and        |
474        and                 │text                │clearing   |
475        clearing            │with                │in         |
476        in                  │many                │split      |
477        split               │lines               │windows    |
478        windows             │to                  │           |
479        {2:[No Name] [+]        }{3:[No Name] [+]        }{2:<Name] [+] }|
480        clearing                                             |
481        in                                                   |
482        split                                                |
483        windows                                              |
484                                                             |
485        {2:[No Name] [+]                                        }|
486                                                             |
487      ]])
488      feed('7j')
489      screen:expect([[
490        scrolling           │with                │and        |
491        and                 │many                │clearing   |
492        clearing            │lines               │in         |
493        in                  │to                  │split      |
494        split               │test                │windows    |
495        windows             │^scrolling           │           |
496        {2:[No Name] [+]        }{3:[No Name] [+]        }{2:<Name] [+] }|
497        clearing                                             |
498        in                                                   |
499        split                                                |
500        windows                                              |
501                                                             |
502        {2:[No Name] [+]                                        }|
503                                                             |
504      ]])
505      feed('2j')
506      screen:expect([[
507        scrolling           │lines               │and        |
508        and                 │to                  │clearing   |
509        clearing            │test                │in         |
510        in                  │scrolling           │split      |
511        split               │and                 │windows    |
512        windows             │^clearing            │           |
513        {2:[No Name] [+]        }{3:[No Name] [+]        }{2:<Name] [+] }|
514        clearing                                             |
515        in                                                   |
516        split                                                |
517        windows                                              |
518                                                             |
519        {2:[No Name] [+]                                        }|
520                                                             |
521      ]])
522      feed('5k')
523      screen:expect([[
524        scrolling           │^lines               │and        |
525        and                 │to                  │clearing   |
526        clearing            │test                │in         |
527        in                  │scrolling           │split      |
528        split               │and                 │windows    |
529        windows             │clearing            │           |
530        {2:[No Name] [+]        }{3:[No Name] [+]        }{2:<Name] [+] }|
531        clearing                                             |
532        in                                                   |
533        split                                                |
534        windows                                              |
535                                                             |
536        {2:[No Name] [+]                                        }|
537                                                             |
538      ]])
539      feed('k')
540      screen:expect([[
541        scrolling           │^many                │and        |
542        and                 │lines               │clearing   |
543        clearing            │to                  │in         |
544        in                  │test                │split      |
545        split               │scrolling           │windows    |
546        windows             │and                 │           |
547        {2:[No Name] [+]        }{3:[No Name] [+]        }{2:<Name] [+] }|
548        clearing                                             |
549        in                                                   |
550        split                                                |
551        windows                                              |
552                                                             |
553        {2:[No Name] [+]                                        }|
554                                                             |
555      ]])
556    end)
557
558    it('recomposes lines when floating window is positioned over scroll region', function()
559      local scroll_events = 0
560      local original = screen._handle_grid_scroll
561      screen._handle_grid_scroll = function(...)
562        scroll_events = scroll_events + 1
563        return original(...)
564      end
565
566      local buf = api.nvim_create_buf(false, false)
567      api.nvim_open_win(
568        buf,
569        false,
570        { relative = 'editor', width = 10, height = 2, row = 3, col = 0 }
571      )
572
573      screen:expect([[
574        and                 │and             │and            |
575        clearing            │clearing        │clearing       |
576        in                  │in              │in             |
577        {4:          }          │split           │split          |
578        {11:~         }          │windows         │windows        |
579        ^                    │                │               |
580        {3:[No Name] [+]        }{2:[No Name] [+]    [No Name] [+]  }|
581        clearing                                             |
582        in                                                   |
583        split                                                |
584        windows                                              |
585                                                             |
586        {2:[No Name] [+]                                        }|
587                                                             |
588      ]])
589      feed('gg')
590      screen:expect([[
591        ^Inserting           │and             │and            |
592        text                │clearing        │clearing       |
593        with                │in              │in             |
594        {4:          }          │split           │split          |
595        {11:~         }          │windows         │windows        |
596        to                  │                │               |
597        {3:[No Name] [+]        }{2:[No Name] [+]    [No Name] [+]  }|
598        clearing                                             |
599        in                                                   |
600        split                                                |
601        windows                                              |
602                                                             |
603        {2:[No Name] [+]                                        }|
604                                                             |
605      ]])
606      eq(0, scroll_events)
607      feed('<c-f>')
608      screen:expect([[
609        ^lines               │and             │and            |
610        to                  │clearing        │clearing       |
611        test                │in              │in             |
612        {4:          }          │split           │split          |
613        {11:~         }          │windows         │windows        |
614        clearing            │                │               |
615        {3:[No Name] [+]        }{2:[No Name] [+]    [No Name] [+]  }|
616        clearing                                             |
617        in                                                   |
618        split                                                |
619        windows                                              |
620                                                             |
621        {2:[No Name] [+]                                        }|
622                                                             |
623      ]])
624      eq(0, scroll_events)
625      feed('<c-w>jHk')
626      screen:expect([[
627        lines               │and             │and            |
628        to                  │clearing        │clearing       |
629        test                │in              │in             |
630        {4:          }          │split           │split          |
631        {11:~         }          │windows         │windows        |
632        clearing            │                │               |
633        {2:[No Name] [+]        [No Name] [+]    [No Name] [+]  }|
634        ^and                                                  |
635        clearing                                             |
636        in                                                   |
637        split                                                |
638        windows                                              |
639        {3:[No Name] [+]                                        }|
640                                                             |
641      ]])
642      eq(1, scroll_events)
643    end)
644  end)
645
646  describe('resize', function()
647    it('rebuilds the whole screen', function()
648      screen:try_resize(25, 5)
649      feed('iresize')
650      screen:expect([[
651        resize^                   |
652        {1:~                        }|*3
653        {5:-- INSERT --}             |
654      ]])
655    end)
656
657    it('has minimum width/height values', function()
658      feed('iresize')
659      screen:try_resize(1, 1)
660      screen:expect([[
661        resize^      |
662        {5:-- INSERT --}|
663      ]])
664
665      feed('<esc>:ls')
666      screen:expect([[
667        resize      |
668        :ls^         |
669      ]])
670    end)
671
672    it('VimResized autocommand does not cause invalid UI events #20692 #20759', function()
673      screen:try_resize(25, 5)
674      feed('iresize<Esc>')
675      command([[autocmd VimResized * redrawtabline]])
676      command([[autocmd VimResized * lua vim.api.nvim_echo({ { 'Hello' } }, false, {})]])
677      command([[autocmd VimResized * let g:echospace = v:echospace]])
678      api.nvim_set_option_value('showtabline', 2, {})
679      screen:expect([[
680        {5: + [No Name] }{2:            }|
681        resiz^e                   |
682        {1:~                        }|*2
683                                 |
684      ]])
685      screen:try_resize(30, 6)
686      screen:expect([[
687        {5: + [No Name] }{2:                 }|
688        resiz^e                        |
689        {1:~                             }|*3
690                                      |
691      ]])
692      eq(29, api.nvim_get_var('echospace'))
693    end)
694
695    it('messages from the same Ex command as resize are visible #22225', function()
696      feed(':set columns=20 | call<CR>')
697      screen:expect([[
698                            |*9
699        {3:                    }|
700        {9:E471: Argument requi}|
701        {9:red}                 |
702        {6:Press ENTER or type }|
703        {6:command to continue}^ |
704      ]])
705      feed('<CR>')
706      screen:expect([[
707        ^                    |
708        {1:~                   }|*12
709                            |
710      ]])
711      feed(':set columns=0<CR>')
712      screen:expect([[
713                            |
714        {1:~                   }|*7
715        {3:                    }|
716        {9:E594: Need at least }|
717        {9:12 columns: columns=}|
718        {9:0}                   |
719        {6:Press ENTER or type }|
720        {6:command to continue}^ |
721      ]])
722      feed('<CR>')
723      screen:expect([[
724        ^                    |
725        {1:~                   }|*12
726                            |
727      ]])
728    end)
729
730    it('does not crash when windows fill the screen #33883', function()
731      screen:try_resize(80, 20)
732      while true do
733        local ok = pcall(command, 'wincmd v')
734        if not ok then
735          break
736        end
737      end
738
739      screen:try_resize(60, 20)
740
741      assert_alive()
742    end)
743
744    it('clamps &cmdheight for current tabpage', function()
745      command('set cmdheight=10 laststatus=2')
746      screen:expect([[
747        ^                                                     |
748        {1:~                                                    }|*2
749        {3:[No Name]                                            }|
750                                                             |*10
751      ]])
752      screen:try_resize(53, 8)
753      screen:expect([[
754        ^                                                     |
755        {3:[No Name]                                            }|
756                                                             |*6
757      ]])
758      eq(6, api.nvim_get_option_value('cmdheight', {}))
759    end)
760
761    it('clamps &cmdheight for another tabpage #31380', function()
762      command('tabnew')
763      command('set cmdheight=9 laststatus=2')
764      screen:expect([[
765        {24: [No Name] }{5: [No Name] }{2:                              }{24:X}|
766        ^                                                     |
767        {1:~                                                    }|*2
768        {3:[No Name]                                            }|
769                                                             |*9
770      ]])
771      command('tabprev')
772      screen:expect([[
773        {5: [No Name] }{24: [No Name] }{2:                              }{24:X}|
774        ^                                                     |
775        {1:~                                                    }|*10
776        {3:[No Name]                                            }|
777                                                             |
778      ]])
779      screen:try_resize(53, 8)
780      screen:expect([[
781        {5: [No Name] }{24: [No Name] }{2:                              }{24:X}|
782        ^                                                     |
783        {1:~                                                    }|*4
784        {3:[No Name]                                            }|
785                                                             |
786      ]])
787      command('tabnext')
788      screen:expect([[
789        {24: [No Name] }{5: [No Name] }{2:                              }{24:X}|
790        ^                                                     |
791        {3:[No Name]                                            }|
792                                                             |*5
793      ]])
794      eq(5, api.nvim_get_option_value('cmdheight', {}))
795    end)
796  end)
797
798  describe('press enter', function()
799    it('does not crash on <F1> at “Press ENTER”', function()
800      command('nnoremap <F1> :echo "TEST"<CR>')
801      feed(':ls<CR>')
802      screen:expect([[
803                                                             |
804        {1:~                                                    }|*9
805        {3:                                                     }|
806        :ls                                                  |
807          1 %a   "[No Name]"                    line 1       |
808        {6:Press ENTER or type command to continue}^              |
809      ]])
810      feed('<F1>')
811      screen:expect([[
812        ^                                                     |
813        {1:~                                                    }|*12
814        TEST                                                 |
815      ]])
816    end)
817  end)
818
819  -- Regression test for #8357
820  it('does not have artifacts after temporary chars in insert mode', function()
821    command('set timeoutlen=10000')
822    command('inoremap jk <esc>')
823    feed('ifooj')
824    screen:expect([[
825      foo^j                                                 |
826      {1:~                                                    }|*12
827      {5:-- INSERT --}                                         |
828    ]])
829    feed('k')
830    screen:expect([[
831      fo^o                                                  |
832      {1:~                                                    }|*12
833                                                           |
834    ]])
835  end)
836end
837
838describe('Screen (char-based)', function()
839  screen_tests(false)
840end)
841
842describe('Screen (line-based)', function()
843  screen_tests(true)
844end)
845
846describe('Screen default colors', function()
847  local screen
848  local function startup(light, termcolors)
849    local extra = (light and ' background=light') or ''
850
851    local nvim_argv = {
852      n.nvim_prog,
853      '-u',
854      'NONE',
855      '-i',
856      'NONE',
857      '-N',
858      '--cmd',
859      'set shortmess+=I noswapfile belloff= noshowcmd noruler' .. extra,
860      '--cmd',
861      'colorscheme vim',
862      '--embed',
863    }
864    local screen_nvim = n.new_session(false, { args = nvim_argv, merge = false })
865    set_session(screen_nvim)
866    screen = Screen.new(53, 14, { rgb = true, ext_termcolors = termcolors or nil })
867  end
868
869  it('are dark per default', function()
870    startup(false, false)
871    screen:expect(function()
872      eq({
873        rgb_bg = 0,
874        rgb_fg = Screen.colors.White,
875        rgb_sp = Screen.colors.Red,
876        cterm_bg = 0,
877        cterm_fg = 0,
878      }, screen.default_colors)
879    end)
880  end)
881
882  it('can be set to light', function()
883    startup(true, false)
884    screen:expect(function()
885      eq({
886        rgb_bg = Screen.colors.White,
887        rgb_fg = 0,
888        rgb_sp = Screen.colors.Red,
889        cterm_bg = 0,
890        cterm_fg = 0,
891      }, screen.default_colors)
892    end)
893  end)
894
895  it('can be handled by external terminal', function()
896    local colors = { rgb_bg = -1, rgb_fg = -1, rgb_sp = -1, cterm_bg = 0, cterm_fg = 0 }
897    startup(false, true)
898    screen:expect(function()
899      eq(colors, screen.default_colors)
900    end)
901
902    startup(true, true)
903    screen:expect(function()
904      eq(colors, screen.default_colors)
905    end)
906  end)
907end)
908
909local screen
910before_each(function()
911  clear()
912  screen = Screen.new()
913end)
914
915it('CTRL-F or CTRL-B scrolls a page after UI attach/resize #20605', function()
916  screen:try_resize(100, 100)
917  eq(100, api.nvim_get_option_value('lines', {}))
918  eq(99, api.nvim_get_option_value('window', {}))
919  eq(99, api.nvim_win_get_height(0))
920  feed('1000o<Esc>')
921  eq(903, fn.line('w0'))
922  feed('<C-B>')
923  eq(806, fn.line('w0'))
924  feed('<C-B>')
925  eq(709, fn.line('w0'))
926  feed('<C-F>')
927  eq(806, fn.line('w0'))
928  feed('<C-F>')
929  eq(903, fn.line('w0'))
930  feed('G')
931  screen:try_resize(50, 50)
932  eq(50, api.nvim_get_option_value('lines', {}))
933  eq(49, api.nvim_get_option_value('window', {}))
934  eq(49, api.nvim_win_get_height(0))
935  eq(953, fn.line('w0'))
936  feed('<C-B>')
937  eq(906, fn.line('w0'))
938  feed('<C-B>')
939  eq(859, fn.line('w0'))
940  feed('<C-F>')
941  eq(906, fn.line('w0'))
942  feed('<C-F>')
943  eq(953, fn.line('w0'))
944end)
945
946it("showcmd doesn't cause empty grid_line with redrawdebug=compositor #22593", function()
947  command('set showcmd redrawdebug=compositor')
948  feed('d')
949  screen:expect([[
950    ^                                                     |
951    {1:~                                                    }|*12
952                                              d          |
953  ]])
954end)
955
956it("scrolling in narrow window doesn't draw over separator #29033", function()
957  screen:try_resize(60, 8)
958  feed('100Oa<Esc>gg')
959  exec([[
960    set number nowrap
961    vsplit
962    set scrollbind
963    wincmd l
964    set scrollbind
965    wincmd |
966  ]])
967  screen:expect([[
968    {8: }│{8:  1 }^a                                                     |
969    {8: }│{8:  2 }a                                                     |
970    {8: }│{8:  3 }a                                                     |
971    {8: }│{8:  4 }a                                                     |
972    {8: }│{8:  5 }a                                                     |
973    {8: }│{8:  6 }a                                                     |
974    {2:< }{3:[No Name] [+]                                             }|
975                                                                |
976  ]])
977  feed('<C-F>')
978  screen:expect([[
979    {8: }│{8:  5 }^a                                                     |
980    {8: }│{8:  6 }a                                                     |
981    {8: }│{8:  7 }a                                                     |
982    {8: }│{8:  8 }a                                                     |
983    {8: }│{8:  9 }a                                                     |
984    {8: }│{8: 10 }a                                                     |
985    {2:< }{3:[No Name] [+]                                             }|
986                                                                |
987  ]])
988end)
989
990it('hidden windows are not redrawn', function()
991  clear()
992  local screen = Screen.new()
993  local opts = { width = 5, height = 5, bufpos = { 0, 0 }, relative = 'win', hide = true }
994  local win = api.nvim_open_win(0, false, opts)
995  local no_redraw = function()
996    vim.o.laststatus = 3
997    local on_win = function(_, winid)
998      _G.did_win = (_G.did_win or 0) + (winid == win and 1 or 0)
999    end
1000    vim.api.nvim_set_decoration_provider(1, { on_win = on_win })
1001    vim.api.nvim__redraw({ flush = true })
1002    return _G.did_win
1003  end
1004  eq(0, exec_lua(no_redraw))
1005  screen:expect([[
1006    ^                                                     |
1007    {1:~                                                    }|*11
1008    {3:[No Name]                                            }|
1009                                                         |
1010  ]])
1011  -- Redrawn properly after unhiding
1012  api.nvim_win_set_config(win, { hide = false })
1013  screen:expect([[
1014    ^                                                     |
1015    {4:     }{1:                                                }|
1016    {11:~    }{1:                                                }|*4
1017    {1:~                                                    }|*6
1018    {3:[No Name]                                            }|
1019                                                         |
1020  ]])
1021end)