Skip to content

Commit

Permalink
fix: literal type to match only when value types equal
Browse files Browse the repository at this point in the history
  • Loading branch information
tlux committed Mar 25, 2024
1 parent ff0be8c commit 05f44a7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 4 additions & 6 deletions lib/vx/literal.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,10 @@ defmodule Vx.Literal do
end

defimpl Vx.Validatable do
def validate(%{value: value}, actual_value) do
if value == actual_value do
:ok
else
{:error, "must be #{Kernel.inspect(value)}"}
end
def validate(%{value: value}, value), do: :ok

def validate(%{value: value}, _value) do
{:error, "must be #{Kernel.inspect(value)}"}
end
end

Expand Down
2 changes: 2 additions & 0 deletions test/vx/literal_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ defmodule Vx.LiteralTest do
assert {:error, error} = Vx.validate(Vx.Literal.t(value), "bar")
assert Exception.message(error) == "must be #{inspect(value)}"
end)

assert {:error, _} = Vx.validate(Vx.Literal.t(123.0), 123)
end
end
end

0 comments on commit 05f44a7

Please sign in to comment.