File: test_remove.R

package info (click to toggle)
r-cran-fail 1.3-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 188 kB
  • sloc: sh: 9; makefile: 5
file content (42 lines) | stat: -rw-r--r-- 1,134 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
context("remove and clear")

test_that("remove", {
  path = tempfile()
  f = fail(path)

  f$put(a = 1, b = 2)
  expect_equal(f$remove("b"), setNames(TRUE, "b"))
  expect_equal(f$ls(), "a")
  f$put(b = 2)
  expect_equal(f$ls(), letters[1:2])
  expect_equal(f$remove(letters[1:2]), setNames(c(TRUE, TRUE), letters[1:2]))
  f$put(a = 1, b = 2)

  # invalid keys and empty sets
  expect_warning(f$remove("c"), "Files not removed")
  expect_error(f$remove())
  expect_equal(f$remove(character(0L)), setNames(logical(0), character(0)))

  # cache
  expect_equal(f$get("a", use.cache=TRUE), 1)
  expect_equal(f$cached(), "a")
  expect_equal(f$remove("a"), setNames(TRUE, "a"))
  expect_equal(f$cached(), character(0L))
  f$put(a = 1)
  f$get("a", use.cache=TRUE)
  f$get("b", use.cache=TRUE)
  expect_equal(f$cached(), letters[1:2])
  f$remove(letters[1:2])
  expect_equal(f$cached(), character(0L))
})

test_that("clear", {
  path = tempfile()
  f = fail(path)
  f$put(a = 1, b = 2)
  f$get("a", use.cache=TRUE)
  f$get("b", use.cache=TRUE)
  expect_equal(f$cached(), letters[1:2])
  f$clear()
  expect_equal(f$cached(), character(0L))
})