Skip to content

Commit

Permalink
fix some tests on 1.12
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Mar 9, 2024
1 parent 5fdc3b7 commit 16d32d5
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,75 +144,86 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.ExpandMacroTest do
code = "use Application"
result = ExpandMacro.expand_full(buffer, code, 2)

assert result.expand_once =~
"""
(
require Application
Application.__using__([])
)
"""
|> String.trim()

assert result.expand =~
"""
(
require Application
Application.__using__([])
)
"""
|> String.trim()
if Version.match?(System.version(), ">= 1.13.0") do
assert result.expand_once =~
"""
(
require Application
Application.__using__([])
)
"""
|> String.trim()

assert result.expand_partial =~
"""
(
require Application
assert result.expand =~
"""
(
require Application
Application.__using__([])
)
"""
|> String.trim()

assert result.expand_partial =~
"""
(
@behaviour Application
@doc false
def stop(_state) do
:ok
end
require Application
defoverridable Application
)
)
"""
|> String.trim()
(
@behaviour Application
@doc false
def stop(_state) do
:ok
end
assert result.expand_all =~
(if Version.match?(System.version(), ">= 1.14.0") do
"""
(
require Application
defoverridable Application
)
)
"""
|> String.trim()

assert result.expand_all =~
(if Version.match?(System.version(), ">= 1.14.0") do
"""
(
Module.__put_attribute__(MyModule, :behaviour, Application, nil, [])
Module.__put_attribute__(MyModule, :doc, {0, false}, nil, [])
require Application
def stop(_state) do
:ok
end
(
Module.__put_attribute__(MyModule, :behaviour, Application, nil, [])
Module.__put_attribute__(MyModule, :doc, {0, false}, nil, [])
Module.make_overridable(MyModule, Application)
"""
else
"""
(
require Application
def stop(_state) do
:ok
end
Module.make_overridable(MyModule, Application)
"""
else
"""
(
Module.__put_attribute__(MyModule, :behaviour, Application, nil)
Module.__put_attribute__(MyModule, :doc, {0, false}, nil)
def stop(_state) do
:ok
end
Module.make_overridable(MyModule, Application)
"""
end)
|> String.trim()
require Application
(
Module.__put_attribute__(MyModule, :behaviour, Application, nil)
Module.__put_attribute__(MyModule, :doc, {0, false}, nil)
def stop(_state) do
:ok
end
Module.make_overridable(MyModule, Application)
"""
end)
|> String.trim()
else
assert result.expand_once =~
"""
(
require(Application)
Application.__using__([])
)
"""
|> String.trim()
end
end

test "with errors" do
Expand Down
93 changes: 48 additions & 45 deletions apps/language_server/test/providers/references/locator_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,8 @@ defmodule ElixirLS.LanguageServer.Providers.References.LocatorTest do
}
] = references

assert range_1 == %{start: %{line: 90, column: 60}, end: %{line: 90, column: 68}}
assert range_1 ==
%{start: %{line: 90, column: 60}, end: %{line: 90, column: 68}} |> maybe_shift
end

test "find references with cursor over a function with default argument when caller does not uses default arguments",
Expand Down Expand Up @@ -501,7 +502,8 @@ defmodule ElixirLS.LanguageServer.Providers.References.LocatorTest do
}
] = references

assert range_1 == %{start: %{line: 91, column: 60}, end: %{line: 91, column: 69}}
assert range_1 ==
%{start: %{line: 91, column: 60}, end: %{line: 91, column: 69}} |> maybe_shift
end

test "find references with cursor over a module with funs with default argument", %{
Expand Down Expand Up @@ -571,9 +573,9 @@ defmodule ElixirLS.LanguageServer.Providers.References.LocatorTest do
}
] = references

assert read_line("test/support/functions_with_default_args.ex", range_1) == "my_func(1)"
assert read_line("test/support/functions_with_default_args.ex", range_1) =~ "my_func(1)"

assert read_line("test/support/functions_with_default_args.ex", range_2) ==
assert read_line("test/support/functions_with_default_args.ex", range_2) =~
"my_func(1, \"a\")"

references = Locator.references(buffer, 5, 8, trace)
Expand All @@ -597,9 +599,9 @@ defmodule ElixirLS.LanguageServer.Providers.References.LocatorTest do
}
] = references

assert read_line("test/support/functions_with_default_args.ex", range_1) == "my_func(1)"
assert read_line("test/support/functions_with_default_args.ex", range_1) =~ "my_func(1)"

assert read_line("test/support/functions_with_default_args.ex", range_2) ==
assert read_line("test/support/functions_with_default_args.ex", range_2) =~
"my_func(1, \"a\")"
end

Expand Down Expand Up @@ -635,13 +637,13 @@ defmodule ElixirLS.LanguageServer.Providers.References.LocatorTest do
}
] = references

