Skip to content

Commit

Permalink
Local calls can be patched in string interpolations
Browse files Browse the repository at this point in the history
  • Loading branch information
ollien committed Feb 24, 2025
1 parent 4fc5191 commit 3cbf71f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/patch/mock/code/transforms/remote.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ defmodule Patch.Mock.Code.Transforms.Remote do
end
end

defp expression({:bin, anno, body}, module, exports) do
{:bin, anno, expressions(body, module, exports)}
end

defp expression({:bin_element, anno, body, size, types}, module, exports) do
{:bin_element, anno, expression(body, module, exports), size, types}
end

defp expression({:block, anno, body}, module, exports) do
{:block, anno, expressions(body, module, exports)}
end
Expand Down
8 changes: 8 additions & 0 deletions test/support/user/patch/local_call.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ defmodule Patch.Test.Support.User.Patch.LocalCall do
{:original, public_function(a)}
end

def public_caller_string_interpolation(a) do
{:original, "#{inspect(public_function(a))}"}
end

def public_function(a) do
{:public, a}
end
Expand All @@ -19,6 +23,10 @@ defmodule Patch.Test.Support.User.Patch.LocalCall do
{:original, private_function(a)}
end

def private_caller_string_interpolation(a) do
{:original, "#{inspect(private_function(a))}"}
end

## Private

defp private_function(a) do
Expand Down
16 changes: 16 additions & 0 deletions test/user/patch/local_call_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ defmodule Patch.Test.User.Patch.LocalCallTest do
assert LocalCall.public_caller(:test_argument) == {:original, :patched}
end

test "can be patched in a string interpolation" do
assert LocalCall.public_caller_string_interpolation(:test_argument) == {:original, "{:public, :test_argument}"}

patch(LocalCall, :public_function, :patched)

assert LocalCall.public_caller_string_interpolation(:test_argument) == {:original, ":patched"}
end

test "can be assert_called" do
assert LocalCall.public_caller(:test_argument) == {:original, {:public, :test_argument}}

Expand Down Expand Up @@ -41,6 +49,14 @@ defmodule Patch.Test.User.Patch.LocalCallTest do
assert LocalCall.private_caller(:test_argument) == {:original, :patched}
end

test "can be patched in a string interpolation" do
assert LocalCall.private_caller_string_interpolation(:test_argument) == {:original, "{:private, :test_argument}"}

patch(LocalCall, :private_function, :patched)

assert LocalCall.private_caller_string_interpolation(:test_argument) == {:original, ":patched"}
end

test "can be assert_called" do
assert LocalCall.private_caller(:test_argument) == {:original, {:private, :test_argument}}

Expand Down

0 comments on commit 3cbf71f

Please sign in to comment.