summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMicah Halter <micah@mehalter.com>2024-07-01 13:58:55 -0400
committerGitHub <noreply@github.com>2024-07-01 10:58:55 -0700
commitcd75be867f2331b22905f47d28c0c270a69466aa (patch)
tree026bb2bd83bacad4e12e590b67073d4472197733 /tests
parentfc19dfc0e7d0f5e9f01cd42a4c518e030b3790f0 (diff)
feat(shfmt): add automatic indentation detection (#481)
* feat(shfmt): automatically detect indentation * fix(markdown-toc): improve correctness of indentation size calculation * fix(djlint): improve correctness of indentation size calculation * feat: add effective `shiftwidth` to `conform.Context` this also refactors formatters that automatically set indentation level to use the new shiftwidth context
Diffstat (limited to 'tests')
-rw-r--r--tests/runner_spec.lua35
1 files changed, 30 insertions, 5 deletions
diff --git a/tests/runner_spec.lua b/tests/runner_spec.lua
index 8c0dadf..5d4fea4 100644
--- a/tests/runner_spec.lua
+++ b/tests/runner_spec.lua
@@ -59,11 +59,36 @@ describe("runner", function()
local config = assert(conform.get_formatter_config("test"))
local ctx = runner.build_context(0, config)
local filename = vim.api.nvim_buf_get_name(bufnr)
- assert.are.same({
- buf = bufnr,
- filename = filename,
- dirname = vim.fs.dirname(filename),
- }, ctx)
+ assert.equal(bufnr, ctx.buf)
+ assert.equal(filename, ctx.filename)
+ assert.equal(vim.fs.dirname(filename), ctx.dirname)
+ end)
+
+ it("sets the shiftwidth to shiftwidth", function()
+ vim.cmd.edit({ args = { "README.md" } })
+ local bufnr = vim.api.nvim_get_current_buf()
+ vim.bo[bufnr].shiftwidth = 7
+ conform.formatters.test = {
+ meta = { url = "", description = "" },
+ command = "echo",
+ }
+ local config = assert(conform.get_formatter_config("test"))
+ local ctx = runner.build_context(0, config)
+ assert.equal(7, ctx.shiftwidth)
+ end)
+
+ it("sets the shiftwidth to tabstop as fallback", function()
+ vim.cmd.edit({ args = { "README.md" } })
+ local bufnr = vim.api.nvim_get_current_buf()
+ vim.bo[bufnr].shiftwidth = 0
+ vim.bo[bufnr].tabstop = 3
+ conform.formatters.test = {
+ meta = { url = "", description = "" },
+ command = "echo",
+ }
+ local config = assert(conform.get_formatter_config("test"))
+ local ctx = runner.build_context(0, config)
+ assert.equal(3, ctx.shiftwidth)
end)
it("sets temp file when stdin = false", function()