Skip to content

Commit

Permalink
test: find_config and config param
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmh committed May 16, 2023
1 parent 9c58bb1 commit 0e9c586
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions custom-dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ nvim
readfile
writefile
bufname
luassert
realpath
5 changes: 5 additions & 0 deletions lua/cspell/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ M.set_word = function(diagnostic, new_word)
)
end

M.clear_cache = function()
PATH_BY_CWD = {}
CONFIG_INFO_BY_CWD = {}
end

return M

---@class Diagnostic
Expand Down
50 changes: 50 additions & 0 deletions tests/spec/diagnostics_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ local diagnostics = require("cspell.diagnostics")
local code_actions = require("cspell.code_actions")
local helpers = require("cspell.helpers")

local uv = vim.loop

local CSPELL_CONFIG_PATH = uv.fs_realpath("./cspell.json")

mock(require("null-ls.logger"), true)

describe("diagnostics", function()
Expand Down Expand Up @@ -49,12 +53,16 @@ describe("diagnostics", function()

describe("without code actions", function()
before_each(function()
helpers.clear_cache()
async_get_config_info = stub(helpers, "async_get_config_info")
get_source = stub(require("null-ls.sources"), "get")
get_source.returns({})
args = args_fn({
ft = "lua",
bufname = "file.txt",
get_config = function()
return {}
end,
})
end)

Expand All @@ -69,6 +77,8 @@ describe("diagnostics", function()

it("does not include a suggestions param", function()
assert.same({
"-c",
CSPELL_CONFIG_PATH,
"lint",
"--language-id",
"lua",
Expand All @@ -79,6 +89,7 @@ describe("diagnostics", function()

describe("with code actions", function()
before_each(function()
helpers.clear_cache()
async_get_config_info = stub(helpers, "async_get_config_info")
get_source = stub(require("null-ls.sources"), "get")
get_source.returns({ code_actions })
Expand All @@ -103,6 +114,45 @@ describe("diagnostics", function()
it("includes a suggestions param", function()
assert.same({
"--show-suggestions",
"-c",
CSPELL_CONFIG_PATH,
"lint",
"--language-id",
"lua",
"stdin://file.txt",
}, args)
end)
end)

describe("with custom json config file", function()
before_each(function()
helpers.clear_cache()
async_get_config_info = stub(helpers, "async_get_config_info")
get_source = stub(require("null-ls.sources"), "get")
get_source.returns({})
end)

after_each(function()
get_source:revert()
async_get_config_info:revert()
end)

it("includes a suggestions param", function()
args = args_fn({
ft = "lua",
bufname = "file.txt",
get_config = function()
return {
find_json = function()
return "some/custom/path/cspell.json"
end,
}
end,
})

assert.same({
"-c",
"some/custom/path/cspell.json",
"lint",
"--language-id",
"lua",
Expand Down

0 comments on commit 0e9c586

Please sign in to comment.