github.com/cayleygraph/cayley@v0.7.7/graph/iterator/linksto_test.go (about) 1 // Copyright 2014 The Cayley Authors. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package iterator_test 16 17 import ( 18 "context" 19 "testing" 20 21 "github.com/cayleygraph/cayley/graph/graphmock" 22 . "github.com/cayleygraph/cayley/graph/iterator" 23 "github.com/cayleygraph/quad" 24 ) 25 26 func TestLinksTo(t *testing.T) { 27 ctx := context.TODO() 28 qs := &graphmock.Oldstore{ 29 Data: []string{1: "cool"}, 30 Iter: NewFixed(), 31 } 32 qs.Iter.(*Fixed).Add(Int64Quad(2)) 33 fixed := NewFixed() 34 val := qs.ValueOf(quad.Raw("cool")) 35 if val.(Int64Node) != 1 { 36 t.Fatalf("Failed to return correct value, got:%v expect:1", val) 37 } 38 fixed.Add(val) 39 lto := NewLinksTo(qs, fixed, quad.Object) 40 if !lto.Next(ctx) { 41 t.Error("At least one quad matches the fixed object") 42 } 43 val = lto.Result() 44 if val.(Int64Quad) != 2 { 45 t.Errorf("Quad index 2, such as %s, should match %s", qs.Quad(Int64Quad(2)), qs.Quad(val)) 46 } 47 }