Add RDF test suite testing and fix grammar errors
This commit is contained in:
parent
9ff97602f0
commit
5953a8dfa0
4 changed files with 74 additions and 5 deletions
BIN
nquads/nquad_tests.tar.gz
Normal file
BIN
nquads/nquad_tests.tar.gz
Normal file
Binary file not shown.
|
|
@ -57,8 +57,7 @@
|
||||||
| 0x0b .. 0x0c
|
| 0x0b .. 0x0c
|
||||||
| 0x0e .. '!'
|
| 0x0e .. '!'
|
||||||
| '#' .. '['
|
| '#' .. '['
|
||||||
| ']' .. '~'
|
| ']' .. 0x10ffff
|
||||||
| 0x80 .. 0x10ffff
|
|
||||||
| ECHAR
|
| ECHAR
|
||||||
| UCHAR)*
|
| UCHAR)*
|
||||||
'"'
|
'"'
|
||||||
|
|
@ -90,9 +89,9 @@
|
||||||
|
|
||||||
statement := (
|
statement := (
|
||||||
whitespace* subject >StartSubject %SetSubject
|
whitespace* subject >StartSubject %SetSubject
|
||||||
whitespace+ predicate >StartPredicate %SetPredicate
|
whitespace* predicate >StartPredicate %SetPredicate
|
||||||
whitespace+ object >StartObject %SetObject
|
whitespace* object >StartObject %SetObject
|
||||||
(whitespace+ graphLabel >StartLabel %SetLabel)?
|
(whitespace* graphLabel >StartLabel %SetLabel)?
|
||||||
whitespace* '.' whitespace* ('#' any*)? >Comment
|
whitespace* '.' whitespace* ('#' any*)? >Comment
|
||||||
) %Return @!Error ;
|
) %Return @!Error ;
|
||||||
}%%
|
}%%
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,12 @@
|
||||||
package nquads
|
package nquads
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"archive/tar"
|
||||||
|
"compress/gzip"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"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 {
|
var escapeSequenceTests = []struct {
|
||||||
input string
|
input string
|
||||||
expect string
|
expect string
|
||||||
|
|
|
||||||
BIN
nquads/ntriple_tests.tar.gz
Normal file
BIN
nquads/ntriple_tests.tar.gz
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue