From dc2b070e0572822718b7ea108e198a5f4218aef1 Mon Sep 17 00:00:00 2001 From: Marcel Otto Date: Thu, 20 Jun 2019 22:27:06 +0200 Subject: [PATCH] Fix RDF.Double to not accept +INF as a valid value --- CHANGELOG.md | 1 + lib/rdf/datatypes/double.ex | 1 - test/unit/datatypes/boolean_test.exs | 2 +- test/unit/datatypes/double_test.exs | 5 ++--- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 95f44f2..9f15bab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/lib/rdf/datatypes/double.ex b/lib/rdf/datatypes/double.ex index 737c4f3..99206ea 100644 --- a/lib/rdf/datatypes/double.ex +++ b/lib/rdf/datatypes/double.ex @@ -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) diff --git a/test/unit/datatypes/boolean_test.exs b/test/unit/datatypes/boolean_test.exs index c37b96d..3cae9bd 100644 --- a/test/unit/datatypes/boolean_test.exs +++ b/test/unit/datatypes/boolean_test.exs @@ -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" diff --git a/test/unit/datatypes/double_test.exs b/test/unit/datatypes/double_test.exs index b5e8f76..c9af7ef 100644 --- a/test/unit/datatypes/double_test.exs +++ b/test/unit/datatypes/double_test.exs @@ -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