neovim

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

normal_spec.lua (5196B)


      1 local t = require('test.testutil')
      2 local n = require('test.functional.testnvim')()
      3 local Screen = require('test.functional.ui.screen')
      4 
      5 local clear = n.clear
      6 local exec = n.exec
      7 local feed = n.feed
      8 local api = n.api
      9 local eq = t.eq
     10 local fn = n.fn
     11 
     12 describe('normal', function()
     13  local screen
     14 
     15  before_each(function()
     16    clear()
     17    screen = Screen.new(40, 19)
     18  end)
     19 
     20  -- oldtest: Test_normal_j_below_botline()
     21  it([[no skipped lines with "j" scrolling below botline and 'foldmethod' not "manual"]], function()
     22    exec([[
     23      set number foldmethod=diff scrolloff=0
     24      call setline(1, map(range(1, 9), 'repeat(v:val, 200)'))
     25      norm Lj
     26    ]])
     27    screen:expect([[
     28      {8:  2 }222222222222222222222222222222222222|
     29      {8:    }222222222222222222222222222222222222|*4
     30      {8:    }22222222222222222222                |
     31      {8:  3 }333333333333333333333333333333333333|
     32      {8:    }333333333333333333333333333333333333|*4
     33      {8:    }33333333333333333333                |
     34      {8:  4 }^444444444444444444444444444444444444|
     35      {8:    }444444444444444444444444444444444444|*4
     36      {8:    }44444444444444444444                |
     37                                              |
     38    ]])
     39  end)
     40 
     41  -- oldtest: Test_single_line_scroll()
     42  it('(Half)-page scroll up or down reveals virtual lines #19605, #27967', function()
     43    fn.setline(1, 'foobar one two three')
     44    exec('set smoothscroll')
     45    local ns = api.nvim_create_namespace('')
     46    api.nvim_buf_set_extmark(0, ns, 0, 0, {
     47      virt_lines = { { { '---', 'IncSearch' } } },
     48      virt_lines_above = true,
     49    })
     50    -- Nvim: not actually necessary to scroll down to hide the virtual line.
     51    -- Check topfill instead of skipcol and show the screen state.
     52    feed('<C-E>')
     53    eq(0, fn.winsaveview().topfill)
     54    local s1 = [[
     55      ^foobar one two three                    |
     56      {1:~                                       }|*17
     57                                              |
     58    ]]
     59    screen:expect(s1)
     60    feed('<C-B>')
     61    eq(1, fn.winsaveview().topfill)
     62    local s2 = [[
     63      {2:---}                                     |
     64      ^foobar one two three                    |
     65      {1:~                                       }|*16
     66                                              |
     67    ]]
     68    screen:expect(s2)
     69    feed('<C-E>')
     70    eq(0, fn.winsaveview().topfill)
     71    screen:expect(s1)
     72    feed('<C-U>')
     73    eq(1, fn.winsaveview().topfill)
     74    screen:expect(s2)
     75 
     76    -- Nvim: also test virt_lines below the last line
     77    feed('yy100pG<C-L>')
     78    api.nvim_buf_set_extmark(0, ns, 100, 0, { virt_lines = { { { '---', 'IncSearch' } } } })
     79    screen:expect({
     80      grid = [[
     81        foobar one two three                    |*17
     82        ^foobar one two three                    |
     83                                                |
     84      ]],
     85    })
     86    feed('<C-F>')
     87    screen:expect({
     88      grid = [[
     89        ^foobar one two three                    |
     90        {2:---}                                     |
     91        {1:~                                       }|*16
     92                                                |
     93      ]],
     94    })
     95    feed('ggG<C-D>')
     96    screen:expect({
     97      grid = [[
     98        foobar one two three                    |*16
     99        ^foobar one two three                    |
    100        {2:---}                                     |
    101                                                |
    102      ]],
    103    })
    104  end)
    105 
    106  -- oldtest: Test_normal_gm()
    107  it('gm sets curswant correctly', function()
    108    screen:try_resize(75, 10)
    109    exec([[
    110      call setline(1, repeat(["  abcd\tefgh\tij"], 10))
    111      call cursor(1, 1)
    112    ]])
    113    feed('jVjzf')
    114    -- gm
    115    feed('gmk')
    116    eq(18, fn.virtcol('.'))
    117    -- g0
    118    feed('gj0k')
    119    eq(1, fn.virtcol('.'))
    120    -- g^
    121    feed('jg^k')
    122    eq(3, fn.virtcol('.'))
    123    exec('call cursor(10, 1)')
    124    -- gm
    125    feed('gmk')
    126    eq(18, fn.virtcol('.'))
    127    -- g0
    128    feed('gj0k')
    129    eq(1, fn.virtcol('.'))
    130    -- g^
    131    feed('jg^k')
    132    eq(3, fn.virtcol('.'))
    133  end)
    134 
    135  -- oldtest: Test_pos_percentage_in_turkish_locale()
    136  it('viewport position percentage in Turkish locale', function()
    137    t.skip(not t.translations_enabled(), 'Nvim not built with ENABLE_TRANSLATIONS')
    138    t.skip(not pcall(exec, 'lang tr_TR.UTF-8'), 'Turkish locale not available')
    139 
    140    local build_dir = t.paths.test_build_dir
    141    local locale_dir = build_dir .. '/share/locale/tr/LC_MESSAGES'
    142 
    143    fn.mkdir(locale_dir, 'p')
    144    fn.filecopy(build_dir .. '/src/nvim/po/tr.mo', locale_dir .. '/nvim.mo')
    145    finally(function()
    146      n.rmdir(vim.fs.dirname(locale_dir))
    147    end)
    148 
    149    clear({ env = { LANG = 'tr_TR.UTF-8' } })
    150    screen = Screen.new(75, 5)
    151    exec('set ruler')
    152    exec('lang tr_TR.UTF-8')
    153    exec('put =range(1,40)')
    154    exec('5')
    155    screen:expect([[
    156      3                                                                          |
    157      ^4                                                                          |
    158      5                                                                          |
    159      6                                                                          |
    160      40 more lines                                            5,1            %8 |
    161    ]])
    162  end)
    163 end)