Skip to content

Commit

Permalink
Merge pull request #42 from ma2gedev/feature/explicitly-hide-inject-s…
Browse files Browse the repository at this point in the history
…tore-code

hide `inject_store_code` explicitly
  • Loading branch information
ma2gedev authored Dec 29, 2020
2 parents 5f73e71 + 7d18c79 commit 2e5d306
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
10 changes: 5 additions & 5 deletions lib/power_assert/assertion.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ defmodule PowerAssert.Assertion do
[_ | t] = String.split(Macro.to_string(ast), " = ")
rhs_expr = Enum.join(t, " = ")
rhs_index = (Macro.to_string(left) |> String.length()) + @assign_len
injected_rhs_ast = inject_store_code(right, rhs_expr, rhs_index)
injected_rhs_ast = __inject_store_code__(right, rhs_expr, rhs_index)
message_ast = message_ast(msg)

left = Macro.expand(left, __CALLER__)
Expand Down Expand Up @@ -78,9 +78,9 @@ defmodule PowerAssert.Assertion do
code = Macro.escape(ast)
[lhs_expr | t] = String.split(Macro.to_string(ast), " == ")
rhs_expr = Enum.join(t, " == ")
injected_lhs_ast = inject_store_code(left, lhs_expr)
injected_lhs_ast = __inject_store_code__(left, lhs_expr)
rhs_index = (Macro.to_string(left) |> String.length()) + @equal_len
injected_rhs_ast = inject_store_code(right, rhs_expr, rhs_index)
injected_rhs_ast = __inject_store_code__(right, rhs_expr, rhs_index)
message_ast = message_ast(msg)

quote do
Expand Down Expand Up @@ -110,7 +110,7 @@ defmodule PowerAssert.Assertion do

defmacro assert(ast, msg) do
code = Macro.escape(ast)
injected_ast = inject_store_code(ast, Macro.to_string(ast))
injected_ast = __inject_store_code__(ast, Macro.to_string(ast))

message_ast = message_ast(msg)

Expand Down Expand Up @@ -148,7 +148,7 @@ defmodule PowerAssert.Assertion do
end

@doc false
def inject_store_code(ast, expr, default_index \\ 0) do
def __inject_store_code__(ast, expr, default_index \\ 0) do
positions = detect_position(ast, expr, default_index)

{injected_ast, _} =
Expand Down
4 changes: 1 addition & 3 deletions lib/power_assert/debug.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
defmodule PowerAssert.Debug do
import PowerAssert.Assertion

@moduledoc """
This module provides debug utilities
"""
Expand All @@ -18,7 +16,7 @@ defmodule PowerAssert.Debug do
"""
defmacro puts_expr(ast) do
code = Macro.escape(ast)
injected_ast = inject_store_code(ast, Macro.to_string(ast))
injected_ast = PowerAssert.Assertion.__inject_store_code__(ast, Macro.to_string(ast))

quote do
unquote(injected_ast)
Expand Down

0 comments on commit 2e5d306

Please sign in to comment.