Use the W3C manifest files also on the N-Triples and N-Quads test suites
This commit is contained in:
parent
8e17beff71
commit
8e216c57a3
6 changed files with 109 additions and 76 deletions
|
@ -7,23 +7,34 @@ defmodule RDF.NQuads.W3C.TestSuite do
|
|||
|
||||
use ExUnit.Case, async: false
|
||||
|
||||
@w3c_nquads_test_suite Path.join(RDF.TestData.dir(), "N-QUADS-TESTS")
|
||||
alias RDF.{TestSuite, NQuads}
|
||||
alias TestSuite.NS.RDFT
|
||||
|
||||
ExUnit.Case.register_attribute(__ENV__, :nq_test)
|
||||
@path RDF.TestData.path("N-QUADS-TESTS")
|
||||
@base "http://example/base/"
|
||||
@manifest TestSuite.manifest_path(@path) |> TestSuite.manifest_graph(base: @base)
|
||||
|
||||
@w3c_nquads_test_suite
|
||||
|> File.ls!()
|
||||
|> Enum.filter(fn file -> Path.extname(file) == ".nq" end)
|
||||
|> Enum.each(fn file ->
|
||||
@nq_test file: Path.join(@w3c_nquads_test_suite, file)
|
||||
if file |> String.contains?("-bad-") do
|
||||
test "Negative syntax test: #{file}", context do
|
||||
assert {:error, _} = RDF.NQuads.read_file(context.registered.nq_test[:file])
|
||||
end
|
||||
else
|
||||
test "Positive syntax test: #{file}", context do
|
||||
assert {:ok, %RDF.Dataset{}} = RDF.NQuads.read_file(context.registered.nq_test[:file])
|
||||
end
|
||||
@manifest
|
||||
|> TestSuite.test_cases(RDFT.TestNQuadsPositiveSyntax)
|
||||
|> Enum.each(fn test_case ->
|
||||
@tag test_case: test_case
|
||||
test TestSuite.test_title(test_case), %{test_case: test_case} do
|
||||
assert {:ok, %RDF.Dataset{}} =
|
||||
test_case
|
||||
|> TestSuite.test_input_file_path(@path)
|
||||
|> NQuads.read_file()
|
||||
end
|
||||
end)
|
||||
|
||||
@manifest
|
||||
|> TestSuite.test_cases(RDFT.TestNQuadsNegativeSyntax)
|
||||
|> Enum.each(fn test_case ->
|
||||
@tag test_case: test_case
|
||||
test TestSuite.test_title(test_case), %{test_case: test_case} do
|
||||
assert {:error, _} =
|
||||
test_case
|
||||
|> TestSuite.test_input_file_path(@path)
|
||||
|> NQuads.read_file()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
|
|
@ -7,23 +7,34 @@ defmodule RDF.Star.NTriples.W3C.TestSuite do
|
|||
|
||||
use ExUnit.Case, async: false
|
||||
|
||||
@ntriples_star_test_suite Path.join(RDF.TestData.dir(), "rdf-star/nt/syntax")
|
||||
alias RDF.{TestSuite, NTriples}
|
||||
alias TestSuite.NS.RDFT
|
||||
|
||||
ExUnit.Case.register_attribute(__ENV__, :nt_test)
|
||||
@path RDF.TestData.path("rdf-star/nt/syntax")
|
||||
@base "http://example/base/"
|
||||
@manifest TestSuite.manifest_path(@path) |> TestSuite.manifest_graph(base: @base)
|
||||
|
||||
@ntriples_star_test_suite
|
||||
|> File.ls!()
|
||||
|> Enum.filter(fn file -> Path.extname(file) == ".nt" end)
|
||||
|> Enum.each(fn file ->
|
||||
@nt_test file: Path.join(@ntriples_star_test_suite, file)
|
||||
if file |> String.contains?("-bad-") do
|
||||
test "Negative syntax test: #{file}", context do
|
||||
assert {:error, _} = RDF.NTriples.read_file(context.registered.nt_test[:file])
|
||||
end
|
||||
else
|
||||
test "Positive syntax test: #{file}", context do
|
||||
assert {:ok, %RDF.Graph{}} = RDF.NTriples.read_file(context.registered.nt_test[:file])
|
||||
end
|
||||
@manifest
|
||||
|> TestSuite.test_cases(RDFT.TestNTriplesPositiveSyntax)
|
||||
|> Enum.each(fn test_case ->
|
||||
@tag test_case: test_case
|
||||
test TestSuite.test_title(test_case), %{test_case: test_case} do
|
||||
assert {:ok, %RDF.Graph{}} =
|
||||
test_case
|
||||
|> TestSuite.test_input_file_path(@path)
|
||||
|> NTriples.read_file()
|
||||
end
|
||||
end)
|
||||
|
||||
@manifest
|
||||
|> TestSuite.test_cases(RDFT.TestNTriplesNegativeSyntax)
|
||||
|> Enum.each(fn test_case ->
|
||||
@tag test_case: test_case
|
||||
test TestSuite.test_title(test_case), %{test_case: test_case} do
|
||||
assert {:error, _} =
|
||||
test_case
|
||||
|> TestSuite.test_input_file_path(@path)
|
||||
|> NTriples.read_file()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
|
|
@ -7,23 +7,34 @@ defmodule RDF.NTriples.W3C.TestSuite do
|
|||
|
||||
use ExUnit.Case, async: false
|
||||
|
||||
@w3c_ntriples_test_suite Path.join(RDF.TestData.dir(), "N-TRIPLES-TESTS")
|
||||
alias RDF.{TestSuite, NTriples}
|
||||
alias TestSuite.NS.RDFT
|
||||
|
||||
ExUnit.Case.register_attribute(__ENV__, :nt_test)
|
||||
@path RDF.TestData.path("N-TRIPLES-TESTS")
|
||||
@base "http://example/base/"
|
||||
@manifest TestSuite.manifest_path(@path) |> TestSuite.manifest_graph(base: @base)
|
||||
|
||||
@w3c_ntriples_test_suite
|
||||
|> File.ls!()
|
||||
|> Enum.filter(fn file -> Path.extname(file) == ".nt" end)
|
||||
|> Enum.each(fn file ->
|
||||
@nt_test file: Path.join(@w3c_ntriples_test_suite, file)
|
||||
if file |> String.contains?("-bad-") do
|
||||
test "Negative syntax test: #{file}", context do
|
||||
assert {:error, _} = RDF.NTriples.read_file(context.registered.nt_test[:file])
|
||||
end
|
||||
else
|
||||
test "Positive syntax test: #{file}", context do
|
||||
assert {:ok, %RDF.Graph{}} = RDF.NTriples.read_file(context.registered.nt_test[:file])
|
||||
end
|
||||
@manifest
|
||||
|> TestSuite.test_cases(RDFT.TestNTriplesPositiveSyntax)
|
||||
|> Enum.each(fn test_case ->
|
||||
@tag test_case: test_case
|
||||
test TestSuite.test_title(test_case), %{test_case: test_case} do
|
||||
assert {:ok, %RDF.Graph{}} =
|
||||
test_case
|
||||
|> TestSuite.test_input_file_path(@path)
|
||||
|> NTriples.read_file()
|
||||
end
|
||||
end)
|
||||
|
||||
@manifest
|
||||
|> TestSuite.test_cases(RDFT.TestNTriplesNegativeSyntax)
|
||||
|> Enum.each(fn test_case ->
|
||||
@tag test_case: test_case
|
||||
test TestSuite.test_title(test_case), %{test_case: test_case} do
|
||||
assert {:error, _} =
|
||||
test_case
|
||||
|> TestSuite.test_input_file_path(@path)
|
||||
|> NTriples.read_file()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
|
|
@ -8,14 +8,15 @@ defmodule RDF.Turtle.W3C.Test do
|
|||
"""
|
||||
|
||||
use ExUnit.Case, async: false
|
||||
ExUnit.Case.register_attribute(__ENV__, :test_case)
|
||||
|
||||
alias RDF.{Turtle, TestSuite, NTriples}
|
||||
alias TestSuite.NS.RDFT
|
||||
|
||||
@path RDF.TestData.path("TURTLE-TESTS")
|
||||
@base "http://www.w3.org/2013/TurtleTests/"
|
||||
@manifest TestSuite.manifest_path(@path) |> TestSuite.manifest_graph(base: @base)
|
||||
|
||||
TestSuite.test_cases("Turtle", RDFT.TestTurtleEval, base: @base)
|
||||
TestSuite.test_cases(@manifest, RDFT.TestTurtleEval)
|
||||
|> Enum.each(fn test_case ->
|
||||
@tag test_case: test_case
|
||||
if TestSuite.test_name(test_case) in ~w[
|
||||
|
@ -54,40 +55,40 @@ defmodule RDF.Turtle.W3C.Test do
|
|||
test TestSuite.test_title(test_case), %{test_case: test_case} do
|
||||
with base = to_string(TestSuite.test_input_file(test_case)) do
|
||||
assert RDF.Graph.equal?(
|
||||
TestSuite.test_input_file_path(test_case, "Turtle")
|
||||
TestSuite.test_input_file_path(test_case, @path)
|
||||
|> Turtle.read_file!(base: base),
|
||||
TestSuite.test_result_file_path(test_case, "Turtle")
|
||||
TestSuite.test_result_file_path(test_case, @path)
|
||||
|> NTriples.read_file!()
|
||||
)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
TestSuite.test_cases("Turtle", RDFT.TestTurtlePositiveSyntax, base: @base)
|
||||
TestSuite.test_cases(@manifest, RDFT.TestTurtlePositiveSyntax)
|
||||
|> 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, "Turtle")
|
||||
TestSuite.test_input_file_path(test_case, @path)
|
||||
|> Turtle.read_file(base: base)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
TestSuite.test_cases("Turtle", RDFT.TestTurtleNegativeSyntax, base: @base)
|
||||
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, "Turtle")
|
||||
TestSuite.test_input_file_path(test_case, @path)
|
||||
|> Turtle.read_file(base: base)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
TestSuite.test_cases("Turtle", RDFT.TestTurtleNegativeEval, base: @base)
|
||||
TestSuite.test_cases(@manifest, RDFT.TestTurtleNegativeEval)
|
||||
|> Enum.each(fn test_case ->
|
||||
if TestSuite.test_name(test_case) in ~w[turtle-eval-bad-01 turtle-eval-bad-02 turtle-eval-bad-03] do
|
||||
@tag skip: "TODO: IRI validation"
|
||||
|
@ -97,7 +98,7 @@ defmodule RDF.Turtle.W3C.Test do
|
|||
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, "Turtle")
|
||||
TestSuite.test_input_file_path(test_case, @path)
|
||||
|> Turtle.read_file(base: base)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,11 +2,13 @@ defmodule RDF.TestData do
|
|||
@dir Path.join(File.cwd!(), "test/data/")
|
||||
def dir, do: @dir
|
||||
|
||||
def file(name) do
|
||||
if (path = Path.join(@dir, name)) |> File.exists?() do
|
||||
def path(name) do
|
||||
path = Path.join(@dir, name)
|
||||
|
||||
if File.exists?(path) do
|
||||
path
|
||||
else
|
||||
raise "Test data file '#{name}' not found"
|
||||
raise "test data file '#{path}' not found"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,6 +14,10 @@ defmodule RDF.TestSuite do
|
|||
TestTurtlePositiveSyntax
|
||||
TestTurtleNegativeSyntax
|
||||
TestTurtleNegativeEval
|
||||
TestNTriplesPositiveSyntax
|
||||
TestNTriplesNegativeSyntax
|
||||
TestNQuadsPositiveSyntax
|
||||
TestNQuadsNegativeSyntax
|
||||
],
|
||||
strict: false
|
||||
end
|
||||
|
@ -25,23 +29,16 @@ defmodule RDF.TestSuite do
|
|||
|
||||
alias RDF.{Turtle, Graph, Description, IRI}
|
||||
|
||||
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_path(root), do: Path.join(root, "manifest.ttl")
|
||||
|
||||
def manifest_graph(format, opts \\ []) do
|
||||
format
|
||||
|> manifest_path
|
||||
|> Turtle.read_file!(opts)
|
||||
def manifest_graph(path, opts \\ []) do
|
||||
Turtle.read_file!(path, opts)
|
||||
end
|
||||
|
||||
def test_cases(format, test_type, opts) do
|
||||
format
|
||||
|> manifest_graph(opts)
|
||||
def test_cases(manifest_graph, test_type) do
|
||||
manifest_graph
|
||||
|> Graph.descriptions()
|
||||
|> Enum.filter(fn description ->
|
||||
RDF.iri(test_type) in Description.get(description, RDF.type(), [])
|
||||
end)
|
||||
|> Enum.filter(&(RDF.iri(test_type) in Description.get(&1, RDF.type(), [])))
|
||||
end
|
||||
|
||||
def test_name(test_case), do: value(test_case, MF.name())
|
||||
|
@ -58,12 +55,12 @@ defmodule RDF.TestSuite do
|
|||
def test_output_file(test_case),
|
||||
do: test_case |> Description.first(MF.result()) |> IRI.parse()
|
||||
|
||||
def test_input_file_path(test_case, format),
|
||||
do: test_input_file(test_case).path |> Path.basename() |> file(format)
|
||||
def test_input_file_path(test_case, path),
|
||||
do: Path.join(path, test_input_file(test_case).path |> Path.basename())
|
||||
|
||||
def test_result_file_path(test_case, format),
|
||||
do: test_output_file(test_case).path |> Path.basename() |> file(format)
|
||||
def test_result_file_path(test_case, path),
|
||||
do: Path.join(path, test_output_file(test_case).path |> Path.basename())
|
||||
|
||||
defp value(description, property),
|
||||
do: Description.first(description, property) |> to_string
|
||||
do: Description.first(description, property) |> to_string()
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue