File: test-format.R

package info (click to toggle)
r-cran-blob 1.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 180 kB
  • sloc: sh: 13; makefile: 2
file content (64 lines) | stat: -rw-r--r-- 999 bytes parent folder | download | duplicates (2)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
context("format")

expect_format_equal <- function(formatted, result) {
  expect_equal(
    paste(formatted, collapse = "\n"),
    paste(result, collapse = "\n")
  )
}

test_that("unequal sizes", {
  skip_on_cran()

  x <- blob(raw(2 ** 2), raw(2 ** 11), raw(2 ** 20))

  expect_format_equal(
    format(x),
    c(
      "blob[4 B]",
      "blob[2.05 kB]",
      "blob[1.05 MB]"
    )
  )

  expect_format_equal(
    format(x, trim = FALSE),
    c(
      "blob[    4 B]",
      "blob[2.05 kB]",
      "blob[1.05 MB]"
    )
  )
})

test_that("similar sizes", {
  skip_on_cran()

  x <- blob(raw(2 ** 10), raw(2 ** 11), raw(2 ** 12))

  expect_format_equal(
    format(x),
    c(
      "blob[1.02 kB]",
      "blob[2.05 kB]",
      "blob[4.10 kB]"
    )
  )
})

test_that("empty", {
  x <- blob()

  expect_format_equal(
    format(x),
    character()
  )
})

test_that("output", {
  skip_on_cran()

  x <- blob(raw(2 ** 2), raw(2 ** 11), raw(2 ** 20))

  expect_known_output(print(x), "blob.txt")
})