Add RDF test suite testing and fix grammar errors

This commit is contained in:
kortschak 2014-07-26 11:58:56 +09:30
parent 9ff97602f0
commit 5953a8dfa0
4 changed files with 74 additions and 5 deletions

BIN
nquads/nquad_tests.tar.gz Normal file

Binary file not shown.

View file

@ -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 ;
}%%

View file

@ -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

BIN
nquads/ntriple_tests.tar.gz Normal file

Binary file not shown.