Various fixes of RDF.Datatype.cast/1 implementations
This commit is contained in:
parent
e0635b42ad
commit
97b1cec4aa
5 changed files with 17 additions and 16 deletions
|
@ -44,12 +44,8 @@ defmodule RDF.Boolean do
|
|||
!Decimal.equal?(literal.value, 0)
|
||||
|> new()
|
||||
|
||||
is_xsd_double(datatype) or is_xsd_float(datatype) ->
|
||||
literal.value not in [0.0, :nan]
|
||||
|> new()
|
||||
|
||||
RDF.Numeric.type?(datatype) ->
|
||||
literal.value
|
||||
literal.value not in [0, 0.0, :nan]
|
||||
|> new()
|
||||
|
||||
true ->
|
||||
|
|
|
@ -36,9 +36,10 @@ defmodule RDF.Integer do
|
|||
new(1)
|
||||
|
||||
is_xsd_string(datatype) ->
|
||||
literal.value
|
||||
|> new()
|
||||
|> canonical()
|
||||
case Integer.parse(literal.value) do
|
||||
{value, _} -> new(value)
|
||||
_ -> nil
|
||||
end
|
||||
|
||||
is_xsd_decimal(datatype) ->
|
||||
literal.value
|
||||
|
|
|
@ -62,8 +62,9 @@ defmodule RDF.BooleanTest do
|
|||
end
|
||||
|
||||
test "casting an integer" do
|
||||
assert RDF.integer(0) |> RDF.Boolean.cast() == RDF.false
|
||||
assert RDF.integer(1) |> RDF.Boolean.cast() == RDF.true
|
||||
assert RDF.integer(0) |> RDF.Boolean.cast() == RDF.false
|
||||
assert RDF.integer(1) |> RDF.Boolean.cast() == RDF.true
|
||||
assert RDF.integer(42) |> RDF.Boolean.cast() == RDF.true
|
||||
end
|
||||
|
||||
test "casting a decimal" do
|
||||
|
|
|
@ -72,8 +72,9 @@ defmodule RDF.DoubleTest do
|
|||
end
|
||||
|
||||
test "casting a string" do
|
||||
assert RDF.string("1.0") |> RDF.Double.cast() == RDF.double("1.0E0")
|
||||
assert RDF.string("3.14") |> RDF.Double.cast() == RDF.double("3.14E0")
|
||||
assert RDF.string("1.0") |> RDF.Double.cast() == RDF.double("1.0E0")
|
||||
assert RDF.string("3.14") |> RDF.Double.cast() == RDF.double("3.14E0")
|
||||
assert RDF.string("3.14E0") |> RDF.Double.cast() == RDF.double("3.14E0")
|
||||
end
|
||||
|
||||
test "casting an integer" do
|
||||
|
@ -82,9 +83,9 @@ defmodule RDF.DoubleTest do
|
|||
end
|
||||
|
||||
test "casting a decimal" do
|
||||
assert RDF.decimal(0) |> RDF.Double.cast() == RDF.double(0)
|
||||
assert RDF.decimal(1) |> RDF.Double.cast() == RDF.double(1)
|
||||
assert RDF.decimal(3.14) |> RDF.Double.cast() == RDF.double(3.14)
|
||||
assert RDF.decimal(0) |> RDF.Double.cast() == RDF.double(0)
|
||||
assert RDF.decimal(1) |> RDF.Double.cast() == RDF.double(1)
|
||||
assert RDF.decimal(3.14) |> RDF.Double.cast() == RDF.double(3.14)
|
||||
end
|
||||
|
||||
@tag skip: "TODO: RDF.Float datatype"
|
||||
|
|
|
@ -28,7 +28,9 @@ defmodule RDF.IntegerTest do
|
|||
end
|
||||
|
||||
test "casting a string" do
|
||||
assert RDF.string("0") |> RDF.Integer.cast() == RDF.integer(0)
|
||||
assert RDF.string("0") |> RDF.Integer.cast() == RDF.integer(0)
|
||||
assert RDF.string("042") |> RDF.Integer.cast() == RDF.integer(42)
|
||||
assert RDF.string("3.14") |> RDF.Integer.cast() == RDF.integer(3)
|
||||
end
|
||||
|
||||
test "casting an decimal" do
|
||||
|
|
Loading…
Reference in a new issue