Remove goconvey dependency

This commit is contained in:
kortschak 2014-07-03 20:25:59 +09:30
parent 03fb6e367a
commit 859164d714

View file

@ -17,8 +17,6 @@ package sexp
import ( import (
"testing" "testing"
. "github.com/smartystreets/goconvey/convey"
"github.com/google/cayley/graph" "github.com/google/cayley/graph"
"github.com/google/cayley/graph/memstore" "github.com/google/cayley/graph/memstore"
) )
@ -26,41 +24,55 @@ import (
func TestBadParse(t *testing.T) { func TestBadParse(t *testing.T) {
str := ParseString("()") str := ParseString("()")
if str != "" { if str != "" {
t.Errorf("It parsed! Got \"%s\"", str) t.Errorf("Unexpected parse result, got:%q", str)
} }
} }
func TestParseSexpWithMemstore(t *testing.T) { var testQueries = []struct {
Convey("With a Memstore", t, func() { message string
ts := memstore.NewTripleStore() add *graph.Triple
query string
typ string
expect string
}{
{
message: "get a single triple linkage",
add: &graph.Triple{"i", "can", "win", ""},
query: "($a (:can \"win\"))",
typ: "and",
expect: "i",
},
{
message: "get a single triple linkage",
add: &graph.Triple{"i", "can", "win", ""},
query: "(\"i\" (:can $a))",
typ: "and",
expect: "i",
},
}
Convey("It should parse an empty query", func() { func TestMemstoreBackedSexp(t *testing.T) {
it := BuildIteratorTreeForQuery(ts, "()") ts := memstore.NewTripleStore()
So(it.Type(), ShouldEqual, "null") it := BuildIteratorTreeForQuery(ts, "()")
}) if it.Type() != "null" {
t.Errorf(`Incorrect type for empty query, got:%q expect: "null"`, it.Type())
Convey("It should get a single triple linkage", func() { }
ts.AddTriple(&graph.Triple{"i", "can", "win", ""}) for _, test := range testQueries {
query := "($a (:can \"win\"))" if test.add != nil {
So(len(query), ShouldEqual, 17) ts.AddTriple(test.add)
it := BuildIteratorTreeForQuery(ts, query) }
So(it.Type(), ShouldEqual, "and") it := BuildIteratorTreeForQuery(ts, test.query)
out, ok := it.Next() if it.Type() != test.typ {
So(ok, ShouldBeTrue) t.Errorf("Incorrect type for %s, got:%q expect %q", test.message, it.Type(), test.expect)
So(out, ShouldEqual, ts.ValueOf("i")) }
}) got, ok := it.Next()
if !ok {
Convey("It can get an internal linkage", func() { t.Errorf("Failed to %s", test.message)
ts.AddTriple(&graph.Triple{"i", "can", "win", ""}) }
query := "(\"i\" (:can $a))" if expect := ts.ValueOf(test.expect); got != expect {
it := BuildIteratorTreeForQuery(ts, query) t.Errorf("Incorrect result for %s, got:%v expect %v", test.message, got, expect)
So(it.Type(), ShouldEqual, "and") }
out, ok := it.Next() }
So(ok, ShouldBeTrue)
So(out, ShouldEqual, ts.ValueOf("i"))
})
})
} }
func TestTreeConstraintParse(t *testing.T) { func TestTreeConstraintParse(t *testing.T) {
@ -72,7 +84,7 @@ func TestTreeConstraintParse(t *testing.T) {
"($a (:is :good))))" "($a (:is :good))))"
it := BuildIteratorTreeForQuery(ts, query) it := BuildIteratorTreeForQuery(ts, query)
if it.Type() != "and" { if it.Type() != "and" {
t.Error("Odd iterator tree. Got: %s", it.DebugString(0)) t.Error("Odd iterator tree, got: %s", it.DebugString(0))
} }
out, ok := it.Next() out, ok := it.Next()
if !ok { if !ok {
@ -105,12 +117,18 @@ func TestTreeConstraintTagParse(t *testing.T) {
func TestMultipleConstraintParse(t *testing.T) { func TestMultipleConstraintParse(t *testing.T) {
ts := memstore.NewTripleStore() ts := memstore.NewTripleStore()
ts.AddTriple(&graph.Triple{"i", "like", "food", ""}) for _, tv := range []*graph.Triple{
ts.AddTriple(&graph.Triple{"i", "like", "beer", ""}) {"i", "like", "food", ""},
ts.AddTriple(&graph.Triple{"you", "like", "beer", ""}) {"i", "like", "beer", ""},
query := "($a \n" + {"you", "like", "beer", ""},
"(:like :beer)\n" + } {
"(:like \"food\"))" ts.AddTriple(tv)
}
query := `(
$a
(:like :beer)
(:like "food")
)`
it := BuildIteratorTreeForQuery(ts, query) it := BuildIteratorTreeForQuery(ts, query)
if it.Type() != "and" { if it.Type() != "and" {
t.Error("Odd iterator tree. Got: %s", it.DebugString(0)) t.Error("Odd iterator tree. Got: %s", it.DebugString(0))