Separate N-Triples and N-Quads W3C test suites

This commit is contained in:
Marcel Otto 2017-07-06 21:47:04 +02:00
parent 06dbddaf3f
commit 4c96499353
5 changed files with 65 additions and 53 deletions

View file

@ -0,0 +1,31 @@
defmodule RDF.NQuads.W3C.TestSuite do
@moduledoc """
The official W3C RDF 1.1 N-Quads Test Suite.
from <https://www.w3.org/2013/N-QuadsTests/>
"""
use ExUnit.Case, async: false
@w3c_nquads_test_suite Path.join(RDF.TestData.dir, "N-QUADS-TESTS")
ExUnit.Case.register_attribute __ENV__, :nq_test
@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
end
end)
end

View file

@ -0,0 +1,30 @@
defmodule RDF.NTriples.W3C.TestSuite do
@moduledoc """
The official W3C RDF 1.1 N-Triples Test Suite.
from <https://www.w3.org/2013/N-TriplesTests/>
"""
use ExUnit.Case, async: false
@w3c_ntriples_test_suite Path.join(RDF.TestData.dir, "N-TRIPLES-TESTS")
ExUnit.Case.register_attribute __ENV__, :nt_test
@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
end
end)
end

View file

@ -3,10 +3,11 @@ defmodule RDF.NQuads.DecoderTest do
doctest RDF.NQuads.Decoder
alias RDF.{Dataset, TestData}
alias RDF.Dataset
import RDF.Sigils
use RDF.Vocabulary.Namespace
defvocab EX,
@ -18,8 +19,6 @@ defmodule RDF.NQuads.DecoderTest do
terms: [], strict: false
@w3c_nquads_test_suite Path.join(TestData.dir, "N-QUADS-TESTS")
test "an empty string is deserialized to an empty graph" do
assert RDF.NQuads.Decoder.decode!("") == Dataset.new
assert RDF.NQuads.Decoder.decode!(" \n\r\r\n ") == Dataset.new
@ -152,27 +151,4 @@ defmodule RDF.NQuads.DecoderTest do
])
end
describe "the official W3C RDF 1.1 N-Quads Test Suite" do
# from https://www.w3.org/2013/N-QuadsTests/
ExUnit.Case.register_attribute __ENV__, :nq_test
@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
end
end)
end
end

View file

@ -3,7 +3,7 @@ defmodule RDF.NTriples.DecoderTest do
doctest RDF.NTriples.Decoder
alias RDF.{Graph, TestData}
alias RDF.Graph
use RDF.Vocabulary.Namespace
@ -17,8 +17,6 @@ defmodule RDF.NTriples.DecoderTest do
terms: [], strict: false
@w3c_ntriples_test_suite Path.join(TestData.dir, "N-TRIPLES-TESTS")
test "an empty string is deserialized to an empty graph" do
assert RDF.NTriples.Decoder.decode!("") == Graph.new
assert RDF.NTriples.Decoder.decode!(" \n\r\r\n ") == Graph.new
@ -133,27 +131,4 @@ defmodule RDF.NTriples.DecoderTest do
])
end
describe "the official W3C RDF 1.1 N-Triples Test Suite" do
# from https://www.w3.org/2013/N-TriplesTests/
ExUnit.Case.register_attribute __ENV__, :nt_test
@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
end
end)
end
end

View file

@ -5,7 +5,7 @@ defmodule RDF.Turtle.DecoderTest do
import RDF.Sigils
alias RDF.{Turtle, Graph, TestData}
alias RDF.{Turtle, Graph}
alias RDF.NS.{XSD}