Move remove() and removeAll() to tests

This is done to keep deadcode quiet.
This commit is contained in:
kortschak 2014-08-22 16:50:39 +09:30
parent cce0f88803
commit ec008b5820
2 changed files with 19 additions and 18 deletions

View file

@ -194,24 +194,6 @@ func load(qw graph.QuadWriter, cfg *config.Config, path, typ string) error {
return decompressAndLoad(qw, cfg, path, typ, db.Load) return decompressAndLoad(qw, cfg, path, typ, db.Load)
} }
func removeAll(qw graph.QuadWriter, cfg *config.Config, path, typ string) error {
return decompressAndLoad(qw, cfg, path, typ, remove)
}
func remove(qw graph.QuadWriter, cfg *config.Config, dec quad.Unmarshaler) error {
for {
t, err := dec.Unmarshal()
if err != nil {
if err == io.EOF {
break
}
return err
}
qw.RemoveQuad(t)
}
return nil
}
func decompressAndLoad(qw graph.QuadWriter, cfg *config.Config, path, typ string, loadFn func(graph.QuadWriter, *config.Config, quad.Unmarshaler) error) error { func decompressAndLoad(qw graph.QuadWriter, cfg *config.Config, path, typ string, loadFn func(graph.QuadWriter, *config.Config, quad.Unmarshaler) error) error {
var r io.Reader var r io.Reader

View file

@ -19,6 +19,7 @@ import (
"compress/bzip2" "compress/bzip2"
"compress/gzip" "compress/gzip"
"fmt" "fmt"
"github.com/google/cayley/quad"
"io" "io"
"reflect" "reflect"
"sort" "sort"
@ -411,6 +412,24 @@ func deletePrepare(t testing.TB) {
}) })
} }
func removeAll(qw graph.QuadWriter, cfg *config.Config, path, typ string) error {
return decompressAndLoad(qw, cfg, path, typ, remove)
}
func remove(qw graph.QuadWriter, cfg *config.Config, dec quad.Unmarshaler) error {
for {
t, err := dec.Unmarshal()
if err != nil {
if err == io.EOF {
break
}
return err
}
qw.RemoveQuad(t)
}
return nil
}
func TestQueries(t *testing.T) { func TestQueries(t *testing.T) {
prepare(t) prepare(t)
checkQueries(t) checkQueries(t)