-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lost tests for json structure somehow, recreated most here #2
- Loading branch information
Jeremy
committed
Aug 26, 2016
1 parent
141cf9d
commit f5575c2
Showing
1 changed file
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
context("json_structure") | ||
|
||
test_that("simple string works", { | ||
|
||
expect_identical( | ||
'"a"' %>% json_structure, | ||
tbl_json( | ||
data_frame( | ||
document.id = 1L, | ||
parent.id = NA_character_, | ||
level = 1L, | ||
index = 1L, | ||
child.id = "1", | ||
key = NA_character_, | ||
type = "string" %>% factor(levels = allowed_json_types), | ||
length = 1L | ||
), | ||
list("a") | ||
) | ||
) | ||
|
||
}) | ||
|
||
test_that("simple object works", { | ||
|
||
expect_identical( | ||
'{"key": "value"}' %>% json_structure, | ||
tbl_json( | ||
data_frame( | ||
document.id = c(1L, 1L), | ||
parent.id = c(NA_character_, "1"), | ||
level = c(1L, 2L), | ||
index = c(1L, 1L), | ||
child.id = c("1", "1.1"), | ||
key = c(NA_character_, "key"), | ||
type = c("object", "string") %>% factor(levels = allowed_json_types), | ||
length = c(1L, 1L) | ||
), | ||
list(list("key" = "value"), "value") | ||
) | ||
) | ||
|
||
}) | ||
|
||
test_that("simple array works", { | ||
|
||
expect_identical( | ||
'[1, 2]' %>% json_structure, | ||
tbl_json( | ||
data_frame( | ||
document.id = c(1L, 1L, 1L), | ||
parent.id = c(NA_character_, "1", "1"), | ||
level = c(1L, 2L, 2L), | ||
index = c(1L, 1L, 2L), | ||
child.id = c("1", "1.1", "1.2"), | ||
key = rep(NA_character_, 3), | ||
type = c("array", "number", "number") %>% factor(levels = allowed_json_types), | ||
length = c(2L, 1L, 1L) | ||
), | ||
list(list(1L, 2L), 1L, 2L) | ||
) | ||
) | ||
|
||
}) | ||
|
||
test_that("nested object works", { | ||
|
||
expect_identical( | ||
'{"k1": {"k2": "value"}}' %>% json_structure, | ||
tbl_json( | ||
data_frame( | ||
document.id = c(1L, 1L, 1L), | ||
parent.id = c(NA_character_, "1", "1.1"), | ||
level = c(1L, 2L, 3L), | ||
index = c(1L, 1L, 1L), | ||
child.id = c("1", "1.1", "1.1.1"), | ||
key = c(NA_character_, "k1", "k2"), | ||
type = c("object", "object", "string") %>% factor(levels = allowed_json_types), | ||
length = c(1L, 1L, 1L) | ||
), | ||
list(list("k1" = list("k2" = "value")), | ||
list("k2" = "value"), | ||
"value") | ||
) | ||
) | ||
|
||
}) | ||
|
||
test_that("works with empty values appropriately", { | ||
|
||
expect_identical( | ||
'null' %>% json_structure, | ||
tbl_json( | ||
data_frame( | ||
document.id = 1L, | ||
parent.id = NA_character_, | ||
level = 1L, | ||
index = 1L, | ||
child.id = "1", | ||
key = NA_character_, | ||
type = "null" %>% factor(levels = allowed_json_types), | ||
length = 0L | ||
), | ||
list(NULL) | ||
) | ||
) | ||
|
||
}) |