Skip to content

Commit

Permalink
Show in test that special forms are local functions
Browse files Browse the repository at this point in the history
  • Loading branch information
angelikatyborska committed Dec 26, 2023
1 parent ffb976b commit d555e17
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 29 deletions.
4 changes: 2 additions & 2 deletions lib/elixir_analyzer/test_suite/file_sniffer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ defmodule ElixirAnalyzer.TestSuite.FileSniffer do
assert_call "use <<>> to pattern match a bitstring in function body" do
type :essential
comment Constants.file_sniffer_use_bitstring()
called_fn module: Kernel, name: :<<>>
called_fn name: :<<>>
calling_fn module: FileSniffer, name: :type_from_binary
end

assert_call "use :: in bitstrings to specify segment type when pattern matching in function body" do
type :essential
comment Constants.file_sniffer_use_bitstring()
called_fn module: Kernel, name: :"::"
called_fn name: :"::"
calling_fn module: FileSniffer, name: :type_from_binary
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ defmodule ElixirAnalyzer.ExerciseTest.AssertCall.FunctionHeadCallTest do
test_exercise_analysis "calls from the wrong function",
comments: [
"didn't find any call to Kernel.is_integer/1 from main_function/1",
"didn't find any call to Kernel.|/2 from main_function/1",
"didn't find any call to |/2 from main_function/1",
"didn't find any call to Kernel.@/1 from main_function/1"
] do
[
Expand Down Expand Up @@ -100,7 +100,7 @@ defmodule ElixirAnalyzer.ExerciseTest.AssertCall.FunctionHeadCallTest do
comments: [
"didn't find any call to Kernel.>/2 from anywhere",
"didn't find any call to Kernel.is_integer/1 from main_function/1",
"didn't find any call to Kernel.|/2 from main_function/1",
"didn't find any call to |/2 from main_function/1",
"didn't find any call to Kernel.@/1 from main_function/1"
] do
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ defmodule ElixirAnalyzer.ExerciseTest.AssertCall.KernelTest do
"didn't find a call to Kernel.dbg/0",
"didn't find a call to dbg/0",
"didn't find a call to Kernel.self/0",
"didn't find a call to self/0"
"didn't find a call to self/0",
"didn't find a call to <<>>/1"
] do
defmodule AssertCallVerification do
def function() do
Expand Down Expand Up @@ -62,4 +63,29 @@ defmodule ElixirAnalyzer.ExerciseTest.AssertCall.KernelTest do
end
]
end

test_exercise_analysis "Calling <<>>/1",
comments_exclude: [
"didn't find a call to <<>>/1"
] do
[
defmodule AssertCallVerification do
def function() do
<<a, b, c>> = <<1, 2, 3>>
a
end
end,
defmodule AssertCallVerification do
def function() do
<<a, b, c>> = <<1, 2, 3>>

if b > 2 do
a + c
else
nil
end
end
end
]
end
end
48 changes: 27 additions & 21 deletions test/elixir_analyzer/test_suite/file_sniffer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,37 @@ defmodule ElixirAnalyzer.ExerciseTest.FileSnifferTest do
def type_from_binary(<<?\d, ?E, ?L, ?F, _::binary>>),
do: "application/octet-stream"
end,
def type_from_binary(file_binary) do
case file_binary do
<<0x7F, 0x45, 0x4C, 0x46, rest::binary>> -> "application/octet-stream"
<<0x42, 0x4D, rest::binary>> -> "image/bmp"
<<0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, rest::binary>> -> "image/png"
<<0xFF, 0xD8, 0xFF, rest::binary>> -> "image/jpg"
<<0x47, 0x49, 0x46, rest::binary>> -> "image/gif"
defmodule FileSniffer do
def type_from_binary(file_binary) do
case file_binary do
<<0x7F, 0x45, 0x4C, 0x46, rest::binary>> -> "application/octet-stream"
<<0x42, 0x4D, rest::binary>> -> "image/bmp"
<<0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, rest::binary>> -> "image/png"
<<0xFF, 0xD8, 0xFF, rest::binary>> -> "image/jpg"
<<0x47, 0x49, 0x46, rest::binary>> -> "image/gif"
end
end
end,
def type_from_binary(file_binary) do
case file_binary do
<<0x7F, 0x45, 0x4C, 0x46, rest::bitstring>> -> "application/octet-stream"
<<0x42, 0x4D, rest::bitstring>> -> "image/bmp"
<<0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, rest::bitstring>> -> "image/png"
<<0xFF, 0xD8, 0xFF, rest::bitstring>> -> "image/jpg"
<<0x47, 0x49, 0x46, rest::bitstring>> -> "image/gif"
defmodule FileSniffer do
def type_from_binary(file_binary) do
case file_binary do
<<0x7F, 0x45, 0x4C, 0x46, rest::bitstring>> -> "application/octet-stream"
<<0x42, 0x4D, rest::bitstring>> -> "image/bmp"
<<0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, rest::bitstring>> -> "image/png"
<<0xFF, 0xD8, 0xFF, rest::bitstring>> -> "image/jpg"
<<0x47, 0x49, 0x46, rest::bitstring>> -> "image/gif"
end
end
end,
def type_from_binary(file_binary) do
case file_binary do
<<0x7F, 0x45, 0x4C, 0x46, rest::bits>> -> "application/octet-stream"
<<0x42, 0x4D, rest::bits>> -> "image/bmp"
<<0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, rest::bits>> -> "image/png"
<<0xFF, 0xD8, 0xFF, rest::bits>> -> "image/jpg"
<<0x47, 0x49, 0x46, rest::bits>> -> "image/gif"
defmodule FileSniffer do
def type_from_binary(file_binary) do
case file_binary do
<<0x7F, 0x45, 0x4C, 0x46, rest::bits>> -> "application/octet-stream"
<<0x42, 0x4D, rest::bits>> -> "image/bmp"
<<0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, rest::bits>> -> "image/png"
<<0xFF, 0xD8, 0xFF, rest::bits>> -> "image/jpg"
<<0x47, 0x49, 0x46, rest::bits>> -> "image/gif"
end
end
end,
defmodule FileSniffer do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ defmodule ElixirAnalyzer.Support.AnalyzerVerification.AssertCall.FunctionHeadCal
comment "didn't find any call to Kernel.is_integer/1 from main_function/1"
end

assert_call "find a call to Kernel.|/2 from main_function" do
assert_call "find a call to |/2 from main_function" do
type :informative
called_fn module: Kernel, name: :|
called_fn name: :|
calling_fn module: AssertCallVerification, name: :main_function
comment "didn't find any call to Kernel.|/2 from main_function/1"
comment "didn't find any call to |/2 from main_function/1"
end

assert_call "find a call to Kernel.@/1 from main_function" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,10 @@ defmodule ElixirAnalyzer.Support.AnalyzerVerification.AssertCall.Kernel do
called_fn name: :self
comment "didn't find a call to self/0"
end

assert_call "finds call to Kernel.SpecialForms.<<>>/1 without module" do
type :informative
called_fn name: :<<>>
comment "didn't find a call to <<>>/1"
end
end

0 comments on commit d555e17

Please sign in to comment.