| 1 |
test_that("renderPrint and renderText behavior is correct", { |
| 2 |
expect_equal(isolate(renderPrint({ "foo" })()), |
| 3 |
'[1] "foo"') |
| 4 |
expect_equal(isolate(renderPrint({ invisible("foo") })()), |
| 5 |
'') |
| 6 |
expect_equal(isolate(renderPrint({ print("foo"); "bar"})()), |
| 7 |
'[1] "foo"\n[1] "bar"') |
| 8 |
expect_equal(isolate(renderPrint({ NULL })()), |
| 9 |
'NULL') |
| 10 |
expect_equal(isolate(renderPrint({ invisible() })()), |
| 11 |
'') |
| 12 |
expect_equal(isolate(renderPrint({ 1:5 })()), |
| 13 |
'[1] 1 2 3 4 5') |
| 14 |
|
| 15 |
expect_equal(isolate(renderText({ "foo" })()), |
| 16 |
'foo') |
| 17 |
expect_equal(isolate(renderText({ invisible("foo") })()), |
| 18 |
'foo') |
| 19 |
expect_equal(isolate(renderText({ c("hello", "world") })()), |
| 20 |
'hello world') |
| 21 |
|
| 22 |
expect_equal(isolate(renderText({ c("hello", "world") }, sep=", ")()), |
| 23 |
'hello, world') |
| 24 |
# Really just measuring the behavior of `cat` when it receives a vector of |
| 25 |
# separators, but probably worth covering. |
| 26 |
expect_equal(isolate(renderText({ c("hello", "there", "world", "repeats") }, |
| 27 |
sep=c(" ", ", "))()), |
| 28 |
'hello there, world repeats') |
| 29 |
|
| 30 |
# Capture the print output so it's not shown on console during test, and |
| 31 |
# also check that it is correct |
| 32 |
print_out <- utils::capture.output(ret <- isolate(renderText({ print("foo"); "bar"})())) |
| 33 |
expect_equal(ret, 'bar') |
| 34 |
expect_equal(print_out, '[1] "foo"') |
| 35 |
expect_equal(isolate(renderText({ NULL })()), |
| 36 |
'') |
| 37 |
expect_equal(isolate(renderText({ invisible() })()), |
| 38 |
'') |
| 39 |
expect_equal(isolate(renderText({ 1:5 })()), |
| 40 |
'1 2 3 4 5') |
| 41 |
}) |
| 42 |
|
| 43 |
test_that("reactive functions save visibility state", { |
| 44 |
# Call each function twice - should be no change in state with second call |
| 45 |
|
| 46 |
# invisible NULL |
| 47 |
f <- reactive({ invisible() }) |
| 48 |
expect_identical(withVisible(isolate(f())), list(value=NULL, visible=FALSE)) |
| 49 |
expect_identical(withVisible(isolate(f())), list(value=NULL, visible=FALSE)) |
| 50 |
|
| 51 |
# visible NULL |
| 52 |
f <- reactive({ NULL }) |
| 53 |
expect_identical(withVisible(isolate(f())), list(value=NULL, visible=TRUE)) |
| 54 |
expect_identical(withVisible(isolate(f())), list(value=NULL, visible=TRUE)) |
| 55 |
|
| 56 |
# invisible non-NULL value |
| 57 |
f <- reactive({ invisible(10)}) |
| 58 |
expect_identical(withVisible(isolate(f())), list(value=10, visible=FALSE)) |
| 59 |
expect_identical(withVisible(isolate(f())), list(value=10, visible=FALSE)) |
| 60 |
|
| 61 |
# visible non-NULL value |
| 62 |
f <- reactive({ 10 }) |
| 63 |
expect_identical(withVisible(isolate(f())), list(value=10, visible=TRUE)) |
| 64 |
expect_identical(withVisible(isolate(f())), list(value=10, visible=TRUE)) |
| 65 |
}) |