Use the manifest file on the Turtle-star test suite

This commit is contained in:
Marcel Otto 2021-12-19 04:58:38 +01:00
parent 3acda86d7e
commit e230860bbc
2 changed files with 55 additions and 27 deletions

View file

@ -7,34 +7,39 @@ defmodule RDF.Star.Turtle.W3C.EvalTest do
use ExUnit.Case, async: false use ExUnit.Case, async: false
@turtle_star_eval_test_suite Path.join(RDF.TestData.dir(), "rdf-star/turtle/eval") alias RDF.{Turtle, TestSuite, NTriples}
alias TestSuite.NS.RDFT
ExUnit.Case.register_attribute(__ENV__, :turtle_test) @path RDF.TestData.path("rdf-star/turtle/eval")
@base "http://example/base/"
@manifest TestSuite.manifest_path(@path) |> TestSuite.manifest_graph(base: @base)
@turtle_star_eval_test_suite TestSuite.test_cases(@manifest, RDFT.TestTurtleEval)
|> File.ls!() |> Enum.each(fn test_case ->
|> Enum.filter(fn file -> Path.extname(file) == ".ttl" and file != "manifest.ttl" end) @tag test_case: test_case
|> Enum.each(fn file ->
base = Path.basename(file, ".ttl")
if base in [ if (test_case |> TestSuite.test_input_file_path(@path) |> Path.basename(".ttl")) in [
"turtle-star-eval-bnode-1", "turtle-star-eval-bnode-1",
"turtle-star-eval-bnode-2", "turtle-star-eval-bnode-2",
# TODO: this one just fails, because our blank node counter starts at 0 instead of 1 # TODO: this one just fails, because our blank node counter starts at 0 instead of 1
"turtle-star-eval-annotation-2" "turtle-star-eval-annotation-2"
] do ] do
@tag earl_result: :passed
@tag earl_mode: :semi_auto
@tag skip: """ @tag skip: """
The produced graphs are correct, but have different blank node labels than the result graph. The produced graphs are correct, but have different blank node labels than the result graph.
TODO: Implement a graph isomorphism algorithm. TODO: Implement a graph isomorphism algorithm.
""" """
end end
@turtle_test ttl_file: Path.join(@turtle_star_eval_test_suite, file), test TestSuite.test_title(test_case), %{test_case: test_case} do
nt_file: Path.join(@turtle_star_eval_test_suite, base <> ".nt") assert RDF.Graph.equal?(
test "eval test: #{file}", context do TestSuite.test_input_file_path(test_case, @path)
assert RDF.Turtle.read_file!(context.registered.turtle_test[:ttl_file]) |> Turtle.read_file!()
|> RDF.Graph.clear_metadata() == |> RDF.Graph.clear_metadata(),
RDF.NTriples.read_file!(context.registered.turtle_test[:nt_file]) TestSuite.test_result_file_path(test_case, @path)
|> NTriples.read_file!()
)
end end
end) end)
end end

View file

@ -7,22 +7,45 @@ defmodule RDF.Star.Turtle.W3C.SyntaxTest do
use ExUnit.Case, async: false use ExUnit.Case, async: false
@turtle_star_syntax_test_suite Path.join(RDF.TestData.dir(), "rdf-star/turtle/syntax") alias RDF.{Turtle, TestSuite}
alias TestSuite.NS.RDFT
ExUnit.Case.register_attribute(__ENV__, :turtle_test) @path RDF.TestData.path("rdf-star/turtle/syntax")
@base "http://example/base/"
@manifest TestSuite.manifest_path(@path) |> TestSuite.manifest_graph(base: @base)
@turtle_star_syntax_test_suite TestSuite.test_cases(@manifest, RDFT.TestTurtlePositiveSyntax)
|> File.ls!() |> Enum.each(fn test_case ->
|> Enum.filter(fn file -> Path.extname(file) == ".ttl" and file != "manifest.ttl" end) @tag test_case: test_case
|> Enum.each(fn file -> test TestSuite.test_title(test_case), %{test_case: test_case} do
@turtle_test file: Path.join(@turtle_star_syntax_test_suite, file) with base = to_string(TestSuite.test_input_file(test_case)) do
if file |> String.contains?("-bad-") do assert {:ok, _} =
test "Negative syntax test: #{file}", context do TestSuite.test_input_file_path(test_case, @path)
assert {:error, _} = RDF.Turtle.read_file(context.registered.turtle_test[:file]) |> Turtle.read_file(base: base)
end end
else end
test "Positive syntax test: #{file}", context do end)
assert {:ok, %RDF.Graph{}} = RDF.Turtle.read_file(context.registered.turtle_test[:file])
TestSuite.test_cases(@manifest, RDFT.TestNTriplesPositiveSyntax)
|> Enum.each(fn test_case ->
@tag test_case: test_case
test TestSuite.test_title(test_case), %{test_case: test_case} do
with base = to_string(TestSuite.test_input_file(test_case)) do
assert {:ok, _} =
TestSuite.test_input_file_path(test_case, @path)
|> Turtle.read_file(base: base)
end
end
end)
TestSuite.test_cases(@manifest, RDFT.TestTurtleNegativeSyntax)
|> Enum.each(fn test_case ->
@tag test_case: test_case
test TestSuite.test_title(test_case), %{test_case: test_case} do
with base = to_string(TestSuite.test_input_file(test_case)) do
assert {:error, _} =
TestSuite.test_input_file_path(test_case, @path)
|> Turtle.read_file(base: base)
end end
end end
end) end)