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

Code before:
    write_file(testdir .. '/spell/en.ascii.spl', spellheader:sub(1, -3) .. '\000\000')
    api.nvim_set_option_value('spelllang', 'en', {})
    eq('Vim(set):E757: This does not look like a spell file', exc_exec('set spell'))
  end)

  it('can be set to a relative path', function()
    local fname = testdir .. '/spell/spell.add'
    api.nvim_set_option_value('spellfile', fname, {})
  end)

  it('can be set to an absolute path', function()
    local fname = fn.fnamemodify(testdir .. '/spell/spell.add', ':p')
    api.nvim_set_option_value('spellfile', fname, {})
  end)

  describe('default location', function()
    it("is stdpath('data')/spell/en.utf-8.add", function()
      n.command('set spell')
      n.insert('abc')
      n.feed('zg')
      eq(testdir .. '/xdg_data/nvim/spell/en.utf-8.add', api.nvim_get_option_value('spellfile', {}))
    end)

    it("is not set if stdpath('data') is not writable", function()
      n.command('set spell')
      vim.uv.fs_mkdir(testdir .. '/xdg_data', 444)
      n.insert('abc')
      eq("Vim(normal):E764: Option 'spellfile' is not set", exc_exec('normal! zg'))
    end)

    it("is not set if 'spelllang' is not set", function()
      n.command('set spell spelllang=')
      n.insert('abc')
      eq("Vim(normal):E764: Option 'spellfile' is not set", exc_exec('normal! zg'))
    end)
  end)
end)


Review comment (bug):
I think chmod 444 isn't possible on Windows. Instead, to make this test work on windows, try overwriting `.../xdg_data` with a file instead of a directory. That should hopefully "fail" correctly.

If that doesn't work, then use `t.is_os('win')` to `return` from this test (don't use `skip()` because it's not possible to ever "fix" this).

Code after:
    write_file(testdir .. '/spell/en.ascii.spl', spellheader:sub(1, -3) .. '\000\000')
    api.nvim_set_option_value('spelllang', 'en', {})
    eq('Vim(set):E757: This does not look like a spell file', exc_exec('set spell'))
  end)

  it('can be set to a relative path', function()
    local fname = testdir .. '/spell/spell.add'
    api.nvim_set_option_value('spellfile', fname, {})
  end)

  it('can be set to an absolute path', function()
    local fname = fn.fnamemodify(testdir .. '/spell/spell.add', ':p')
    api.nvim_set_option_value('spellfile', fname, {})
  end)

  describe('default location', function()
    it("is stdpath('data')/spell/en.utf-8.add", function()
      n.command('set spell')
      n.insert('abc')
      n.feed('zg')
      eq(
        t.fix_slashes(fn.stdpath('data') .. '/spell/en.utf-8.add'),
        t.fix_slashes(api.nvim_get_option_value('spellfile', {}))
      )
    end)

    it("is not set if stdpath('data') is not writable", function()
      n.command('set spell')
      fn.writefile({ '' }, testdir .. '/xdg_data')
      n.insert('abc')
      eq("Vim(normal):E764: Option 'spellfile' is not set", exc_exec('normal! zg'))
    end)

    it("is not set if 'spelllang' is not set", function()
      n.command('set spell spelllang=')
      n.insert('abc')
      eq("Vim(normal):E764: Option 'spellfile' is not set", exc_exec('normal! zg'))
    end)
  end)
end)