Skip to content

Commit

Permalink
Apply another suggestion to add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
scottming committed Mar 28, 2024
1 parent 254b306 commit 8027167
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,38 @@ defmodule Lexical.RemoteControl.Search.Indexer.Extractors.FunctionReferenceTest

assert expected == extract(code, reference.range)
end

test "find a captured local private function" do
code = in_a_module(~q[
def public_fun(x), do: x
defp private_fun(x, y), do: {x, y}
def use_private_fun(_l), do: &private_fun(&1, 1)
])

{:ok, [reference], _} = index(code)

assert reference.subject == "Parent.private_fun/2"
assert reference.type == :function
assert reference.subtype == :reference
assert "private_fun(&1, 1)" == extract(code, reference.range)
end

test "finds a captured local public function" do
code = in_a_module(~q[
def public_fun(x), do: x
defp private_fun(x, y), do: {x, y}
def use_public_fun(_l), do: &public_fun/1
])

{:ok, [reference], _} = index(code)

assert reference.subject == "Parent.public_fun/1"
assert reference.type == :function
assert reference.subtype == :reference
assert "public_fun/1" == extract(code, reference.range)
end
end

describe "imported function references" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,38 @@ defmodule Lexical.RemoteControl.Search.Indexer.Extractors.ModuleTest do
assert decorate(doc, module_ref.range) =~ " &«Some.Module».function/1"
end

test "can detect a module reference in a remote captured function with multiple arities" do
{:ok, [_module, module_ref], doc} =
~q[
defmodule Capture do
def my_fn do
&Some.Module.function(&1, 1)
end
end
]t
|> index()

assert module_ref.type == :module
assert module_ref.subject == Some.Module
assert decorate(doc, module_ref.range) =~ " &«Some.Module».function(&1, 1)"
end

test "can detect a module reference in an aliased remote captured function" do
{:ok, [_module, _alias, _aliased, module_ref], doc} =
~q[
defmodule Capture do
alias First.Second, as: Third
def my_fn do
&Third.function/1
end
end
]t |> index()

assert module_ref.type == :module
assert module_ref.subject == First.Second
assert decorate(doc, module_ref.range) =~ " &«Third».function/1"
end

test "can detect a module reference in a function call's arguments" do
{:ok, [_module, module_ref], doc} =
~q[
Expand Down

0 comments on commit 8027167

Please sign in to comment.