Debian Codegraph @

tests/testthat/test-input-handler.R

raw
1 test_that("A new type can be registered successfully", {
2 expect_error(
3 registerInputHandler("shiny.someType", function(){}),
4 NA
5 )
6 })
7
8 test_that("A duplicated type throws", {
9 expect_error({
10 registerInputHandler("shiny.dupType", function(){})
11 registerInputHandler("shiny.dupType", function(){})
12 })
13 })
14
15 test_that("Date converts to date", {
16 x <- "2013/01/01"
17 class(x) <- "shiny.date"
18 handler <- inputHandlers$get('shiny.date')
19 expect_identical(
20 handler(x), as.Date(unclass(x))
21 )
22 })
23
24 test_that("List of dates converts to vector", {
25 x <- list("2013/01/01", "2014/01/01")
26 class(x) <- "shiny.date"
27 handler <- inputHandlers$get('shiny.date')
28 expect_identical(
29 handler(x), as.Date(unlist(x))
30 )
31 })
32
33 test_that("Matrix converts list of lists to matrix", {
34 x <- list(a=1:3,b=4:6)
35 class(x) <- "shiny.matrix"
36 handler <- inputHandlers$get('shiny.matrix')
37 expect_identical(
38 handler(x), matrix(c(1:3,4:6), byrow=FALSE, ncol=2)
39 )
40 })
41
42 test_that("Nulls are not converted to NAs in parsing", {
43 msg <- charToRaw("{\"method\":\"init\",\"data\":{\"obs\":500,\"nullObs\":null}}")
44 expect_identical(
45 decodeMessage(msg),
46 list(method="init", data=list(obs=500L, nullObs=NULL))
47 )
48 })
49
50
51 test_that("characters turn into symbols", {
52 handler <- inputHandlers$get("shiny.symbol")
53 x <- "mpg"
54 expect_identical(
55 handler(x),
56 as.symbol(x)
57 )
58 expect_identical(
59 handler(NULL),
60 NULL
61 )
62 })
63 test_that("character vectors turn into symbol lists", {
64 handler <- inputHandlers$get("shiny.symbolList")
65 x <- list("mpg")
66 expect_identical(
67 handler(x),
68 list(as.symbol(x[[1]]))
69 )
70 x <- list("mpg", "cyl", "disp")
71 expect_identical(
72 handler(x),
73 list(as.symbol(x[[1]]), as.symbol(x[[2]]), as.symbol(x[[3]]))
74 )
75 expect_identical(
76 handler(NULL),
77 list()
78 )
79 })