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

Code before:
    it('works', function()
      local result = exec_lua(function()
        vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, {
          _G.make_error('Error 1', 0, 1, 0, 1),
          _G.make_error('Error 2', 1, 1, 1, 1),
          _G.make_warning('Warning', 2, 2, 2, 2),
        })

        local diagnostics = vim.diagnostic.get(_G.diagnostic_bufnr)
        vim.fn.setqflist(vim.diagnostic.toqflist(diagnostics))
        local list = vim.fn.getqflist()
        local new_diagnostics = vim.diagnostic.fromqflist(list)

        -- Remove namespace since it isn't present in the return value of
        -- fromlist()
        for _, v in ipairs(diagnostics) do
          v.namespace = nil
        end

        return { diagnostics, new_diagnostics }
      end)
      eq(result[1], result[2])
    end)
  end)

  describe('status', function()
    it('returns empty string if no diagnostics', function()
      local result = exec_lua(function()
        vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, {})
        return vim.diagnostic.status()
      end)

      eq(result, '')
    end)

    it('returns count for each diagnostic kind', function()
      local result = exec_lua(function()
        vim.diagnostic.set(_G.diagnostic_ns, 0, {
          _G.make_error('Error 1', 0, 1, 0, 1),

          _G.make_warning('Warning 1', 2, 2, 2, 2),
          _G.make_warning('Warning 2', 2, 2, 2, 2),

          _G.make_info('Info 1', 3, 3, 3, 3),
          _G.make_info('Info 2', 3, 3, 3, 3),
          _G.make_info('Info 3', 3, 3, 3, 3),

          _G.make_hint('Hint 1', 4, 4, 4, 4),
          _G.make_hint('Hint 2', 4, 4, 4, 4),
          _G.make_hint('Hint 3', 4, 4, 4, 4),
          _G.make_hint('Hint 4', 4, 4, 4, 4),

Review comment (suggestion):
```suggestion
  describe('status()', function()
```

Code after:
      eq('foo_ls: Error', qf_list[1].text)
    end)
  end)

  describe('match()', function()
    it('matches a string', function()
      local msg = 'ERROR: george.txt:19:84:Two plus two equals five'
      local diagnostic = {
        severity = exec_lua [[return vim.diagnostic.severity.ERROR]],
        lnum = 18,
        col = 83,
        end_lnum = 18,
        end_col = 83,
        message = 'Two plus two equals five',
      }
      eq(
        diagnostic,
        exec_lua(function()
          return vim.diagnostic.match(
            msg,
            '^(%w+): [^:]+:(%d+):(%d+):(.+)$',
            { 'severity', 'lnum', 'col', 'message' }
          )
        end)
      )
    end)

    it('returns nil if the pattern fails to match', function()
      eq(
        nil,
        exec_lua(function()
          local msg = 'The answer to life, the universe, and everything is'
          return vim.diagnostic.match(msg, 'This definitely will not match', {})
        end)
      )
    end)

    it('respects default values', function()
      local msg = 'anna.txt:1:Happy families are all alike'
      local diagnostic = {
        severity = exec_lua [[return vim.diagnostic.severity.INFO]],
        lnum = 0,
        col = 0,
        end_lnum = 0,
        end_col = 0,
        message = 'Happy families are all alike',
      }
      eq(
        diagnostic,
        exec_lua(function()
          return vim.diagnostic.match(