Debian Codegraph @

tests/testthat/test_Filterable.R

raw
1 context("Filterable")
2
3
4 test_that("is_filter() works", {
5 fil <- function(event) { blubb }
6 expect_true(is_filter(fil))
7 expect_false(is_filter(mean))
8 expect_false(is_filter("blubb"))
9
10 assert_filter(fil)
11 expect_error(
12 assert_filter(mean),
13 regexp = "mean",
14 class = "ObjectIsNoFilterError"
15 )
16 })
17
18
19
20
21 test_that("Filterable: $add_filter(), $remove_filter(), $filters", {
22 app <- Appender$new()
23
24 fil <- function(event) { FALSE }
25
26 expect_error(app$add_filter(mean))
27
28 app$add_filter(fil)
29 expect_identical(app$filters[[1]], fil)
30 expect_false(app$filter())
31
32 app$remove_filter(1)
33 expect_length(app$filters, 0)
34 expect_true(app$filter())
35
36 app$add_filter(fil, "foo")
37 expect_identical(app$filters[[1]], fil)
38 app$remove_filter("foo")
39 expect_length(app$filters, 0)
40
41 fil <- function(event) { NA }
42 app$add_filter(fil, "foo")
43 app$add_filter(fil, "foo")
44 expect_warning(expect_true(app$filter()))
45 })
46
47
48
49
50 test_that("Filterable: $set_filter works with functions", {
51 app <- Appender$new()
52 fil <- function(event) { FALSE }
53 app$set_filters(fil)
54 expect_identical(app$filters[[1]], fil)
55 expect_length(app$filters, 1L)
56
57 app$set_filters(list(fil))
58 expect_identical(app$filters[[1]], fil)
59 expect_length(app$filters, 1L)
60
61 app$set_filters(list(fil, fil))
62 expect_identical(app$filters[[1]], fil)
63 expect_identical(app$filters[[2]], fil)
64 expect_length(app$filters, 2L)
65 })