Skip to content

Commit

Permalink
fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Mar 8, 2024
1 parent ab73951 commit 473d2be
Show file tree
Hide file tree
Showing 7 changed files with 358 additions and 337 deletions.
29 changes: 18 additions & 11 deletions apps/elixir_ls_utils/test/complete_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ defmodule ElixirLS.Utils.CompletionEngineTest do
] = expand(~c"String.Cha")
end

@tag requires_elixir_1_14: true
if Version.match?(System.version(), ">= 1.14.0") do
test "elixir submodule completion with __MODULE__" do
assert [
%{
Expand All @@ -281,8 +281,9 @@ defmodule ElixirLS.Utils.CompletionEngineTest do
}
] = expand(~c"__MODULE__.Cha", %Env{module: String})
end
end

@tag requires_elixir_1_14: true
if Version.match?(System.version(), ">= 1.14.0") do
test "elixir submodule completion with attribute bound to module" do
assert [
%{
Expand All @@ -302,6 +303,7 @@ defmodule ElixirLS.Utils.CompletionEngineTest do
]
})
end
end

test "find elixir modules that require alias" do
assert [
Expand Down Expand Up @@ -361,19 +363,21 @@ defmodule ElixirLS.Utils.CompletionEngineTest do
assert [%{name: "fun2ms", origin: ":ets"}] = expand(~c":ets.fun2")
end

@tag requires_elixir_1_14: true
if Version.match?(System.version(), ">= 1.14.0") do
test "function completion on __MODULE__" do
assert [%{name: "version", origin: "System"}] =
expand(~c"__MODULE__.ve", %Env{module: System})
end
end

@tag requires_elixir_1_14: true
if Version.match?(System.version(), ">= 1.14.0") do
test "function completion on __MODULE__ submodules" do
assert [%{name: "to_string", origin: "String.Chars"}] =
expand(~c"__MODULE__.Chars.to", %Env{module: String})
end
end

@tag requires_elixir_1_14: true
if Version.match?(System.version(), ">= 1.14.0") do
test "function completion on attribute bound to module" do
assert [%{name: "version", origin: "System"}] =
expand(~c"@my_attr.ve", %Env{
Expand All @@ -385,6 +389,7 @@ defmodule ElixirLS.Utils.CompletionEngineTest do
]
})
end
end

test "function completion with arity" do
assert [
Expand Down Expand Up @@ -440,7 +445,6 @@ defmodule ElixirLS.Utils.CompletionEngineTest do
] = expand(~c"Enum.count/")
end

@tag requires_elixir_1_13: true
test "operator completion" do
assert [%{name: "+", arity: 1}, %{name: "+", arity: 2}, %{name: "++", arity: 2}] =
expand(~c"+")
Expand All @@ -452,7 +456,6 @@ defmodule ElixirLS.Utils.CompletionEngineTest do
assert entries |> Enum.any?(&(&1.name == "div"))
end

@tag requires_elixir_1_13: true
test "sigil completion" do
sigils = expand(~c"~")
assert sigils |> Enum.any?(fn s -> s.name == "~C" end)
Expand Down Expand Up @@ -1562,13 +1565,14 @@ defmodule ElixirLS.Utils.CompletionEngineTest do
assert Enum.any?(entries, &(&1.name == "MyDate" and &1.subtype == :struct))
end

@tag requires_elixir_1_14: true
if Version.match?(System.version(), ">= 1.14.0") do
test "completion for struct names with __MODULE__" do
assert [%{name: "__MODULE__"}] = expand(~c"%__MODU", %Env{module: Date.Range})
assert [%{name: "Range"}] = expand(~c"%__MODULE__.Ra", %Env{module: Date})
end
end

@tag requires_elixir_1_14: true
if Version.match?(System.version(), ">= 1.14.0") do
test "completion for struct attributes" do
assert [%{name: "@my_attr"}] =
expand(~c"%@my", %Env{
Expand All @@ -1592,6 +1596,7 @@ defmodule ElixirLS.Utils.CompletionEngineTest do
scope: MyMod
})
end
end

# handled elsewhere
# TODO consider moving struct key completion here after elixir 1.13+ is required
Expand Down Expand Up @@ -1966,7 +1971,7 @@ defmodule ElixirLS.Utils.CompletionEngineTest do
] = expand(~c"ArgumentError.bla")
end

@tag requires_otp_23: true
if System.otp_release() |> String.to_integer() >= 23 do
test "complete build in :erlang functions" do
assert [
%{arity: 2, name: "open_port", origin: ":erlang"},
Expand Down Expand Up @@ -2013,6 +2018,7 @@ defmodule ElixirLS.Utils.CompletionEngineTest do
%{arity: 2, name: "append_element", origin: ":erlang"}
] = expand(~c":erlang.and")
end
end

test "provide doc and specs for erlang functions" do
assert [
Expand Down Expand Up @@ -2197,7 +2203,7 @@ defmodule ElixirLS.Utils.CompletionEngineTest do
] = expand(~c"unquote", %Env{requires: []})
end

