fix: fix and test keyword setting on empty list

This commit is contained in:
Zach Daniel 2024-08-08 10:53:58 -04:00
parent e776b2cb7d
commit 1e1359e255
2 changed files with 33 additions and 1 deletions

View file

@ -191,6 +191,9 @@ defmodule Igniter.Code.Keyword do
{{:__block__, [], [key]}, value}
end
[] ->
{{:__block__, [format: :keyword], [key]}, {:__block__, [], [value]}}
_ ->
{key, value}
end

View file

@ -38,7 +38,7 @@ defmodule Igniter.Project.ConfigTest do
end
@tag :regression
test "it merges the spark formatter plugins" do
test "it sets the spark formatter plugins" do
%{rewrite: rewrite} =
Igniter.new()
|> Igniter.Project.Config.configure(
@ -64,6 +64,35 @@ defmodule Igniter.Project.ConfigTest do
"""
end
@tag :regression
test "it merges the spark formatter plugins" do
%{rewrite: rewrite} =
Igniter.new()
|> Igniter.create_new_file("config/fake.exs", """
import Config
config :spark, formatter: ["Ash.Resource": []]
""")
|> Igniter.Project.Config.configure(
"fake.exs",
:spark,
[:formatter, :"Ash.Resource", :section_order],
[:section],
updater: fn zipper ->
case Igniter.Code.List.prepend_new_to_list(zipper, :section) do
{:ok, zipper} -> {:ok, zipper}
:error -> {:ok, zipper}
end
end
)
config_file = Rewrite.source!(rewrite, "config/fake.exs")
assert Source.get(config_file, :content) == """
import Config
config :spark, formatter: ["Ash.Resource": [section_order: [:section]]]
"""
end
test "it merges with 2 arg version of existing config with a single path item" do
%{rewrite: rewrite} =
Igniter.new()