Skip to content

Commit

Permalink
Accept guards in high-score
Browse files Browse the repository at this point in the history
  • Loading branch information
angelikatyborska committed Feb 18, 2024
1 parent 7da405f commit 1f5d860
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/elixir_analyzer/test_suite/high_score.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ defmodule ElixirAnalyzer.TestSuite.HighScore do
def add_player(_ignore, _ignore, _ignore \\ @_ignore)
end

form do
def add_player(_ignore, _ignore, _ignore \\ @_ignore) when _ignore do
_ignore
end
end

form do
def add_player(_ignore, _ignore, _ignore \\ @_ignore) when _ignore
end

form do
defdelegate add_player(_ignore, _ignore, _ignore \\ @_ignore), _ignore
end
Expand Down
34 changes: 34 additions & 0 deletions test/elixir_analyzer/test_suite/high_score_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,40 @@ defmodule ElixirAnalyzer.ExerciseTest.HighScoreTest do
end
end
end

test_exercise_analysis "accepts a guard",
comments_exclude: [Constants.high_score_use_default_argument_with_module_attribute()] do
defmodule HighScore do
def new(), do: %{}

@score 0
def add_player(scores, name, score \\ @score) when is_bitstring(name) do
Map.put(scores, name, score)
end

def reset_score(scores, name) do
Map.put(scores, name, @score)
end
end
end

test_exercise_analysis "accepts an empty function head with a guard",
comments_exclude: [Constants.high_score_use_default_argument_with_module_attribute()] do
defmodule HighScore do
def new(), do: %{}

@score 0
def add_player(scores, name, score \\ @score) when is_bitstring(name)

def add_player(scores, name, score) do
Map.put(scores, name, score)
end

def reset_score(scores, name) do
Map.put(scores, name, @score)
end
end
end
end

describe "looks for a module attribute with the initial score of 0" do
Expand Down

0 comments on commit 1f5d860

Please sign in to comment.