2017-07-09 23:46:33 +00:00
|
|
|
defmodule RDF.TestSuite do
|
|
|
|
|
|
|
|
defmodule NS do
|
|
|
|
use RDF.Vocabulary.Namespace
|
|
|
|
|
|
|
|
defvocab MF,
|
2017-08-20 20:35:14 +00:00
|
|
|
base_iri: "http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#",
|
2017-07-09 23:46:33 +00:00
|
|
|
terms: [], strict: false
|
|
|
|
|
|
|
|
defvocab RDFT,
|
2017-08-20 20:35:14 +00:00
|
|
|
base_iri: "http://www.w3.org/ns/rdftest#",
|
2017-07-09 23:46:33 +00:00
|
|
|
terms: ~w[
|
|
|
|
TestTurtleEval
|
|
|
|
TestTurtlePositiveSyntax
|
|
|
|
TestTurtleNegativeSyntax
|
|
|
|
TestTurtleNegativeEval
|
|
|
|
],
|
|
|
|
strict: false
|
|
|
|
end
|
|
|
|
|
2020-04-04 23:33:42 +00:00
|
|
|
@compile {:no_warn_undefined, RDF.TestSuite.NS.MF}
|
|
|
|
@compile {:no_warn_undefined, RDF.TestSuite.NS.RDFT}
|
|
|
|
|
2017-07-09 23:46:33 +00:00
|
|
|
alias NS.MF
|
|
|
|
|
2017-08-20 20:35:14 +00:00
|
|
|
alias RDF.{Turtle, Graph, Description, IRI}
|
2017-07-09 23:46:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
def dir(format), do: Path.join(RDF.TestData.dir, String.upcase(format) <> "-TESTS")
|
|
|
|
def file(filename, format), do: format |> dir |> Path.join(filename)
|
|
|
|
def manifest_path(format), do: file("manifest.ttl", format)
|
|
|
|
|
|
|
|
def manifest_graph(format, opts \\ []) do
|
|
|
|
format
|
|
|
|
|> manifest_path
|
|
|
|
|> Turtle.read_file!(opts)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_cases(format, test_type, opts) do
|
|
|
|
format
|
|
|
|
|> manifest_graph(opts)
|
|
|
|
|> Graph.descriptions
|
|
|
|
|> Enum.filter(fn description ->
|
2017-08-20 20:35:14 +00:00
|
|
|
RDF.iri(test_type) in Description.get(description, RDF.type, [])
|
2017-07-09 23:46:33 +00:00
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_name(test_case), do: value(test_case, MF.name)
|
|
|
|
|
|
|
|
def test_title(test_case),
|
2017-07-10 00:19:20 +00:00
|
|
|
# Unfortunately OTP < 20 doesn't support unicode characters in atoms,
|
|
|
|
# so we can't put the description in the test name
|
|
|
|
# do: test_name(test_case) <> ": " <> value(test_case, RDFS.comment)
|
|
|
|
do: test_name(test_case)
|
2017-07-09 23:46:33 +00:00
|
|
|
|
2017-08-20 20:35:14 +00:00
|
|
|
def test_input_file(test_case),
|
|
|
|
do: test_case |> Description.first(MF.action) |> IRI.parse
|
|
|
|
|
|
|
|
def test_output_file(test_case),
|
|
|
|
do: test_case |> Description.first(MF.result) |> IRI.parse
|
2017-07-09 23:46:33 +00:00
|
|
|
|
|
|
|
def test_input_file_path(test_case, format),
|
|
|
|
do: test_input_file(test_case).path |> Path.basename |> file(format)
|
|
|
|
|
|
|
|
def test_result_file_path(test_case, format),
|
2017-08-20 20:35:14 +00:00
|
|
|
do: test_output_file(test_case).path |> Path.basename |> file(format)
|
2017-07-09 23:46:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
defp value(description, property),
|
|
|
|
do: Description.first(description, property) |> to_string
|
|
|
|
|
|
|
|
end
|