Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/bertex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ defmodule Bertex do
end

defimpl Bert, for: Any do
def encode(term), do: term
def decode(term), do: term
def encode(term) when is_integer(term) or is_float(term) or is_binary(term) or is_map(term), do: term
def decode(term) when is_integer(term) or is_float(term) or is_binary(term) or is_map(term), do: term
end

@doc """
Expand Down
8 changes: 8 additions & 0 deletions test/bertex_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,12 @@ defmodule Bertex.Test do
{:ok, date} = DateTime.from_naive(naive, "Etc/UTC")
assert decode(term_to_binary({:bert, :time, 1255, 270321, 0})) == date
end

test "refuses to encode a function" do
catch_error(encode(fn x -> x end))
end

test "refuses to decode a function" do
catch_error(decode(term_to_binary(fn x -> x + 1 end)))
end
end