Skip to content

Commit

Permalink
Allow any default parameter in two-fer (#432)
Browse files Browse the repository at this point in the history
* Allow any default parameter in two-fer

Fixes #431

* Update tests for two-fer

* mix format

---------

Co-authored-by: Jeremie Gillet <[email protected]>
  • Loading branch information
skeltoac and jiegillet authored Jul 21, 2024
1 parent f3e6767 commit 5228eed
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
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

0 comments on commit 5228eed

Please sign in to comment.