Skip to content

Commit

Permalink
Use setup instead of private_function in the definition test
Browse files Browse the repository at this point in the history
  • Loading branch information
scottming committed Feb 25, 2023
1 parent 59c101b commit a3ed366
Showing 1 changed file with 127 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,177 +38,173 @@ defmodule ElixirLS.Experimental.Provider.Handlers.GotoDefinitionTest do
Handlers.GotoDefinition.handle(request, Env.new())
end

defp get_referenced_file_uri do
"references_referenced.ex"
|> FixtureHelpers.get_path()
|> Conversions.ensure_uri()
def with_referenced_file(_) do
path = FixtureHelpers.get_path("references_referenced.ex")
uri = Conversions.ensure_uri(path)
{:ok, file_uri: uri, file_path: path}
end

test "find definition remote function call" do
referenced_uri = get_referenced_file_uri()
file_path = FixtureHelpers.get_path("references_remote.ex")
{line, char} = {4, 28}
describe "when a file contains references" do
setup [:with_referenced_file]

{:ok, request} = request(file_path, line, char)
test "find definition remote function call", %{file_uri: uri} do
file_path = FixtureHelpers.get_path("references_remote.ex")
{line, char} = {4, 28}

annotate_assert(file_path, line, char, """
ReferencesReferenced.referenced_fun()
^
""")
{:ok, request} = request(file_path, line, char)

{:reply, %Responses.GotoDefinition{result: definition}} = handle(request)
annotate_assert(file_path, line, char, """
ReferencesReferenced.referenced_fun()
^
""")

assert definition.uri == referenced_uri
assert definition.range.start.line == 1
assert definition.range.start.character == 6
assert definition.range.end.line == 1
assert definition.range.end.character == 6
end
{:reply, %Responses.GotoDefinition{result: definition}} = handle(request)

assert definition.uri == uri
assert definition.range.start.line == 1
assert definition.range.start.character == 6
assert definition.range.end.line == 1
assert definition.range.end.character == 6
end

test "find definition remote macro call" do
referenced_uri = get_referenced_file_uri()
file_path = FixtureHelpers.get_path("references_remote.ex")
{line, char} = {8, 28}
test "find definition remote macro call", %{file_uri: uri} do
file_path = FixtureHelpers.get_path("references_remote.ex")
{line, char} = {8, 28}

{:ok, request} = request(file_path, line, char)
{:ok, request} = request(file_path, line, char)

annotate_assert(file_path, line, char, """
ReferencesReferenced.referenced_macro a do
^
""")
annotate_assert(file_path, line, char, """
ReferencesReferenced.referenced_macro a do
^
""")

{:reply, %Responses.GotoDefinition{result: definition}} = handle(request)
{:reply, %Responses.GotoDefinition{result: definition}} = handle(request)

assert definition.uri == referenced_uri
assert definition.range.start.line == 8
assert definition.range.start.character == 11
assert definition.range.end.line == 8
assert definition.range.end.character == 11
end
assert definition.uri == uri
assert definition.range.start.line == 8
assert definition.range.start.character == 11
assert definition.range.end.line == 8
assert definition.range.end.character == 11
end

test "find definition imported function call" do
referenced_uri = get_referenced_file_uri()
file_path = FixtureHelpers.get_path("references_imported.ex")
{line, char} = {4, 5}
test "find definition imported function call", %{file_uri: uri} do
file_path = FixtureHelpers.get_path("references_imported.ex")
{line, char} = {4, 5}

{:ok, request} = request(file_path, line, char)
{:ok, request} = request(file_path, line, char)

annotate_assert(file_path, line, char, """
referenced_fun()
^
""")
annotate_assert(file_path, line, char, """
referenced_fun()
^
""")

{:reply, %Responses.GotoDefinition{result: definition}} = handle(request)
{:reply, %Responses.GotoDefinition{result: definition}} = handle(request)

assert definition.uri == referenced_uri
assert definition.range.start.line == 1
assert definition.range.start.character == 6
assert definition.range.end.line == 1
assert definition.range.end.character == 6
end
assert definition.uri == uri
assert definition.range.start.line == 1
assert definition.range.start.character == 6
assert definition.range.end.line == 1
assert definition.range.end.character == 6
end

test "find definition imported macro call" do
referenced_uri = get_referenced_file_uri()
file_path = FixtureHelpers.get_path("references_imported.ex")
{line, char} = {8, 5}
test "find definition imported macro call", %{file_uri: uri} do
file_path = FixtureHelpers.get_path("references_imported.ex")
{line, char} = {8, 5}

{:ok, request} = request(file_path, line, char)
{:ok, request} = request(file_path, line, char)

annotate_assert(file_path, line, char, """
referenced_macro a do
^
""")
annotate_assert(file_path, line, char, """
referenced_macro a do
^
""")

{:reply, %Responses.GotoDefinition{result: definition}} = handle(request)
{:reply, %Responses.GotoDefinition{result: definition}} = handle(request)

