jsonld-ex/test/suite/to_rdf_test.exs
Marcel Otto 9c17fd1694 json_ld: some of the URI.merge problems are solved with Elixir 1.4.4
- but URI.merge still causes problems due to incomplete RFC3986 implementation
   see: https://github.com/elixir-lang/elixir/pull/6208
2017-06-09 04:14:46 +02:00

56 lines
2.2 KiB
Elixir

defmodule JSON.LD.TestSuite.ToRdfTest do
use ExUnit.Case, async: false
import JSON.LD.TestSuite
import RDF.Sigils
setup_all do
[base_iri: manifest("toRdf")["baseIri"]]
end
test_cases("toRdf")
# TODO: Ordering problems
# |> Enum.filter(fn %{"@id" => id} -> id in ~w[#t0118] end)
# TODO: Fixed in next Elixir release
# |> Enum.filter(fn %{"@id" => id} -> id in ~w[#t0102] end)
|> Enum.each(fn %{"name" => name, "input" => input} = test_case ->
if input in ~w[toRdf-0102-in.jsonld] do
@tag skip: """
caused by a another problem in Elixirs URI.merge which should be fixed with next Elixir release
https://github.com/elixir-lang/elixir/pull/6208
"""
end
if input in ~w[toRdf-0118-in.jsonld] do
@tag skip: """
Actually an isomorphic graph is generated, but due to different ordering
during expansion the generated blank nodes are named different.
"""
end
@tag :test_suite
@tag :to_rdf_test_suite
@tag data: test_case
test "#{input}: #{name}",
%{data: %{"input" => input, "expect" => output} = test_case, base_iri: base_iri} do
# This requires a special handling, since the N-Quad ouput file is not valid, by using blank nodes as predicates
dataset = if input == "toRdf-0118-in.jsonld",
do: toRdf_0118_dataset(),
else: RDF.NQuads.read_file!(file(output))
assert JSON.LD.read_file!(file(input), test_case_options(test_case, base_iri)) == dataset
end
end)
def toRdf_0118_dataset do
RDF.Dataset.new([
{RDF.bnode("b0"), ~I<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>, RDF.bnode("b0")},
{RDF.bnode("b0"), RDF.bnode("b0"), "plain value"},
{RDF.bnode("b0"), RDF.bnode("b0"), ~I<http://json-ld.org/test-suite/tests/relativeIri>},
{RDF.bnode("b0"), RDF.bnode("b0"), RDF.bnode("b0")},
{RDF.bnode("b0"), RDF.bnode("b0"), RDF.bnode("b1")},
{RDF.bnode("b0"), RDF.bnode("b0"), RDF.bnode("b2")},
{RDF.bnode("b0"), RDF.bnode("b0"), RDF.bnode("b3")},
{RDF.bnode("b1"), RDF.bnode("b0"), "term"},
{RDF.bnode("b2"), RDF.bnode("b0"), "termId"},
])
end
end