Debian Codegraph @

tests/testthat/test-modules.R

raw
1 test_that("Namespace qualifying", {
2 expect_equal(NS(NULL, "one"), "one")
3 expect_equal(NS(NULL)("one"), "one")
4
5 expect_equal(NS("one", NULL), "one")
6 expect_equal(NS("one")(NULL), "one")
7
8 expect_equal(NS("one", "two"), "one-two")
9 expect_equal(NS("one")("two"), "one-two")
10
11 expect_equal(NS(c("one", "two"))(NULL), "one-two")
12 expect_equal(NS(c("one", "two"), NULL), "one-two")
13
14 expect_equal(NS(NULL)(c("one", "two")), c("one", "two"))
15 expect_equal(NS(NULL, c("one", "two")), c("one", "two"))
16
17 expect_equal(NS("one", c("two", "three")), c("one-two", "one-three"))
18 expect_equal(NS("one")(c("two", "three")), c("one-two", "one-three"))
19
20 expect_equal(NS(c("one", "two"), "three"), "one-two-three")
21 expect_equal(NS(c("one", "two"))("three"), "one-two-three")
22
23 expect_equal(NS(c("one", "two"), c("three", "four")), c("one-two-three", "one-two-four"))
24 expect_equal(NS(c("one", "two"))(c("three", "four")), c("one-two-three", "one-two-four"))
25
26 expect_equal(NS(c("one", "two"))("three four"), "one-two-three four")
27 expect_equal(NS(c("one", "two"))("three-four"), "one-two-three-four")
28 })
29
30 test_that("reactiveValues with namespace", {
31 values <- ReactiveValues$new()
32
33 rv <- .createReactiveValues(values)
34 rv$foo <- 10
35 rv$baz <- 11
36 expect_equal(isolate(values$get("foo")), 10)
37 expect_equal(isolate(values$get("baz")), 11)
38
39 rv1 <- .createReactiveValues(values, ns = NS("bar"))
40 rv1$baz <- 20
41 expect_equal(isolate(rv1$baz), 20)
42 expect_equal(isolate(rv[["bar-baz"]]), 20)
43
44 rv2 <- .createReactiveValues(values, ns = NS(c("bar", "qux")))
45 rv2$quux <- 30
46 expect_equal(isolate(rv2$quux), 30)
47 expect_equal(isolate(rv1[["qux-quux"]]), 30)
48 expect_equal(isolate(rv[["bar-qux-quux"]]), 30)
49
50 # Namespaced reactive values objects only get their own names,
51 # minus the namespace prefix, when names() is called.
52 # Unnamespaced (root) reactive values objects get all names.
53 expect_setequal(isolate(names(rv)), c("bar-baz", "bar-qux-quux", "baz", "foo"))
54 expect_setequal(isolate(names(rv1)), c("baz", "qux-quux"))
55 expect_setequal(isolate(names(rv2)), c("quux"))
56 })
57
58 test_that("implicit output respects module namespace", {
59 output <- new.env(parent = emptyenv())
60 ns <- NS("test")
61 result <- withReactiveDomain(list(output = output, ns = ns),
62 as.tags(renderText("hi"))
63 )
64 # Does the automatically-generated output id include the correct namespace qualifier?
65 # (See issue #2000)
66 expect_equal(result$attribs$id, ns(ls(output)))
67 })