| 72 | } |
| 73 | |
| 74 | func TestLoadIteratorTo(t *testing.T) { |
| 75 | sch := schema.NewConfig() |
| 76 | for i, c := range testFillValueCases { |
| 77 | t.Run(c.name, func(t *testing.T) { |
| 78 | qs := memstore.New(c.quads...) |
| 79 | rt := reflect.TypeOf(c.expect) |
| 80 | var out reflect.Value |
| 81 | if rt.Kind() == reflect.Ptr { |
| 82 | out = reflect.New(rt.Elem()) |
| 83 | } else { |
| 84 | out = reflect.New(rt) |
| 85 | } |
| 86 | var it graph.Iterator |
| 87 | if c.from != nil { |
| 88 | fixed := iterator.NewFixed() |
| 89 | for _, id := range c.from { |
| 90 | fixed.Add(qs.ValueOf(id)) |
| 91 | } |
| 92 | it = fixed |
| 93 | } |
| 94 | depth := c.depth |
| 95 | if depth == 0 { |
| 96 | depth = -1 |
| 97 | } |
| 98 | if err := sch.LoadIteratorToDepth(nil, qs, out, depth, it); err != nil { |
| 99 | t.Errorf("case %d failed: %v", i+1, err) |
| 100 | return |
| 101 | } |
| 102 | var got interface{} |
| 103 | if rt.Kind() == reflect.Ptr { |
| 104 | got = out.Interface() |
| 105 | } else { |
| 106 | got = out.Elem().Interface() |
| 107 | } |
| 108 | if s, ok := got.(interface { |
| 109 | Sort() |
| 110 | }); ok { |
| 111 | s.Sort() |
| 112 | } |
| 113 | if s, ok := c.expect.(interface { |
| 114 | Sort() |
| 115 | }); ok { |
| 116 | s.Sort() |
| 117 | } |
| 118 | if !reflect.DeepEqual(got, c.expect) { |
| 119 | t.Errorf("case %d failed: objects are different\n%#v\n%#v", |
| 120 | i+1, got, c.expect, |
| 121 | ) |
| 122 | } |
| 123 | }) |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | var testFillValueCases = []struct { |
| 128 | name string |