HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //home/ubuntu/neovim/test/functional/ui/mode_spec.lua
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')

local clear, feed, insert = n.clear, n.feed, n.insert
local command = n.command
local retry = t.retry

describe('ui mode_change event', function()
  local screen

  before_each(function()
    clear()
    screen = Screen.new(25, 4)
    screen:attach({ rgb = true })
  end)

  it('works in normal mode', function()
    screen:expect {
      grid = [[
      ^                         |
      {1:~                        }|*2
                               |
    ]],
      mode = 'normal',
    }

    feed('d')
    screen:expect {
      grid = [[
      ^                         |
      {1:~                        }|*2
                               |
    ]],
      mode = 'operator',
    }

    feed('<esc>')
    screen:expect {
      grid = [[
      ^                         |
      {1:~                        }|*2
                               |
    ]],
      mode = 'normal',
    }
  end)

  -- oldtest: Test_mouse_shape_after_failed_change()
  it('is restored to Normal mode after failed "c"', function()
    screen:try_resize(50, 4)
    command('set nomodifiable')

    feed('c')
    screen:expect {
      grid = [[
      ^                                                  |
      {1:~                                                 }|*2
                                                        |
    ]],
      mode = 'operator',
    }

    feed('c')
    screen:expect {
      grid = [[
      ^                                                  |
      {1:~                                                 }|*2
      {9:E21: Cannot make changes, 'modifiable' is off}     |
    ]],
      mode = 'normal',
    }
  end)

  -- oldtest: Test_mouse_shape_after_cancelling_gr()
  it('is restored to Normal mode after cancelling "gr"', function()
    feed('gr')
    screen:expect {
      grid = [[
      ^                         |
      {1:~                        }|*2
                               |
    ]],
      mode = 'replace',
    }

    feed('<Esc>')
    screen:expect {
      grid = [[
      ^                         |
      {1:~                        }|*2
                               |
    ]],
      mode = 'normal',
    }
  end)

  it('works in insert mode', function()
    feed('i')
    screen:expect {
      grid = [[
      ^                         |
      {1:~                        }|*2
      {5:-- INSERT --}             |
    ]],
      mode = 'insert',
    }

    feed('word<esc>')
    screen:expect {
      grid = [[
      wor^d                     |
      {1:~                        }|*2
                               |
    ]],
      mode = 'normal',
    }

    local matchtime = 0
    command('set showmatch')
    retry(nil, nil, function()
      matchtime = matchtime + 1
      local screen_timeout = 1000 * matchtime -- fail faster for retry.

      command('set matchtime=' .. matchtime) -- tenths of seconds
      feed('a(stuff')
      screen:expect {
        grid = [[
        word(stuff^               |
        {1:~                        }|*2
        {5:-- INSERT --}             |
      ]],
        mode = 'insert',
        timeout = screen_timeout,
      }

      feed(')')
      screen:expect {
        grid = [[
        word^(stuff)              |
        {1:~                        }|*2
        {5:-- INSERT --}             |
      ]],
        mode = 'showmatch',
        timeout = screen_timeout,
      }

      screen:expect {
        grid = [[
        word(stuff)^              |
        {1:~                        }|*2
        {5:-- INSERT --}             |
      ]],
        mode = 'insert',
        timeout = screen_timeout,
      }
    end)
  end)

  it('works in replace mode', function()
    feed('R')
    screen:expect {
      grid = [[
      ^                         |
      {1:~                        }|*2
      {5:-- REPLACE --}            |
    ]],
      mode = 'replace',
    }

    feed('word<esc>')
    screen:expect {
      grid = [[
      wor^d                     |
      {1:~                        }|*2
                               |
    ]],
      mode = 'normal',
    }
  end)

  it('works in cmdline mode', function()
    feed(':')
    screen:expect {
      grid = [[
                               |
      {1:~                        }|*2
      :^                        |
    ]],
      mode = 'cmdline_normal',
    }

    feed('x<left>')
    screen:expect {
      grid = [[
                               |
      {1:~                        }|*2
      :^x                       |
    ]],
      mode = 'cmdline_insert',
    }

    feed('<insert>')
    screen:expect {
      grid = [[
                               |
      {1:~                        }|*2
      :^x                       |
    ]],
      mode = 'cmdline_replace',
    }

    feed('<right>')
    screen:expect {
      grid = [[
                               |
      {1:~                        }|*2
      :x^                       |
    ]],
      mode = 'cmdline_normal',
    }

    feed('<esc>')
    screen:expect {
      grid = [[
      ^                         |
      {1:~                        }|*2
                               |
    ]],
      mode = 'normal',
    }
  end)

  it('works in visual mode', function()
    insert('text')
    feed('v')
    screen:expect {
      grid = [[
      tex^t                     |
      {1:~                        }|*2
      {5:-- VISUAL --}             |
    ]],
      mode = 'visual',
    }

    feed('<esc>')
    screen:expect {
      grid = [[
      tex^t                     |
      {1:~                        }|*2
                               |
    ]],
      mode = 'normal',
    }

    command('set selection=exclusive')
    feed('v')
    screen:expect {
      grid = [[
      tex^t                     |
      {1:~                        }|*2
      {5:-- VISUAL --}             |
    ]],
      mode = 'visual_select',
    }

    feed('<esc>')
    screen:expect {
      grid = [[
      tex^t                     |
      {1:~                        }|*2
                               |
    ]],
      mode = 'normal',
    }
  end)
end)