rdf-ex/test/support/test_suite.ex

73 lines
2 KiB
Elixir
Raw Normal View History

2017-07-09 23:46:33 +00:00
defmodule RDF.TestSuite do
defmodule NS do
use RDF.Vocabulary.Namespace
defvocab MF,
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,
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
@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
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 ->
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),
# 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
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),
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