assert definition.uri == referenced_uri
assert definition.range.start.line == 8
assert definition.range.start.character == 11
assert definition.range.end.line == 8
assert definition.range.end.character == 11
end
assert definition.uri == uri
assert definition.range.start.line == 8
assert definition.range.start.character == 11
assert definition.range.end.line == 8
assert definition.range.end.character == 11
end

test "find definition local function call" do
referenced_uri = get_referenced_file_uri()
file_path = FixtureHelpers.get_path("references_referenced.ex")
{line, char} = {15, 5}
test "find definition local function call", %{file_uri: uri} do
file_path = FixtureHelpers.get_path("references_referenced.ex")
{line, char} = {15, 5}

{:ok, request} = request(file_path, line, char)
{:ok, request} = request(file_path, line, char)

annotate_assert(file_path, line, char, """
referenced_fun()
^
""")
annotate_assert(file_path, line, char, """
referenced_fun()
^
""")

{:reply, %Responses.GotoDefinition{result: definition}} = handle(request)
{:reply, %Responses.GotoDefinition{result: definition}} = handle(request)

assert definition.uri == referenced_uri
assert definition.range.start.line == 1
assert definition.range.start.character == 6
assert definition.range.end.line == 1
assert definition.range.end.character == 6
end
assert definition.uri == uri
assert definition.range.start.line == 1
assert definition.range.start.character == 6
assert definition.range.end.line == 1
assert definition.range.end.character == 6
end

test "find definition local macro call" do
referenced_uri = get_referenced_file_uri()
file_path = FixtureHelpers.get_path("references_referenced.ex")
{line, char} = {19, 5}
test "find definition local macro call", %{file_uri: uri} do
file_path = FixtureHelpers.get_path("references_referenced.ex")
{line, char} = {19, 5}

{:ok, request} = request(file_path, line, char)
{:ok, request} = request(file_path, line, char)

annotate_assert(file_path, line, char, """
referenced_macro a do
^
""")
annotate_assert(file_path, line, char, """
referenced_macro a do
^
""")

{:reply, %Responses.GotoDefinition{result: definition}} = handle(request)
{:reply, %Responses.GotoDefinition{result: definition}} = handle(request)

assert definition.uri == referenced_uri
assert definition.range.start.line == 8
assert definition.range.start.character == 11
assert definition.range.end.line == 8
assert definition.range.end.character == 11
end
assert definition.uri == uri
assert definition.range.start.line == 8
assert definition.range.start.character == 11
assert definition.range.end.line == 8
assert definition.range.end.character == 11
end

test "find definition variable" do
referenced_uri = get_referenced_file_uri()
file_path = FixtureHelpers.get_path("references_referenced.ex")
{line, char} = {4, 13}
test "find definition variable", %{file_uri: uri} do
file_path = FixtureHelpers.get_path("references_referenced.ex")
{line, char} = {4, 13}

{:ok, request} = request(file_path, line, char)
{:ok, request} = request(file_path, line, char)

annotate_assert(file_path, line, char, """
IO.puts(referenced_variable + 1)
^
""")
annotate_assert(file_path, line, char, """
IO.puts(referenced_variable + 1)
^
""")

{:reply, %Responses.GotoDefinition{result: definition}} = handle(request)
{:reply, %Responses.GotoDefinition{result: definition}} = handle(request)

assert definition.uri == referenced_uri
assert definition.range.start.line == 2
assert definition.range.start.character == 4
assert definition.range.end.line == 2
assert definition.range.end.character == 4
end
assert definition.uri == uri
assert definition.range.start.line == 2
assert definition.range.start.character == 4
assert definition.range.end.line == 2
assert definition.range.end.character == 4
end

test "find definition attribute" do
referenced_uri = get_referenced_file_uri()
file_path = FixtureHelpers.get_path("references_referenced.ex")
{line, char} = {27, 5}
test "find definition attribute", %{file_uri: uri} do
file_path = FixtureHelpers.get_path("references_referenced.ex")
{line, char} = {27, 5}

{:ok, request} = request(file_path, line, char)
{:ok, request} = request(file_path, line, char)

annotate_assert(file_path, line, char, """
@referenced_attribute
^
""")
annotate_assert(file_path, line, char, """
@referenced_attribute
^
""")

{:reply, %Responses.GotoDefinition{result: definition}} = handle(request)
{:reply, %Responses.GotoDefinition{result: definition}} = handle(request)

assert definition.uri == referenced_uri
assert definition.range.start.line == 24
assert definition.range.start.character == 2
assert definition.range.end.line == 24
assert definition.range.end.character == 2
assert definition.uri == uri
assert definition.range.start.line == 24
assert definition.range.start.character == 2
assert definition.range.end.line == 24
assert definition.range.end.character == 2
end
end
end

0 comments on commit a3ed366

Please sign in to comment.