Various datatype fixes
This commit is contained in:
parent
6049798b37
commit
2be689b2a1
4 changed files with 68 additions and 5 deletions
11
lib/rdf.ex
11
lib/rdf.ex
|
@ -239,15 +239,18 @@ defmodule RDF do
|
|||
|
||||
for datatype <- RDF.Literal.Datatype.Registry.datatypes() -- [RDF.LangString] do
|
||||
defdelegate unquote(String.to_atom(datatype.name))(value), to: datatype, as: :new
|
||||
defdelegate unquote(String.to_atom(datatype.name))(value, opts), to: datatype, as: :new
|
||||
|
||||
elixir_name = Macro.underscore(datatype.name)
|
||||
unless datatype.name == elixir_name do
|
||||
defdelegate unquote(String.to_atom(elixir_name))(value), to: datatype, as: :new
|
||||
defdelegate unquote(String.to_atom(elixir_name))(value, opts), to: datatype, as: :new
|
||||
end
|
||||
end
|
||||
|
||||
defdelegate lang_string(value, opts), to: RDF.LangString, as: :new
|
||||
defdelegate date_time(value), to: RDF.XSD.DateTime, as: :new
|
||||
defdelegate date_time(value, opts), to: RDF.XSD.DateTime, as: :new
|
||||
defdelegate datetime(value), to: RDF.XSD.DateTime, as: :new
|
||||
defdelegate datetime(value, opts), to: RDF.XSD.DateTime, as: :new
|
||||
defdelegate any_uri(value), to: RDF.XSD.AnyURI, as: :new
|
||||
defdelegate any_uri(value, opts), to: RDF.XSD.AnyURI, as: :new
|
||||
|
||||
defdelegate prefix_map(prefixes), to: RDF.PrefixMap, as: :new
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ defmodule RDF.Numeric do
|
|||
|
||||
import Kernel, except: [abs: 1, floor: 1, ceil: 1, round: 1]
|
||||
|
||||
@datatypes MapSet.new(XSD.Numeric.datatypes(), &RDF.Literal.Datatype.Registry.rdf_datatype/1)
|
||||
@datatypes XSD.Numeric.datatypes()
|
||||
|
||||
@doc """
|
||||
The set of all numeric datatypes.
|
||||
|
|
55
test/unit/literal/datatype/registry_test.exs
Normal file
55
test/unit/literal/datatype/registry_test.exs
Normal file
|
@ -0,0 +1,55 @@
|
|||
defmodule RDF.Literal.Datatype.RegistryTest do
|
||||
use ExUnit.Case
|
||||
|
||||
alias RDF.Literal.Datatype
|
||||
alias RDF.NS
|
||||
|
||||
@unsupported_xsd_datatypes ~w[
|
||||
ENTITIES
|
||||
IDREF
|
||||
language
|
||||
Name
|
||||
normalizedString
|
||||
dayTimeDuration
|
||||
QName
|
||||
gYear
|
||||
NMTOKENS
|
||||
gDay
|
||||
NOTATION
|
||||
ID
|
||||
duration
|
||||
hexBinary
|
||||
ENTITY
|
||||
yearMonthDuration
|
||||
IDREFS
|
||||
base64Binary
|
||||
token
|
||||
NCName
|
||||
NMTOKEN
|
||||
gYearMonth
|
||||
gMonth
|
||||
gMonthDay
|
||||
]
|
||||
|> Enum.map(fn xsd_datatype_name -> RDF.iri(NS.XSD.__base_iri__ <> xsd_datatype_name) end)
|
||||
|
||||
@supported_xsd_datatypes RDF.NS.XSD.__iris__() -- @unsupported_xsd_datatypes
|
||||
|
||||
|
||||
describe "get/1" do
|
||||
test "IRIs of supported datatypes from the XSD namespace" do
|
||||
Enum.each(@supported_xsd_datatypes, fn xsd_datatype_iri ->
|
||||
assert xsd_datatype = Datatype.Registry.get(xsd_datatype_iri)
|
||||
assert xsd_datatype == Datatype.Registry.get(to_string(xsd_datatype_iri))
|
||||
assert RDF.iri(xsd_datatype.id) == xsd_datatype_iri
|
||||
|
||||
end)
|
||||
end
|
||||
|
||||
test "IRIs of unsupported datatypes from the XSD namespace" do
|
||||
Enum.each(@unsupported_xsd_datatypes, fn xsd_datatype_iri ->
|
||||
refute Datatype.Registry.get(xsd_datatype_iri)
|
||||
refute Datatype.Registry.get(to_string(xsd_datatype_iri))
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -71,6 +71,11 @@ defmodule RDF.LiteralTest do
|
|||
RDF.XSD.Decimal.new(Decimal.from_float(3.14))
|
||||
end
|
||||
|
||||
test "unsignedInt" do
|
||||
assert Literal.new(42, datatype: NS.XSD.unsignedInt) == RDF.XSD.UnsignedInt.new(42)
|
||||
assert Literal.new("42", datatype: NS.XSD.unsignedInt) == RDF.XSD.UnsignedInt.new("42")
|
||||
end
|
||||
|
||||
test "string" do
|
||||
assert Literal.new("foo", datatype: NS.XSD.string) == RDF.XSD.String.new("foo")
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue