From 74af0e95e55f7d5ccac8abd80bf8ae1e50771b23 Mon Sep 17 00:00:00 2001 From: Marcel Otto Date: Fri, 28 Apr 2017 00:04:27 +0200 Subject: [PATCH] json_ld: proper JSON-LD Data Round Tripping --- test/support/rdf_datatype_case.ex | 36 ++++++++++++++--------------- test/unit/datatypes/double_test.exs | 1 + 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/test/support/rdf_datatype_case.ex b/test/support/rdf_datatype_case.ex index e2960c4..872ba3e 100644 --- a/test/support/rdf_datatype_case.ex +++ b/test/support/rdf_datatype_case.ex @@ -50,25 +50,14 @@ defmodule RDF.Datatype.Test.Case do end end - # valid value with canonical option - Enum.each @valid, fn {input, {value, _, _}} -> - expected_literal = - %Literal{value: value, datatype: unquote(datatype_id), language: nil} - @tag example: %{input: input, output: expected_literal} - test "valid: #{unquote(datatype)}.new(#{inspect input}, canonicalize: true) == #{inspect expected_literal}", - %{example: example} do - assert unquote(datatype).new(example.input, canonicalize: true) == example.output + test "canonicalize option" do + Enum.each @valid, fn {input, _} -> + assert unquote(datatype).new(input, canonicalize: true) == + (unquote(datatype).new(input) |> Literal.canonical) end - end - - # invalid value with canonical option - Enum.each @invalid, fn value -> - expected_literal = - %Literal{uncanonical_lexical: to_string(value), datatype: unquote(datatype_id), language: nil} - @tag example: %{input: value, output: expected_literal} - test "invalid: #{unquote(datatype)}.new(#{inspect value}, canonicalize: true) == #{inspect expected_literal}", - %{example: example} do - assert unquote(datatype).new(example.input, canonicalize: true) == example.output + Enum.each @invalid, fn input -> + assert unquote(datatype).new(input, canonicalize: true) == + (unquote(datatype).new(input) |> Literal.canonical) end end @@ -172,6 +161,17 @@ defmodule RDF.Datatype.Test.Case do end end +# describe "general equality" do +# test "a Literal initialized with a native value is equal to a Literal with its canonical form" do +# Enum.each @valid, fn {_, {value, _, canonicalized}} -> +# assert unquote(datatype).new(value) == unquote(datatype).new(canonicalized) +## assert Literal.valid? unquote(datatype).new(value) +# end +# +# end +# +# end + end end diff --git a/test/unit/datatypes/double_test.exs b/test/unit/datatypes/double_test.exs index 4efe4f2..a156e40 100644 --- a/test/unit/datatypes/double_test.exs +++ b/test/unit/datatypes/double_test.exs @@ -4,6 +4,7 @@ defmodule RDF.DoubleTest do # input => { value , lexical , canonicalized } 0 => { 0.0 , "0.0" , "0.0E0" }, 42 => { 42.0 , "42.0" , "4.2E1" }, + 0.0E0 => { 0.0 , "0.0" , "0.0E0" }, 1.0E0 => { 1.0 , "1.0" , "1.0E0" }, :positive_infinity => { :positive_infinity , nil , "INF" }, :negative_infinity => { :negative_infinity , nil , "-INF" },