Repository: neovim/neovim
File: test/functional/terminal/tui_spec.lua (Lua)

Code before:
    })
    screen:expect([[
      ^                                                  |
      ~                                                 |*3
      {2:Xtest-file1                     0,0-1          All}|
                                                        |
      {5:-- TERMINAL --}                                    |
    ]])
    server_session = n.connect(server_pipe)
    local expr = 'index(v:argv, "-") >= 0 || index(v:argv, "--") >= 0 ? v:true : v:false'
    eq({ true, true }, { server_session:request('nvim_eval', expr) })

    tt.feed_data(":restart put='foo'\013")
    screen:expect([[
                                                        |
      ^foo                                               |
      ~                                                 |*2
      {2:[No Name] [+]                   2,1            All}|
                                                        |
      {5:-- TERMINAL --}                                    |
    ]])
    server_session:close()
    server_session = n.connect(server_pipe)

    eq({ true, false }, { server_session:request('nvim_eval', expr) })
    local has_s = 'index(v:argv, "-s") >= 0 ? v:true : v:false'
    eq({ true, false }, { server_session:request('nvim_eval', has_s) })
    local argv = ({ server_session:request('nvim_eval', 'v:argv') })[2] --[[@type table]]
    eq(13, #argv)
    eq("-c put='foo'", table.concat(argv, ' ', #argv - 1, #argv))
  end)
end)

describe('TUI :connect', function()
  if t.skip(is_os('win'), "relies on :detach which currently doesn't work on windows") then
    return
  end

  local screen_empty = [[
    ^                                                  |
    {100:~                                                 }|*5
                                                      |
  ]]

  it('leaves the current server running', function()
    n.clear()
    finally(function()
      n.check_close()
    end)

    local server1 = new_pipename()

Review comment (refactor):
move this to line 476 and do the check both before and after, like `expr` (which could also be renamed to `has_minmin`?

Code after:
    })
    screen:expect([[
      ^                                                  |
      ~                                                 |*3
      {2:Xtest-file1                     0,0-1          All}|
                                                        |
      {5:-- TERMINAL --}                                    |
    ]])
    server_session = n.connect(server_pipe)
    local expr = 'index(v:argv, "-") >= 0 || index(v:argv, "--") >= 0 ? v:true : v:false'
    local has_s = 'index(v:argv, "-s") >= 0 ? v:true : v:false'
    eq({ true, true }, { server_session:request('nvim_eval', expr) })
    eq({ true, true }, { server_session:request('nvim_eval', has_s) })

    tt.feed_data(":restart put='foo'\013")
    screen:expect([[
                                                        |
      ^foo                                               |
      ~                                                 |*2
      {2:[No Name] [+]                   2,1            All}|
                                                        |
      {5:-- TERMINAL --}                                    |
    ]])
    server_session:close()
    server_session = n.connect(server_pipe)

    eq({ true, false }, { server_session:request('nvim_eval', expr) })
    eq({ true, false }, { server_session:request('nvim_eval', has_s) })
    local argv = ({ server_session:request('nvim_eval', 'v:argv') })[2] --[[@type table]]
    eq(13, #argv)
    eq("-c put='foo'", table.concat(argv, ' ', #argv - 1, #argv))
  end)
end)

describe('TUI :connect', function()
  if t.skip(is_os('win'), "relies on :detach which currently doesn't work on windows") then
    return
  end

  local screen_empty = [[
    ^                                                  |
    {100:~                                                 }|*5
                                                      |
  ]]

  it('leaves the current server running', function()
    n.clear()
    finally(function()
      n.check_close()
    end)