MCPcopy Create free account
hub / github.com/RedisGraph/redisgraph-go / TestArray

Function TestArray

client_test.go:155–237  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

153}
154
155func TestArray(t *testing.T) {
156 graph.Flush()
157 graph.Query("MATCH (n) DELETE n")
158
159 q := "CREATE (:person{name:'a',age:32,array:[0,1,2]})"
160 res, err := graph.Query(q)
161 if err != nil {
162 t.Error(err)
163 }
164
165 q = "CREATE (:person{name:'b',age:30,array:[3,4,5]})"
166 res, err = graph.Query(q)
167 if err != nil {
168 t.Error(err)
169 }
170
171 q = "WITH [0,1,2] as x return x"
172 res, err = graph.Query(q)
173 if err != nil {
174 t.Error(err)
175 }
176
177 res.Next()
178 r := res.Record()
179 assert.Equal(t, len(res.results), 1, "expecting 1 result record")
180 assert.Equal(t, []interface{}{0, 1, 2}, r.GetByIndex(0))
181
182 q = "unwind([0,1,2]) as x return x"
183 res, err = graph.Query(q)
184 if err != nil {
185 t.Error(err)
186 }
187 assert.Equal(t, len(res.results), 3, "expecting 3 result record")
188
189 i := 0
190 for res.Next() {
191 r = res.Record()
192 assert.Equal(t, i, r.GetByIndex(0))
193 i++
194 }
195
196 q = "MATCH(n) return collect(n) as x"
197 res, err = graph.Query(q)
198 if err != nil {
199 t.Error(err)
200 }
201
202 a := NodeNew("person", "", nil)
203 b := NodeNew("person", "", nil)
204
205 a.SetProperty("name", "a")
206 a.SetProperty("age", 32)
207 a.SetProperty("array", []interface{}{0, 1, 2})
208
209 b.SetProperty("name", "b")
210 b.SetProperty("age", 30)
211 b.SetProperty("array", []interface{}{3, 4, 5})
212

Callers

nothing calls this directly

Calls 8

NodeNewFunction · 0.85
FlushMethod · 0.80
QueryMethod · 0.80
NextMethod · 0.80
RecordMethod · 0.80
GetByIndexMethod · 0.80
SetPropertyMethod · 0.45
GetPropertyMethod · 0.45

Tested by

no test coverage detected