Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow any default parameter in two-fer #432

Merged
merged 3 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/elixir_analyzer/test_suite/two_fer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ defmodule ElixirAnalyzer.TestSuite.TwoFer do

# function header
form do
def two_fer(_ignore \\ "you")
def two_fer(_ignore \\ _ignore)
end

# function without a guard and with a do block
form do
def two_fer(_ignore \\ "you") do
def two_fer(_ignore \\ _ignore) do
_ignore
end
end

# function with do block
form do
def two_fer(_ignore \\ "you") when _ignore do
def two_fer(_ignore \\ _ignore) when _ignore do
_ignore
end
end
Expand Down
18 changes: 15 additions & 3 deletions test/elixir_analyzer/test_suite/two_fer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ defmodule ElixirAnalyzer.TestSuite.TwoFerTest do
defmodule TwoFer do
def two_fer(_)
end,
defmodule TwoFer do
def two_fer(name \\ "wrong default value")
end,
defmodule TwoFer do
def two_fer(name) do
"One for #{name}, one for me."
Expand All @@ -114,6 +111,21 @@ defmodule ElixirAnalyzer.TestSuite.TwoFerTest do
end
end

test_exercise_analysis "accepts any value as the default parameter",
comments_exclude: [Constants.two_fer_use_default_parameter()] do
[
defmodule TwoFer do
def two_fer(name \\ "you")
end,
defmodule TwoFer do
def two_fer(name \\ "wrong default value")
end,
defmodule TwoFer do
def two_fer(name \\ nil)
end
]
end

describe "function header" do
test_exercise_analysis "refer when using a function header",
comments_include: [Constants.two_fer_use_of_function_header()] do
Expand Down