-
-
Notifications
You must be signed in to change notification settings - Fork 33
Added erlang ast test in captains-log
#455
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ defmodule ElixirAnalyzer.TestSuite.CaptainsLog do | |
| """ | ||
| use ElixirAnalyzer.ExerciseTest | ||
| alias ElixirAnalyzer.Constants | ||
| alias ElixirAnalyzer.Source | ||
|
|
||
| assert_call "random_planet_class uses Enum.random" do | ||
| type :essential | ||
|
|
@@ -43,10 +44,30 @@ defmodule ElixirAnalyzer.TestSuite.CaptainsLog do | |
| suppress_if "random_stardate does not use Enum.random", :fail | ||
| end | ||
|
|
||
| assert_call "format_stardate uses :io_lib" do | ||
|
|
||
| check_source "format_stardate uses erlang" do | ||
| type :essential | ||
| calling_fn module: CaptainsLog, name: :format_stardate | ||
| called_fn module: :io_lib, name: :_ | ||
| comment Constants.captains_log_use_io_lib() | ||
| comment Constants.captains_log_use_erlang() | ||
|
|
||
| check(%Source{code_ast: code_ast}) do | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm hesitating about this change.
assert_call "format_stardate uses :io_lib" do
calling_fn module: CaptainsLog, name: :format_stardate
called_fn module: :io_lib, name: :_
suppress_if "format_stardate uses :erlang", :pass
end
assert_call "format_stardate uses :erlang" do
calling_fn module: CaptainsLog, name: :format_stardate
called_fn module: :erlang, name: :_
suppress_if "format_stardate uses :io_lib", :pass
endthis should be equivalent to the intent of your PR.
assert_call "format_stardate uses an Erlang module" do
calling_fn module: CaptainsLog, name: :format_stardate
called_fn module: AnyErlangModule, name: :_
endThis would detect the use of any non-elixir module, while preserving all of the advantages of Since approach 1. would already be a strict improvement, I think that's the one we should aim at to relieve your from your 5-month journey within a reasonable time :) |
||
| {_, erlang?} = | ||
| Macro.prewalk(code_ast, false, fn node, acc -> | ||
| case node do | ||
| # usage :io_lib.format/2 | ||
| {{:., _, [:io_lib, :format]}, _, _} -> | ||
| {node, true} | ||
|
|
||
| # usage :erlang.function_name/arity | ||
| # matches any function call from :erlang module | ||
| {{:., _, [:erlang, _]}, _, _} -> | ||
| {node, true} | ||
|
|
||
| _ -> | ||
| {node, acc} | ||
| end | ||
| end) | ||
|
|
||
| erlang? | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,7 +98,7 @@ defmodule ElixirAnalyzer.ExerciseTest.CaptainsLogTest do | |
| end | ||
|
|
||
| test_exercise_analysis "format_stardate uses Float.round", | ||
| comments_include: [Constants.captains_log_use_io_lib()] do | ||
| comments_include: [Constants.captains_log_use_erlang()] do | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add at one test that use an |
||
| defmodule CaptainsLog do | ||
| def format_stardate(stardate) do | ||
| if is_float(stardate) do | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "authors": [ | ||
| "angelikatyborska" | ||
| ], | ||
| "contributors": [ | ||
| "neenjaw" | ||
| ], | ||
| "files": { | ||
| "solution": [ | ||
| "lib/captains_log.ex" | ||
| ], | ||
| "test": [ | ||
| "test/captains_log_test.exs" | ||
| ], | ||
| "exemplar": [ | ||
| ".meta/exemplar.ex" | ||
| ] | ||
| }, | ||
| "blurb": "Learn about randomness and using Erlang libraries from Elixir by helping Mary generate stardates and starship registry numbers for her Star Trek themed pen-and-paper role playing sessions." | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| defmodule CaptainsLog do | ||
| @planetary_classes ["D", "H", "J", "K", "L", "M", "N", "R", "T", "Y"] | ||
|
|
||
| def random_planet_class() do | ||
| Enum.random(@planetary_classes) | ||
| end | ||
|
|
||
| def random_ship_registry_number() do | ||
| number = Enum.random(1000..9999) | ||
| "NCC-#{number}" | ||
| end | ||
|
|
||
| def random_stardate() do | ||
| :rand.uniform() * 1000 + 41_000 | ||
| end | ||
|
|
||
| def format_stardate(stardate) do | ||
| to_string(:io_lib.format("~.1f", [stardate])) | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"summary":"Check the comments for things to fix. 🛠","comments":[{"type":"essential","comment":"elixir.captains-log.use_erlang"},{"type":"informative","params":{"mentoring_request_url":"https://exercism.org/tracks/elixir/exercises/captains-log/mentor_discussions"},"comment":"elixir.general.feedback_request"}]} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| defmodule CaptainsLog do | ||
| @planetary_classes ["D", "H", "J", "K", "L", "M", "N", "R", "T", "Y"] | ||
|
|
||
| def random_planet_class() do | ||
| Enum.random(@planetary_classes) | ||
| end | ||
|
|
||
| def random_ship_registry_number() do | ||
| number = Enum.random(1000..9999) | ||
| "NCC-#{number}" | ||
| end | ||
|
|
||
| def random_stardate() do | ||
| :rand.uniform() * 1000 + 41_000 | ||
| end | ||
|
|
||
| def format_stardate(stardate) do | ||
| Float.round(stardate, 1) |> to_string() | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "authors": [ | ||
| "angelikatyborska" | ||
| ], | ||
| "contributors": [ | ||
| "neenjaw" | ||
| ], | ||
| "files": { | ||
| "solution": [ | ||
| "lib/captains_log.ex" | ||
| ], | ||
| "test": [ | ||
| "test/captains_log_test.exs" | ||
| ], | ||
| "exemplar": [ | ||
| ".meta/exemplar.ex" | ||
| ] | ||
| }, | ||
| "blurb": "Learn about randomness and using Erlang libraries from Elixir by helping Mary generate stardates and starship registry numbers for her Star Trek themed pen-and-paper role playing sessions." | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| defmodule CaptainsLog do | ||
| @planetary_classes ["D", "H", "J", "K", "L", "M", "N", "R", "T", "Y"] | ||
|
|
||
| def random_planet_class() do | ||
| Enum.random(@planetary_classes) | ||
| end | ||
|
|
||
| def random_ship_registry_number() do | ||
| number = Enum.random(1000..9999) | ||
| "NCC-#{number}" | ||
| end | ||
|
|
||
| def random_stardate() do | ||
| :rand.uniform() * 1000 + 41_000 | ||
| end | ||
|
|
||
| def format_stardate(stardate) do | ||
| to_string(:io_lib.format("~.1f", [stardate])) | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"comments":[],"summary":"Submission analyzed. No automated suggestions found."} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| defmodule CaptainsLog do | ||
| @planetary_classes ["D", "H", "J", "K", "L", "M", "N", "R", "T", "Y"] | ||
|
|
||
| def random_planet_class() do | ||
| Enum.random(@planetary_classes) | ||
| end | ||
|
|
||
| def random_ship_registry_number() do | ||
| number = Enum.random(1000..9999) | ||
| "NCC-#{number}" | ||
| end | ||
|
|
||
| def random_stardate() do | ||
| :rand.uniform() * 1000 + 41_000 | ||
| end | ||
|
|
||
| def format_stardate(stardate) do | ||
| :io_lib.format("~.1f", [stardate]) |> to_string() | ||
| end | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This value is a path to a file in this repo that contains the text of the analyzer comment, so you need to create a new file over there for the analyzer to work. Could you do the appropriate change over there, link to the PR in this PR's description and request a review from me?