neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

altscreen_spec.lua (6568B)


      1 local t = require('test.testutil')
      2 local n = require('test.functional.testnvim')()
      3 
      4 local tt = require('test.functional.testterm')
      5 local clear, eq, api = n.clear, t.eq, n.api
      6 local feed = n.feed
      7 local feed_data = tt.feed_data
      8 local enter_altscreen = tt.enter_altscreen
      9 local exit_altscreen = tt.exit_altscreen
     10 
     11 describe(':terminal altscreen', function()
     12  local screen
     13 
     14  before_each(function()
     15    clear()
     16    screen = tt.setup_screen()
     17    feed_data({
     18      'line1',
     19      'line2',
     20      'line3',
     21      'line4',
     22      'line5',
     23      'line6',
     24      'line7',
     25      'line8',
     26      '',
     27    })
     28    screen:expect([[
     29      line4                                             |
     30      line5                                             |
     31      line6                                             |
     32      line7                                             |
     33      line8                                             |
     34      ^                                                  |
     35      {5:-- TERMINAL --}                                    |
     36    ]])
     37    enter_altscreen()
     38    screen:expect([[
     39                                                        |*5
     40      ^                                                  |
     41      {5:-- TERMINAL --}                                    |
     42    ]])
     43    eq(10, api.nvim_buf_line_count(0))
     44  end)
     45 
     46  it('wont clear lines already in the scrollback', function()
     47    feed('<c-\\><c-n>gg')
     48    screen:expect([[
     49      ^tty ready                                         |
     50      line1                                             |
     51      line2                                             |
     52      line3                                             |
     53                                                        |*3
     54    ]])
     55    -- ED 3 is no-op in altscreen
     56    feed_data('\027[3J')
     57    screen:expect_unchanged()
     58  end)
     59 
     60  describe('restores buffer state', function()
     61    local function test_exit_altscreen_restores_buffer_state()
     62      exit_altscreen()
     63      screen:expect([[
     64        line4                                             |
     65        line5                                             |
     66        line6                                             |
     67        line7                                             |
     68        line8                                             |
     69        ^                                                  |
     70        {5:-- TERMINAL --}                                    |
     71      ]])
     72      feed('<c-\\><c-n>gg')
     73      screen:expect([[
     74        ^tty ready                                         |
     75        line1                                             |
     76        line2                                             |
     77        line3                                             |
     78        line4                                             |
     79        line5                                             |
     80                                                          |
     81      ]])
     82    end
     83 
     84    it('after exit', function()
     85      test_exit_altscreen_restores_buffer_state()
     86    end)
     87 
     88    it('after ED 2 and ED 3 and exit', function()
     89      feed_data('\027[H\027[2J\027[3J')
     90      screen:expect([[
     91        ^                                                  |
     92                                                          |*5
     93        {5:-- TERMINAL --}                                    |
     94      ]])
     95      test_exit_altscreen_restores_buffer_state()
     96    end)
     97  end)
     98 
     99  describe('with lines printed after the screen height limit', function()
    100    before_each(function()
    101      feed_data({
    102        'line9',
    103        'line10',
    104        'line11',
    105        'line12',
    106        'line13',
    107        'line14',
    108        'line15',
    109        'line16',
    110        '',
    111      })
    112      screen:expect([[
    113        line12                                            |
    114        line13                                            |
    115        line14                                            |
    116        line15                                            |
    117        line16                                            |
    118        ^                                                  |
    119        {5:-- TERMINAL --}                                    |
    120      ]])
    121    end)
    122 
    123    it('wont modify line count', function()
    124      eq(10, api.nvim_buf_line_count(0))
    125    end)
    126 
    127    it('wont modify lines in the scrollback', function()
    128      feed('<c-\\><c-n>gg')
    129      screen:expect([[
    130        ^tty ready                                         |
    131        line1                                             |
    132        line2                                             |
    133        line3                                             |
    134        line12                                            |
    135        line13                                            |
    136                                                          |
    137      ]])
    138    end)
    139  end)
    140 
    141  describe('after height is decreased by 2', function()
    142    local function wait_removal()
    143      screen:try_resize(screen._width, screen._height - 2)
    144      screen:expect([[
    145                                                          |*2
    146        rows: 4, cols: 50                                 |
    147        ^                                                  |
    148        {5:-- TERMINAL --}                                    |
    149      ]])
    150    end
    151 
    152    it('removes 2 lines from the bottom of the visible buffer', function()
    153      wait_removal()
    154      feed('<c-\\><c-n>4k')
    155      screen:expect([[
    156        ^                                                  |
    157                                                          |*2
    158        rows: 4, cols: 50                                 |
    159                                                          |
    160      ]])
    161      eq(9, api.nvim_buf_line_count(0))
    162    end)
    163 
    164    describe('and after exit', function()
    165      before_each(function()
    166        wait_removal()
    167        exit_altscreen()
    168      end)
    169 
    170      it('restore buffer state', function()
    171        screen:expect(t.is_os('win') and [[
    172          line6                                             |
    173          line7                                             |
    174          line8                                             |
    175          ^                                                  |
    176          {5:-- TERMINAL --}                                    |
    177        ]] or [[
    178          line5                                             |
    179          line6                                             |
    180          line7                                             |
    181          ^line8                                             |
    182          {5:-- TERMINAL --}                                    |
    183        ]])
    184      end)
    185    end)
    186  end)
    187 end)