Skip to content

Commit

Permalink
test fixes, formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ckoch-cars committed Jul 20, 2022
1 parent 3af8539 commit a5a1c68
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions lib/ex_factor/extractor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ defmodule ExFactor.Extractor do
list = String.split(module_contents, "\n")
{:ok, ast} = Code.string_to_quoted(module_contents, token_metadata: true)

{:defmodule, [do: [line: _begin_line], end: [line: end_line], closing: _, line: _], _} =
ast
{:defmodule, do_metadata, _} = ast
[line: end_line] = Keyword.fetch!(do_metadata, :end)

insert_code(list, end_line, string_fns, target_path, target_module, dry_run)
end
Expand Down
6 changes: 3 additions & 3 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ defmodule ExFactor.MixProject do
@name "ExFactor"
@source_url "https://github.com/ckochx/ex_factor"
@version "VERSION"
|> File.read!()
|> String.trim()
|> File.read!()
|> String.trim()

def project do
[
Expand Down Expand Up @@ -56,7 +56,7 @@ defmodule ExFactor.MixProject do
logo: "assets/X.jpg",
source_ref: "v#{@version}",
source_url: @source_url,
main: @name,
main: @name
# extras: [
# "CHANGELOG.md"
# ]
Expand Down
28 changes: 14 additions & 14 deletions test/ex_factor/extractor_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ defmodule ExFactor.ExtractorTest do
]

Extractor.emplace(opts)

file = File.read!(target_path)
assert file =~ "def(pub1(arg1))"
assert file =~ "defmodule(ExFactor.NewMod) do"

assert file =~ "def pub1(arg1) do"
assert file =~ "defmodule ExFactor.NewMod do"
# includes additional attrs
assert file =~ "@spec(pub1(term()) :: term())"
assert file =~ "@somedoc(\"This is somedoc\")"
assert file =~ "@spec pub1(term()) :: term()"
assert file =~ "@somedoc \"This is somedoc\""
# assert the added elements get flattened correctly
refute file =~ "[@somedoc(\"This is somedoc\"), "
refute file =~ "[@somedoc \"This is somedoc\", "
# comments don't get moved
refute file =~ "# a comment and no aliases"
File.rm("test/tmp/source_module.ex")
Expand Down Expand Up @@ -102,8 +102,8 @@ defmodule ExFactor.ExtractorTest do
Extractor.emplace(opts)

file = File.read!(target_path)
assert file =~ "def(pub1(arg1))"
assert file =~ "@moduledoc(\"This module created with ExFactor\")"
assert file =~ "def pub1(arg1)"
assert file =~ "@moduledoc \"This module created with ExFactor\""
end

test " with dry_run option, don't write the file." do
Expand Down Expand Up @@ -163,8 +163,8 @@ defmodule ExFactor.ExtractorTest do
Extractor.emplace(opts)

file = File.read!("lib/ex_factor/tmp/target_module.ex")
assert file =~ "def(pub1(arg1))"
assert file =~ "defmodule(ExFactor.Tmp.TargetModule) do"
assert file =~ "def pub1(arg1)"
assert file =~ "defmodule ExFactor.Tmp.TargetModule do"
end

test "write the function into an existing module" do
Expand Down Expand Up @@ -201,7 +201,7 @@ defmodule ExFactor.ExtractorTest do
Extractor.emplace(opts)

file = File.read!("lib/ex_factor/tmp/target_module.ex")
assert file =~ "def(refactor1(arg1)) do"
assert file =~ "def refactor1(arg1) do"
assert file =~ "def pub_exists(arg_exists) do"
assert file =~ "defmodule ExFactor.Tmp.TargetModule do"
end
Expand Down Expand Up @@ -243,7 +243,7 @@ defmodule ExFactor.ExtractorTest do
Extractor.emplace(opts)

file = File.read!("lib/ex_factor/tmp/target_module.ex")
assert file =~ "def(refactor1(arg1)) do"
assert file =~ "def refactor1(arg1) do"
assert file =~ "def pub_exists(arg_exists) do"
assert file =~ "def pub_exists(:error) do"
assert file =~ "defmodule ExFactor.Tmp.TargetModule do"
Expand Down Expand Up @@ -291,8 +291,8 @@ defmodule ExFactor.ExtractorTest do
Extractor.emplace(opts)

file = File.read!("lib/ex_factor/tmp/target_module.ex")
assert file =~ "def(refactor1(arg1)) do"
assert file =~ "def(refactor1([])) do"
assert file =~ "def refactor1(arg1) do"
assert file =~ "def refactor1([]) do"
assert file =~ " @doc \"some docs\""
end

Expand Down
8 changes: 4 additions & 4 deletions test/ex_factor_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ defmodule ExFactorTest do
%{additions: _, changes: _, removals: _} = _results = ExFactor.refactor(opts)

file = File.read!("lib/ex_factor/tmp/target_module.ex")
assert file =~ "def(refactor1(arg1)) do"
assert file =~ "def(refactor1([])) do"
assert file =~ "def refactor1(arg1) do"
assert file =~ "def refactor1([]) do"
assert file =~ " @doc \"some docs\""
assert file =~ "def pub_exists(arg_exists) do"

Expand Down Expand Up @@ -108,8 +108,8 @@ defmodule ExFactorTest do

# assert that the original files are unchanged
file = File.read!("lib/ex_factor/tmp/target_module.ex")
refute file =~ "def(refactor1(arg1)) do"
refute file =~ "def(refactor1([])) do"
refute file =~ "def refactor1(arg1) do"
refute file =~ "def refactor1([]) do"

file = File.read!("lib/ex_factor/tmp/source_module.ex")
assert file =~ "def refactor1(arg1) do"
Expand Down

0 comments on commit a5a1c68

Please sign in to comment.