diff --git a/nquads/nquad_tests.tar.gz b/nquads/nquad_tests.tar.gz new file mode 100644 index 0000000..f041493 Binary files /dev/null and b/nquads/nquad_tests.tar.gz differ diff --git a/nquads/nquads.rl b/nquads/nquads.rl index 990213a..b5b3529 100644 --- a/nquads/nquads.rl +++ b/nquads/nquads.rl @@ -57,8 +57,7 @@ | 0x0b .. 0x0c | 0x0e .. '!' | '#' .. '[' - | ']' .. '~' - | 0x80 .. 0x10ffff + | ']' .. 0x10ffff | ECHAR | UCHAR)* '"' @@ -90,9 +89,9 @@ statement := ( whitespace* subject >StartSubject %SetSubject - whitespace+ predicate >StartPredicate %SetPredicate - whitespace+ object >StartObject %SetObject - (whitespace+ graphLabel >StartLabel %SetLabel)? + whitespace* predicate >StartPredicate %SetPredicate + whitespace* object >StartObject %SetObject + (whitespace* graphLabel >StartLabel %SetLabel)? whitespace* '.' whitespace* ('#' any*)? >Comment ) %Return @!Error ; }%% diff --git a/nquads/nquads_test.go b/nquads/nquads_test.go index 337d918..827691d 100644 --- a/nquads/nquads_test.go +++ b/nquads/nquads_test.go @@ -15,8 +15,12 @@ package nquads import ( + "archive/tar" + "compress/gzip" "fmt" "io" + "os" + "path/filepath" "reflect" "strings" "testing" @@ -480,6 +484,72 @@ func TestDecoder(t *testing.T) { } } +func TestRDFWorkingGroupSuit(t *testing.T) { + // These tests erroneously pass because the parser does not + // perform semantic testing on the URI in the IRIRef as required + // by the specification. So, we skip them. + skip := map[string]bool{ + // N-Triples. + "nt-syntax-bad-uri-06.nt": true, + "nt-syntax-bad-uri-07.nt": true, + "nt-syntax-bad-uri-08.nt": true, + "nt-syntax-bad-uri-09.nt": true, + + // N-Quads. + "nq-syntax-bad-uri-01.nq": true, + "nt-syntax-bad-uri-06.nq": true, + "nt-syntax-bad-uri-07.nq": true, + "nt-syntax-bad-uri-08.nq": true, + "nt-syntax-bad-uri-09.nq": true, + } + + for _, file := range []string{ + "ntriple_tests.tar.gz", + "ntriple_tests.tar.gz", + } { + suite, err := os.Open(file) + if err != nil { + t.Fatalf("Failed to open N-Quads test suite in %q: %v", file, err) + } + defer suite.Close() + + r, err := gzip.NewReader(suite) + if err != nil { + t.Fatalf("Failed to uncompress N-Quads test suite in %q: %v", file, err) + } + + tr := tar.NewReader(r) + for { + h, err := tr.Next() + if err != nil { + if err == io.EOF { + break + } + t.Fatalf("Unexpected error while reading suite archive: %v", err) + } + + h.Name = filepath.Base(h.Name) + if (filepath.Ext(h.Name) != ".nt" && filepath.Ext(h.Name) != ".nq") || skip[h.Name] { + continue + } + + isBad := strings.Contains(h.Name, "bad") + + dec := NewDecoder(tr) + for { + _, err := dec.Unmarshal() + if err == io.EOF { + break + } + got := err == nil + if got == isBad { + t.Errorf("Unexpected error return for test suite item %q, got: %v", h.Name, err) + } + } + } + } +} + var escapeSequenceTests = []struct { input string expect string diff --git a/nquads/ntriple_tests.tar.gz b/nquads/ntriple_tests.tar.gz new file mode 100644 index 0000000..5e2ba80 Binary files /dev/null and b/nquads/ntriple_tests.tar.gz differ