File: test-zzz-options.R

package info (click to toggle)
r-cran-tibble 3.0.6%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,492 kB
  • sloc: ansic: 315; sh: 10; makefile: 5
file content (101 lines) | stat: -rw-r--r-- 2,466 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
scoped_lifecycle_silence()

test_that("tibble option takes preference", {
  withr::with_options(
    list(
      tibble.width = 10,
      dplyr.width = 20
    ),
    expect_equal(tibble_opt("width"), 10)
  )
})

test_that("dplyr option is used for compatibility", {
  withr::with_options(
    list(
      tibble.width = NULL,
      dplyr.width = 20
    ),
    expect_equal(tibble_opt("width"), 20)
  )
})

test_that("fallback to default option", {
  withr::with_options(
    list(
      tibble.width = NULL,
      dplyr.width = NULL
    ),
    expect_equal(tibble_opt("width"), op.tibble[["tibble.width"]])
  )
})

test_that("tibble_width returns user-input width,
          then tibble.width option, then width option", {
  test_width <- 42

  expect_equal(tibble_width(test_width), test_width)
  withr::with_options(
    list(tibble.width = test_width),
    expect_equal(tibble_width(NULL), test_width)
  )
  withr::with_options(
    list(width = test_width),
    expect_equal(tibble_width(NULL), test_width)
  )
})

test_that("tibble_width prefers tibble.width / dplyr.width over width", {
  withr::with_options(
    list(tibble.width = 10, width = 20),
    expect_equal(tibble_width(NULL), 10)
  )

  withr::with_options(
    list(dplyr.width = 10, width = 20),
    expect_equal(tibble_width(NULL), 10)
  )
})

test_that("tibble_glimpse_width returns user-input width,
          then tibble.width option, then width option", {
  test_width <- 42

  expect_equal(tibble_glimpse_width(test_width), test_width)
  withr::with_options(
    list(tibble.width = test_width),
    expect_equal(tibble_glimpse_width(NULL), test_width)
  )
  withr::with_options(
    list(width = test_width),
    expect_equal(tibble_glimpse_width(NULL), test_width)
  )
})

test_that("tibble_glimpse_width prefers tibble.width / dplyr.width over width", {
  withr::with_options(
    list(tibble.width = 10, width = 20),
    expect_equal(tibble_glimpse_width(NULL), 10)
  )

  withr::with_options(
    list(dplyr.width = 10, width = 20),
    expect_equal(tibble_glimpse_width(NULL), 10)
  )
})

test_that("tibble_glimpse_width ignores Inf tibble.width", {
  withr::with_options(
    list(tibble.width = Inf, width = 20),
    expect_equal(tibble_glimpse_width(NULL), 20)
  )
})

test_that("print.tbl ignores max.print option", {
  iris2 <- as_tibble(iris)
  expect_output(
    withr::with_options(list(max.print = 3), print(iris2)),
    capture_output(print(iris2)),
    fixed = TRUE
  )
})