Skip to content

Commit

Permalink
fix(config): process modes in correct order. Fixes #50 again
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jun 24, 2023
1 parent 7b58c5b commit 919cbe4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lua/flash/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,13 @@ function M.get(...)
---@type Flash.Config?
local opts = select(i, ...)
if opts then
local mopts = opts
while mopts.mode and not modes[mopts.mode] do
modes[mopts.mode] = true
mopts = options.modes[mopts.mode] or {}
all[#all + 1] = mopts
table.insert(all, opts)
local idx = #all
while opts.mode and not modes[opts.mode] do
modes[opts.mode] = true
opts = options.modes[opts.mode] or {}
table.insert(all, idx, opts)
end
all[#all + 1] = opts
end
end

Expand Down
13 changes: 13 additions & 0 deletions tests/config_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,17 @@ describe("config", function()
assert.is_true(Config.get({ mode = "foo" }).field)
assert.is_true(Config.get({ mode = "bar" }).field)
end)

it("processes modes recursively in correct order", function()
Config.setup({
modes = {
a = { mode = "b", v = "a" },
b = { mode = "c", v = "b" },
c = { v = "c" },
},
})
assert.same("d", Config.get({ mode = "a", v = "d" }).v)
assert.same("a", Config.get({ mode = "a" }).v)
assert.same("b", Config.get({ mode = "b" }).v)
end)
end)

0 comments on commit 919cbe4

Please sign in to comment.