Skip to content

Commit

Permalink
Add test on protocols
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Dec 26, 2024
1 parent 51c0bcd commit 635b77e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/elixir/test/elixir/protocol_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,29 @@ defmodule ProtocolTest do
end
end

test "built-in protocols" do
builtin_protocols =
for app <- ~w[eex elixir ex_unit iex logger mix]a,
Application.ensure_loaded(app),
module <- Application.spec(app, :modules),
Code.ensure_loaded(module),
function_exported?(module, :__protocol__, 1),
do: module

# If this test fails, update:
# * lib/elixir/lib/module/types/apply.ex
# * lib/elixir/scripts/elixir_docs.ex
assert Enum.sort(builtin_protocols) == [
Collectable,
Enumerable,
IEx.Info,
Inspect,
JSON.Encoder,
List.Chars,
String.Chars
]
end

test "protocol implementations without any" do
assert is_nil(Sample.impl_for(:foo))
assert is_nil(Sample.impl_for(fn x -> x end))
Expand Down

0 comments on commit 635b77e

Please sign in to comment.