Fix regression in handling of vocabulary terms as generic datatypes
This commit is contained in:
parent
6873ba4da1
commit
4d3d60a5f4
2 changed files with 12 additions and 2 deletions
|
@ -11,6 +11,7 @@ defmodule RDF.Literal.Generic do
|
|||
|
||||
alias RDF.Literal.Datatype
|
||||
alias RDF.{Literal, IRI}
|
||||
import RDF.Guards
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
value: String.t,
|
||||
|
@ -20,8 +21,9 @@ defmodule RDF.Literal.Generic do
|
|||
@impl Datatype
|
||||
@spec new(any, String.t | IRI.t | keyword) :: Literal.t
|
||||
def new(value, datatype_or_opts \\ [])
|
||||
def new(value, datatype) when is_binary(datatype), do: new(value, datatype: datatype)
|
||||
def new(value, %IRI{} = datatype), do: new(value, datatype: datatype)
|
||||
def new(value, datatype) when is_binary(datatype) or maybe_ns_term(datatype),
|
||||
do: new(value, datatype: datatype)
|
||||
def new(value, opts) do
|
||||
%Literal{
|
||||
literal: %__MODULE__{
|
||||
|
@ -34,6 +36,7 @@ defmodule RDF.Literal.Generic do
|
|||
defp normalize_datatype(nil), do: nil
|
||||
defp normalize_datatype(""), do: nil
|
||||
defp normalize_datatype(%IRI{} = datatype), do: to_string(datatype)
|
||||
defp normalize_datatype(datatype) when maybe_ns_term(datatype), do: datatype |> RDF.iri() |> to_string()
|
||||
defp normalize_datatype(datatype), do: datatype
|
||||
|
||||
@impl Datatype
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
defmodule RDF.Literal.GenericTest do
|
||||
use ExUnit.Case
|
||||
use RDF.Test.Case
|
||||
|
||||
alias RDF.Literal
|
||||
alias RDF.Literal.Generic
|
||||
|
@ -27,6 +27,13 @@ defmodule RDF.Literal.GenericTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "with datatype as a vocabulary term" do
|
||||
datatype = EX.Datatype |> RDF.iri() |> to_string()
|
||||
assert %Literal{literal: %Generic{value: "foo", datatype: ^datatype}} =
|
||||
Generic.new("foo", datatype: EX.Datatype)
|
||||
assert Generic.new("foo", EX.Datatype) == Generic.new("foo", datatype: EX.Datatype)
|
||||
end
|
||||
|
||||
test "with canonicalize opts" do
|
||||
Enum.each @valid, fn {input, {value, datatype}} ->
|
||||
assert %Literal{literal: %Generic{value: ^value, datatype: ^datatype}} =
|
||||
|
|
Loading…
Reference in a new issue