Don't support cast/1 on RDF.Literal.Generic
This commit is contained in:
parent
060fac4675
commit
44a3ecb57a
2 changed files with 2 additions and 20 deletions
|
@ -82,7 +82,6 @@ defmodule RDF.Literal.Generic do
|
|||
def valid?(_), do: false
|
||||
|
||||
@impl Datatype
|
||||
def cast(%Literal{literal: %__MODULE__{}} = literal), do: literal
|
||||
def cast(_), do: nil
|
||||
|
||||
@impl Datatype
|
||||
|
|
|
@ -143,28 +143,11 @@ defmodule RDF.Literal.GenericTest do
|
|||
end
|
||||
|
||||
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}} ->
|
||||
assert (Generic.new(input, datatype: datatype) |> Generic.cast()) ==
|
||||
Generic.new(input, datatype: datatype)
|
||||
assert (Generic.new(input, datatype: datatype) |> Generic.cast()) == nil
|
||||
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
|
||||
|
||||
test "equal_value?/2" do
|
||||
|
|
Loading…
Reference in a new issue