Skip to content

Commit 1b770f1

Browse files
committed
more tests
1 parent 8987355 commit 1b770f1

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

apps/language_server/test/providers/completion/suggestions_test.exs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4041,6 +4041,24 @@ defmodule ElixirLS.LanguageServer.Providers.Completion.SuggestionTest do
40414041
"""
40424042
end
40434043

4044+
test "params with default args" do
4045+
buffer = """
4046+
ElixirSenseExample.ModuleWithTypespecs.Local.fun_with_default()
4047+
"""
4048+
4049+
list = Suggestion.suggestions(buffer, 1, 63)
4050+
assert [%{name: "bar"}, %{name: "foo"}] = list |> Enum.filter(&(&1.type == :param_option))
4051+
end
4052+
4053+
test "params with multiple specs" do
4054+
buffer = """
4055+
ElixirSenseExample.ModuleWithTypespecs.Local.fun_with_multiple_specs()
4056+
"""
4057+
4058+
list = Suggestion.suggestions(buffer, 1, 70)
4059+
assert [%{name: "opt_name"}] = list |> Enum.filter(&(&1.type == :param_option))
4060+
end
4061+
40444062
test "metadata params" do
40454063
buffer = """
40464064
defmodule Foo do
@@ -4056,6 +4074,39 @@ defmodule ElixirLS.LanguageServer.Providers.Completion.SuggestionTest do
40564074
list = Suggestion.suggestions(buffer, 6, 10)
40574075
assert [%{name: "bar"}, %{name: "foo"}] = list |> Enum.filter(&(&1.type == :param_option))
40584076
end
4077+
4078+
test "metadata params multiple specs" do
4079+
buffer = """
4080+
defmodule Foo do
4081+
@spec some([{:foo, integer()} | {:bar, String.t()}]) :: :ok
4082+
@spec some(nil) :: :ok
4083+
def some(options), do: :ok
4084+
4085+
def go do
4086+
some()
4087+
end
4088+
end
4089+
"""
4090+
4091+
list = Suggestion.suggestions(buffer, 7, 10)
4092+
assert [%{name: "bar"}, %{name: "foo"}] = list |> Enum.filter(&(&1.type == :param_option))
4093+
end
4094+
4095+
test "metadata params with default args" do
4096+
buffer = """
4097+
defmodule Foo do
4098+
@spec some(atom, [{:foo, integer()} | {:bar, String.t()}]) :: :ok
4099+
def some(a \\\\ nil, options), do: :ok
4100+
4101+
def go do
4102+
some()
4103+
end
4104+
end
4105+
"""
4106+
4107+
list = Suggestion.suggestions(buffer, 6, 10)
4108+
assert [%{name: "bar"}, %{name: "foo"}] = list |> Enum.filter(&(&1.type == :param_option))
4109+
end
40594110
end
40604111

40614112
describe "suggestions for typespecs" do

apps/language_server/test/support/module_with_typespecs.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,5 +189,8 @@ defmodule ElixirSenseExample.ModuleWithTypespecs do
189189
IO.inspect(options)
190190
{:asd, [], nil}
191191
end
192+
193+
@spec fun_with_default(atom, [{:foo, integer()} | {:bar, String.t()}]) :: :ok
194+
def fun_with_default(a \\ nil, options), do: :ok
192195
end
193196
end

0 commit comments

Comments
 (0)