mirror of
https://github.com/ash-project/igniter.git
synced 2024-09-20 13:33:00 +12:00
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:
parent
99ac8f0582
commit
57288d32ec
3 changed files with 49 additions and 2 deletions
|
@ -57,6 +57,7 @@ defmodule Igniter.Common do
|
||||||
|> Zipper.subtree()
|
|> Zipper.subtree()
|
||||||
|> Zipper.root()
|
|> Zipper.root()
|
||||||
|> Sourceror.to_string()
|
|> Sourceror.to_string()
|
||||||
|
|> then(&"==code==\n#{&1}\n==code==\n")
|
||||||
|> IO.puts()
|
|> IO.puts()
|
||||||
|
|
||||||
zipper
|
zipper
|
||||||
|
@ -539,8 +540,10 @@ defmodule Igniter.Common do
|
||||||
|> Zipper.subtree()
|
|> Zipper.subtree()
|
||||||
|> Zipper.root()
|
|> Zipper.root()
|
||||||
|> case do
|
|> case do
|
||||||
{:__block__, _, [_]} ->
|
{:__block__, _, _} ->
|
||||||
Zipper.down(zipper)
|
zipper
|
||||||
|
|> Zipper.down()
|
||||||
|
|> maybe_move_to_block()
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
zipper
|
zipper
|
||||||
|
|
|
@ -4,6 +4,25 @@ defmodule Igniter.Module do
|
||||||
Module.concat(module_name_prefix(), suffix)
|
Module.concat(module_name_prefix(), suffix)
|
||||||
end
|
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
|
def module_name_prefix do
|
||||||
Mix.Project.get!()
|
Mix.Project.get!()
|
||||||
|> Module.split()
|
|> Module.split()
|
||||||
|
|
|
@ -33,6 +33,31 @@ defmodule Igniter.ConfigTest do
|
||||||
"""
|
"""
|
||||||
end
|
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
|
test "it merges with 2 arg version of existing config with a single path item" do
|
||||||
%{rewrite: rewrite} =
|
%{rewrite: rewrite} =
|
||||||
Igniter.new()
|
Igniter.new()
|
||||||
|
|
Loading…
Reference in a new issue