From 1f5d8604fc753bcc51bf0ef0794a44929750b8ea Mon Sep 17 00:00:00 2001 From: Angelika Tyborska Date: Sun, 18 Feb 2024 18:23:54 +0100 Subject: [PATCH] Accept guards in high-score --- lib/elixir_analyzer/test_suite/high_score.ex | 10 ++++++ .../test_suite/high_score_test.exs | 34 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/lib/elixir_analyzer/test_suite/high_score.ex b/lib/elixir_analyzer/test_suite/high_score.ex index 5f516421..66575087 100644 --- a/lib/elixir_analyzer/test_suite/high_score.ex +++ b/lib/elixir_analyzer/test_suite/high_score.ex @@ -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 diff --git a/test/elixir_analyzer/test_suite/high_score_test.exs b/test/elixir_analyzer/test_suite/high_score_test.exs index b77db954..7d210e9e 100644 --- a/test/elixir_analyzer/test_suite/high_score_test.exs +++ b/test/elixir_analyzer/test_suite/high_score_test.exs @@ -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