Files
shiny/inst/tests/test-input-handler.R
Winston Chang 040ae293fb Revert switch to jsonlite
This reverts commits deffc90, ab4dc64, and 0755579, returning to RJSONIO.
The purpose of this is to prepare for a maintenance release for 0.11
without the switch to jsonlite, to reduce the risk of new bugs.
2015-02-06 10:53:54 -06:00

47 lines
1.2 KiB
R

context("Parse Shiny Input")
test_that("A new type can be registered successfully", {
registerInputHandler("shiny.someType", function(){})
})
test_that("A duplicated type throws", {
expect_error({
registerInputHandler("shiny.dupType", function(){})
registerInputHandler("shiny.dupType", function(){})
})
})
test_that("Date converts to date", {
x <- "2013/01/01"
class(x) <- "shiny.date"
handler <- inputHandlers$get('shiny.date')
expect_identical(
handler(x), as.Date(unclass(x))
)
})
test_that("List of dates converts to vector", {
x <- list("2013/01/01", "2014/01/01")
class(x) <- "shiny.date"
handler <- inputHandlers$get('shiny.date')
expect_identical(
handler(x), as.Date(unlist(x))
)
})
test_that("Matrix converts list of lists to matrix", {
x <- list(a=1:3,b=4:6)
class(x) <- "shiny.matrix"
handler <- inputHandlers$get('shiny.matrix')
expect_identical(
handler(x), matrix(c(1:3,4:6), byrow=FALSE, ncol=2)
)
})
test_that("Nulls are not converted to NAs in parsing", {
msg <- charToRaw("{\"method\":\"init\",\"data\":{\"obs\":500,\"nullObs\":null}}")
expect_identical(
decodeMessage(msg),
list(method="init", data=list(obs=500, nullObs=NULL))
)
})