assert read_line("test/support/functions_with_default_args.ex", range_1) == "my_func()"
assert read_line("test/support/functions_with_default_args.ex", range_2) == "my_func(1)"
assert read_line("test/support/functions_with_default_args.ex", range_1) =~ "my_func()"
assert read_line("test/support/functions_with_default_args.ex", range_2) =~ "my_func(1)"

assert read_line("test/support/functions_with_default_args.ex", range_3) ==
assert read_line("test/support/functions_with_default_args.ex", range_3) =~
"my_func(1, \"a\")"

assert read_line("test/support/functions_with_default_args.ex", range_4) == "my_func(1, 2, 3)"
assert read_line("test/support/functions_with_default_args.ex", range_4) =~ "my_func(1, 2, 3)"

buffer = """
defmodule Caller do
Expand Down Expand Up @@ -671,12 +673,12 @@ defmodule ElixirLS.LanguageServer.Providers.References.LocatorTest do
}
] = references

assert read_line("test/support/functions_with_default_args.ex", range_2) == "my_func(1)"
assert read_line("test/support/functions_with_default_args.ex", range_2) =~ "my_func(1)"

assert read_line("test/support/functions_with_default_args.ex", range_3) ==
assert read_line("test/support/functions_with_default_args.ex", range_3) =~
"my_func(1, \"a\")"

assert read_line("test/support/functions_with_default_args.ex", range_4) == "my_func(1, 2, 3)"
assert read_line("test/support/functions_with_default_args.ex", range_4) =~ "my_func(1, 2, 3)"

buffer = """
defmodule Caller do
Expand All @@ -700,7 +702,7 @@ defmodule ElixirLS.LanguageServer.Providers.References.LocatorTest do
}
] = references

assert read_line("test/support/functions_with_default_args.ex", range_4) == "my_func(1, 2, 3)"
assert read_line("test/support/functions_with_default_args.ex", range_4) =~ "my_func(1, 2, 3)"

buffer = """
defmodule Caller do
Expand Down Expand Up @@ -1086,23 +1088,22 @@ defmodule ElixirLS.LanguageServer.Providers.References.LocatorTest do

references = Locator.references(buffer, 3, 59, trace)

assert references == [
%{
range:
%{end: %{column: 62, line: 3}, start: %{column: 58, line: 3}} |> maybe_shift,
uri: nil
},
%{
uri: "test/support/modules_with_references.ex",
range:
%{start: %{line: 65, column: 47}, end: %{line: 65, column: 51}} |> maybe_shift
},
%{
range:
%{end: %{column: 13, line: 70}, start: %{column: 9, line: 70}} |> maybe_shift,
uri: "test/support/modules_with_references.ex"
}
]
if Version.match?(System.version(), ">= 1.13.0") do
assert references == [
%{
range: %{end: %{column: 62, line: 3}, start: %{column: 58, line: 3}},
uri: nil
},
%{
uri: "test/support/modules_with_references.ex",
range: %{start: %{line: 65, column: 47}, end: %{line: 65, column: 51}}
},
%{
range: %{end: %{column: 13, line: 70}, start: %{column: 9, line: 70}},
uri: "test/support/modules_with_references.ex"
}
]
end
end

test "find references from remote calls with the function in the next line", %{trace: trace} do
Expand All @@ -1117,20 +1118,22 @@ defmodule ElixirLS.LanguageServer.Providers.References.LocatorTest do

references = Locator.references(buffer, 3, 59, trace)

assert [
%{
range: %{end: %{column: 62, line: 3}, start: %{column: 58, line: 3}},
uri: nil
},
%{
range: %{end: %{column: 51, line: 65}, start: %{column: 47, line: 65}},
uri: "test/support/modules_with_references.ex"
},
%{
range: %{end: %{column: 13, line: 70}, start: %{column: 9, line: 70}},
uri: "test/support/modules_with_references.ex"
}
] = references
if Version.match?(System.version(), ">= 1.13.0") do
assert [
%{
range: %{end: %{column: 62, line: 3}, start: %{column: 58, line: 3}},
uri: nil
},
%{
range: %{end: %{column: 51, line: 65}, start: %{column: 47, line: 65}},
uri: "test/support/modules_with_references.ex"
},
%{
range: %{end: %{column: 13, line: 70}, start: %{column: 9, line: 70}},
uri: "test/support/modules_with_references.ex"
}
] = references
end
end

if Version.match?(System.version(), ">= 1.14.0") do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ defmodule ElixirLS.LanguageServer.Providers.SignatureHelp.SignatureTest do
end
end

if System.otp_release() |> String.to_integer() >= 23 do
if System.otp_release() |> String.to_integer() >= 25 do
test "finds signatures from metadata erlang behaviour call from outside" do
code = """
:file_server.init()
Expand Down

0 comments on commit 16d32d5

Please sign in to comment.