improvement: more module helpers

test: add regression test
improvement: wrap code in `==code==` so you can tell what is being `puts`
This commit is contained in:
Zach Daniel 2024-06-02 16:05:31 -04:00
parent 99ac8f0582
commit 57288d32ec
3 changed files with 49 additions and 2 deletions

View file

@ -57,6 +57,7 @@ defmodule Igniter.Common do
|> Zipper.subtree()
|> Zipper.root()
|> Sourceror.to_string()
|> then(&"==code==\n#{&1}\n==code==\n")
|> IO.puts()
zipper
@ -539,8 +540,10 @@ defmodule Igniter.Common do
|> Zipper.subtree()
|> Zipper.root()
|> case do
{:__block__, _, [_]} ->
Zipper.down(zipper)
{:__block__, _, _} ->
zipper
|> Zipper.down()
|> maybe_move_to_block()
_ ->
zipper

View file

@ -4,6 +4,25 @@ defmodule Igniter.Module do
Module.concat(module_name_prefix(), suffix)
end
def proper_location(module_name) do
path =
module_name
|> Module.split()
|> Enum.map(&to_string/1)
|> Enum.map(&Macro.underscore/1)
last = List.last(path)
leading = :lists.droplast(path)
Path.join(["lib" | leading] ++ ["#{last}.ex"])
end
def parse(module_name) do
module_name
|> String.split(".")
|> Module.concat()
end
def module_name_prefix do
Mix.Project.get!()
|> Module.split()

View file

@ -33,6 +33,31 @@ defmodule Igniter.ConfigTest do
"""
end
@tag :regression
test "it merges the spark formatter plugins" do
%{rewrite: rewrite} =
Igniter.new()
|> Igniter.Config.configure(
"fake.exs",
:spark,
[:formatter, :"Ash.Resource"],
[],
fn x ->
x
end
)
|> Igniter.Config.configure("fake.exs", :spark, [:formatter, :"Ash.Domain"], [], fn x ->
x
end)
config_file = Rewrite.source!(rewrite, "config/fake.exs")
assert Source.get(config_file, :content) == """
import Config
config :spark, formatter: ["Ash.Domain": [], "Ash.Resource": []]
"""
end
test "it merges with 2 arg version of existing config with a single path item" do
%{rewrite: rewrite} =
Igniter.new()