Skip to content
This repository has been archived by the owner on May 23, 2019. It is now read-only.

Commit

Permalink
Properly handle empty collections in cypherToList
Browse files Browse the repository at this point in the history
Fixes #40.
  • Loading branch information
nicolewhite committed Oct 5, 2015
1 parent 418708f commit 8760a34
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/cypherToList.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ cypherToList.graph = function(graph, query, ...) {
for(j in 1:length(result$columns)) {
name = result$columns[[j]]
record = data[[i]][[j]]
if(!is.null(names(record)) || !is.list(record)) {
if(!is.null(names(record)) || !is.list(record) || length(record) == 0) {
datum[[name]] = configure_result(record)
} else {
depth = length(record)
Expand Down
29 changes: 29 additions & 0 deletions tests/testthat/test-cypherToList.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,33 @@ test_that("it can return nodes with empty collections as properties", {
n = n[[1]]$n

expect_equal(length(n$a), 0)
})

test_that("it can return empty collections", {
clear(neo4j, input=F)

query = "RETURN [] AS col"
response = cypherToList(neo4j, query)[[1]]

expect_equal(response$col, list())
})

test_that("it can return empty collections along with a value", {
clear(neo4j, input=F)

query = "RETURN [] AS col, 5 AS five"
response = cypherToList(neo4j, query)[[1]]

expect_equal(response$col, list())
expect_equal(response$five, 5)
})

test_that("it can return empty collections and non-empty collections", {
clear(neo4j, input=F)

query = "RETURN [] AS col1, [5,6] AS col2"
response = cypherToList(neo4j, query)[[1]]

expect_equal(response$col1, list())
expect_equal(response$col2, list(5,6))
})

0 comments on commit 8760a34

Please sign in to comment.