Fix RDF.Double to not accept +INF as a valid value

This commit is contained in:
Marcel Otto 2019-06-20 22:27:06 +02:00
parent 874b0d5eea
commit dc2b070e05
4 changed files with 4 additions and 5 deletions

View file

@ -23,6 +23,7 @@ This project adheres to [Semantic Versioning](http://semver.org/) and
correctly
- `true` and `false` with capital letters are no longer valid `RDF.Boolean`s
following the XSD specification; the same applies for booleans in Turtle
- `+INF` is no longer a valid `RDF.Double` (positive infinity doesn't expect a sign)
[Compare v0.6.0...HEAD](https://github.com/marcelotto/rdf-ex/compare/v0.6.0...HEAD)

View file

@ -40,7 +40,6 @@ defmodule RDF.Double do
:error ->
case String.upcase(value) do
"INF" -> :positive_infinity
"+INF" -> :positive_infinity
"-INF" -> :negative_infinity
"NAN" -> :nan
_ -> super(value, opts)

View file

@ -92,7 +92,7 @@ defmodule RDF.BooleanTest do
assert RDF.double(1) |> RDF.Boolean.cast() == RDF.true
assert RDF.double(0.1) |> RDF.Boolean.cast() == RDF.true
assert RDF.double("+INF") |> RDF.Boolean.cast() == RDF.true
assert RDF.double("-INF") |> RDF.Boolean.cast() == RDF.true
end
@tag skip: "TODO: RDF.Float datatype"

View file

@ -25,11 +25,10 @@ defmodule RDF.DoubleTest do
"3E1" => { 3.0E1 , "3E1" , "3.0E1" },
"INF" => { :positive_infinity , nil , "INF" },
"Inf" => { :positive_infinity , "Inf" , "INF" },
"+INF" => { :positive_infinity , "+INF" , "INF" },
"-INF" => { :negative_infinity , nil , "-INF" },
"NaN" => { :nan , nil , "NaN" },
},
invalid: ~w(foo 12.xyz 1.0ez) ++ [true, false, "1.1e1 foo", "foo 1.1e1"]
invalid: ~w(foo 12.xyz 1.0ez +INF) ++ [true, false, "1.1e1 foo", "foo 1.1e1"]
describe "equality" do
@ -63,7 +62,7 @@ defmodule RDF.DoubleTest do
test "casting a double returns the input as it is" do
assert RDF.double(3.14) |> RDF.Double.cast() == RDF.double(3.14)
assert RDF.double("NAN") |> RDF.Double.cast() == RDF.double("NAN")
assert RDF.double("+INF") |> RDF.Double.cast() == RDF.double("+INF")
assert RDF.double("-INF") |> RDF.Double.cast() == RDF.double("-INF")
end
test "casting a boolean" do