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

Code before:
    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),
        })
        return vim.diagnostic.status()
      end)

      eq(result, 'E:1 W:2 I:3 H:4')
    end)

    it('does not return diagnostics for non current buffers', 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_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),
        })
        return vim.diagnostic.status()
      end)

      eq(result, '')
    end)

    it('uses text from diagnostic.config().signs.text[severity]', function()
      local result = exec_lua(function()
        vim.diagnostic.config({

Review comment (suggestion):
instead of a separate test for this case, let's just add an extra step to the end of the one above, something like `enew` followed by `eq('', exec_lua(return vim.diagnostic.status()`.

that saves 20 lines of code, which is valuable.

Code after:
        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(
            msg,
            '^[^:]+:(%d+):(.+)$',
            { 'lnum', 'message' },
            nil,
            { severity = vim.diagnostic.severity.INFO }
          )
        end)
      )
    end)

    it('accepts a severity map', function()
      local msg = '46:FATAL:Et tu, Brute?'
      local diagnostic = {
        severity = exec_lua [[return vim.diagnostic.severity.ERROR]],
        lnum = 45,
        col = 0,
        end_lnum = 45,
        end_col = 0,
        message = 'Et tu, Brute?',
      }
      eq(
        diagnostic,
        exec_lua(function()
          return vim.diagnostic.match(
            msg,
            '^(%d+):(%w+):(.+)$',
            { 'lnum', 'severity', 'message' },
            { FATAL = vim.diagnostic.severity.ERROR }
          )
        end)
      )
    end)
  end)