@tag requires_elixir_1_14: true
if Version.match?(System.version(), ">= 1.14.0") do
test "Application.compile_env classified as macro" do
assert [
%{
Expand Down Expand Up @@ -2238,3 +2244,4 @@ defmodule ElixirLS.Utils.CompletionEngineTest do
] = expand(~c"Application.compile_e")
end
end
end
50 changes: 25 additions & 25 deletions apps/language_server/test/providers/completion/suggestions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1457,32 +1457,33 @@ defmodule ElixirLS.LanguageServer.Providers.Completion.SuggestionTest do
end
end

@tag requires_otp_25: true
test "suggest erlang behaviour callbacks on erlang implementation" do
buffer = """
:file_server.ini
"""
if System.otp_release() |> String.to_integer() >= 25 do
test "suggest erlang behaviour callbacks on erlang implementation" do
buffer = """
:file_server.ini
"""

list =
Suggestion.suggestions(buffer, 1, 17)
|> Enum.filter(fn s -> s.type == :function end)
list =
Suggestion.suggestions(buffer, 1, 17)
|> Enum.filter(fn s -> s.type == :function end)

assert [
%{
args: "args",
args_list: ["args"],
arity: 1,
def_arity: 1,
metadata: %{implementing: :gen_server},
name: "init",
origin: ":file_server",
snippet: nil,
spec: "@callback init(args :: term()) ::" <> _,
summary: "- Args = term" <> _,
type: :function,
visibility: :public
}
] = list
assert [
%{
args: "args",
args_list: ["args"],
arity: 1,
def_arity: 1,
metadata: %{implementing: :gen_server},
name: "init",
origin: ":file_server",
snippet: nil,
spec: "@callback init(args :: term()) ::" <> _,
summary: "- Args = term" <> _,
type: :function,
visibility: :public
}
] = list
end
end

test "lists params and vars" do
Expand Down Expand Up @@ -4443,7 +4444,6 @@ defmodule ElixirLS.LanguageServer.Providers.Completion.SuggestionTest do
Suggestion.suggestions(buffer, 3, 8) |> Enum.filter(&("#{&1.name}" =~ "+"))
end

@tag requires_elixir_1_13: true
test "sigil" do
buffer = """
defmodule ElixirSenseExample.OtherModule do
Expand Down
138 changes: 71 additions & 67 deletions apps/language_server/test/providers/definition/locator_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,26 @@ defmodule ElixirLS.LanguageServer.Providers.Definition.LocatorTest do
assert nil == Locator.definition("__MODULE__", 1, 1)
end

@tag requires_elixir_1_14: true
test "find module definition inside Phoenix's scope" do
_define_existing_atom = ExampleWeb
if Version.match?(System.version(), ">= 1.14.0") do
test "find module definition inside Phoenix's scope" do
_define_existing_atom = ExampleWeb

buffer = """
defmodule ExampleWeb.Router do
import Phoenix.Router
buffer = """
defmodule ExampleWeb.Router do
import Phoenix.Router
scope "/", ExampleWeb do
get "/", PageController, :home
scope "/", ExampleWeb do
get "/", PageController, :home
end
end
end
"""
"""

%Location{type: :module, file: file, line: line, column: column} =
Locator.definition(buffer, 5, 15)
%Location{type: :module, file: file, line: line, column: column} =
Locator.definition(buffer, 5, 15)

assert file =~ "language_server/test/support/plugins/phoenix/page_controller.ex"
assert read_line(file, {line, column}) =~ "ExampleWeb.PageController"
assert file =~ "language_server/test/support/plugins/phoenix/page_controller.ex"
assert read_line(file, {line, column}) =~ "ExampleWeb.PageController"
end
end

test "find definition of aliased modules in `use`" do
Expand Down Expand Up @@ -1125,71 +1126,74 @@ defmodule ElixirLS.LanguageServer.Providers.Definition.LocatorTest do
}
end

@tag requires_elixir_1_14: true
test "find definition of local functions with __MODULE__ submodule" do
buffer = """
defmodule MyModule do
defmodule Sub do
def my_fun(), do: :ok
end
if Version.match?(System.version(), ">= 1.14.0") do
test "find definition of local functions with __MODULE__ submodule" do
buffer = """
defmodule MyModule do
defmodule Sub do
def my_fun(), do: :ok
end
def a do
my_fun1 = 1
__MODULE__.Sub.my_fun()
def a do
my_fun1 = 1
__MODULE__.Sub.my_fun()
end
end
end
"""
"""

assert Locator.definition(buffer, 8, 22) == %Location{
type: :function,
file: nil,
line: 3,
column: 5
}
assert Locator.definition(buffer, 8, 22) == %Location{
type: :function,
file: nil,
line: 3,
column: 5
}
end
end

@tag requires_elixir_1_14: true
test "find definition of local __MODULE__ submodule" do
buffer = """
defmodule MyModule do
defmodule Sub do
def my_fun(), do: :ok
end
if Version.match?(System.version(), ">= 1.14.0") do
test "find definition of local __MODULE__ submodule" do
buffer = """
defmodule MyModule do
defmodule Sub do
def my_fun(), do: :ok
end
def a do
my_fun1 = 1
__MODULE__.Sub.my_fun()
def a do
my_fun1 = 1
__MODULE__.Sub.my_fun()
end
end
end
"""
"""

assert Locator.definition(buffer, 8, 17) == %Location{
type: :module,
file: nil,
line: 2,
column: 3
}
assert Locator.definition(buffer, 8, 17) == %Location{
type: :module,
file: nil,
line: 2,
column: 3
}
end
end

@tag requires_elixir_1_14: true
test "find definition of local functions with @attr" do
buffer = """
defmodule MyModule do
def my_fun(), do: :ok
@attr MyModule
def a do
my_fun1 = 1
@attr.my_fun()
if Version.match?(System.version(), ">= 1.14.0") do
test "find definition of local functions with @attr" do
buffer = """
defmodule MyModule do
def my_fun(), do: :ok
@attr MyModule
def a do
my_fun1 = 1
@attr.my_fun()
end
end
end
"""
"""

assert Locator.definition(buffer, 6, 13) == %Location{
type: :function,
file: nil,
line: 2,
column: 3
}
assert Locator.definition(buffer, 6, 13) == %Location{
type: :function,
file: nil,
line: 2,
column: 3
}
end
end

test "find definition of local functions with current module" do
Expand Down
Loading

0 comments on commit 473d2be

Please sign in to comment.