Don't support cast/1 on RDF.Literal.Generic

This commit is contained in:
Marcel Otto 2020-04-16 23:42:55 +02:00
parent 060fac4675
commit 44a3ecb57a
2 changed files with 2 additions and 20 deletions

View file

@ -82,7 +82,6 @@ defmodule RDF.Literal.Generic do
def valid?(_), do: false def valid?(_), do: false
@impl Datatype @impl Datatype
def cast(%Literal{literal: %__MODULE__{}} = literal), do: literal
def cast(_), do: nil def cast(_), do: nil
@impl Datatype @impl Datatype

View file

@ -143,28 +143,11 @@ defmodule RDF.Literal.GenericTest do
end end
describe "cast/1" do describe "cast/1" do
test "when given a RDF.Literal.Generic literal" do test "always return nil (RDF.Literal.Generic does not support cast)" do
Enum.each @valid, fn {input, {_, datatype}} -> Enum.each @valid, fn {input, {_, datatype}} ->
assert (Generic.new(input, datatype: datatype) |> Generic.cast()) == assert (Generic.new(input, datatype: datatype) |> Generic.cast()) == nil
Generic.new(input, datatype: datatype)
end end
end end
test "when given a literal with a datatype which is not castable" do
assert RDF.XSD.String.new("foo") |> Generic.cast() == nil
assert RDF.XSD.Integer.new(12345) |> Generic.cast() == nil
end
test "with invalid literals" do
assert RDF.XSD.Integer.new(3.14) |> Generic.cast() == nil
assert RDF.XSD.Decimal.new("NAN") |> Generic.cast() == nil
assert RDF.XSD.Double.new(true) |> Generic.cast() == nil
end
test "with non-coercible value" do
assert Generic.cast(:foo) == nil
assert Generic.cast(make_ref()) == nil
end
end end
test "equal_value?/2" do test "equal_value?/2" do