Skip to content

Commit

Permalink
Merge pull request #162 from kortschak/issue160
Browse files Browse the repository at this point in the history
Issue160
  • Loading branch information
barakmich committed Oct 15, 2014
2 parents cfa2cc6 + d6191ba commit 8437520
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
41 changes: 41 additions & 0 deletions query/gremlin/gremlin_test.go
Expand Up @@ -280,3 +280,44 @@ func TestGremlin(t *testing.T) {
}
}
}

var issue160TestGraph = []quad.Quad{
{"alice", "follows", "bob", ""},
{"bob", "follows", "alice", ""},
{"charlie", "follows", "bob", ""},
{"dani", "follows", "charlie", ""},
{"dani", "follows", "alice", ""},
{"alice", "is", "cool", ""},
{"bob", "is", "not cool", ""},
{"charlie", "is", "cool", ""},
{"danie", "is", "not cool", ""},
}

func TestIssue160(t *testing.T) {
query := `g.V().Tag('query').Out('follows').Out('follows').ForEach(function (item) { if (item.id !== item.query) g.Emit({ id: item.id }); })`
expect := []string{
"****\nid : alice\n",
"****\nid : bob\n",
"****\nid : bob\n",
"=> <nil>\n",
}

ses := makeTestSession(issue160TestGraph)
c := make(chan interface{}, 5)
go ses.ExecInput(query, c, 100)
var got []string
for res := range c {
func() {
defer func() {
if r := recover(); r != nil {
t.Errorf("Unexpected panic: %v", r)
}
}()
got = append(got, ses.ToText(res))
}()
}
sort.Strings(got)
if !reflect.DeepEqual(got, expect) {
t.Errorf("Unexpected result, got: %q expected: %q", got, expect)
}
}
14 changes: 11 additions & 3 deletions query/gremlin/session.go
Expand Up @@ -191,9 +191,17 @@ func (s *Session) ToText(result interface{}) string {
} else {
if data.val.IsObject() {
export, _ := data.val.Export()
mapExport := export.(map[string]string)
for k, v := range mapExport {
out += fmt.Sprintf("%s : %v\n", k, v)
switch export := export.(type) {
case map[string]string:
for k, v := range export {
out += fmt.Sprintf("%s : %s\n", k, v)
}
case map[string]interface{}:
for k, v := range export {
out += fmt.Sprintf("%s : %v\n", k, v)
}
default:
panic(fmt.Sprintf("unexpected type: %T", export))
}
} else {
strVersion, _ := data.val.ToString()
Expand Down

0 comments on commit 8437520

Please sign in to comment.