Debian Codegraph @

tests/testthat/test-options.R

raw
1 test_that("print_max", {
2 value <- 15L
3
4 orig <- get_pillar_option_print_max()
5 expect_identical(orig, pillar_options$print_max())
6
7 old <- set_pillar_option_print_max(value)
8 expect_equal(get_pillar_option_print_max(), value)
9 expect_equal(expect_invisible(set_pillar_option_print_max(old)), value)
10
11 old <- pillar_options$print_max(value)
12 expect_equal(pillar_options$print_max(), value)
13 expect_equal(expect_invisible(pillar_options$print_max(old)), value)
14
15 local({
16 expect_equal(expect_invisible(local_pillar_option_print_max(value)), old)
17 expect_equal(get_pillar_option_print_max(), value)
18 })
19 expect_equal(get_pillar_option_print_max(), orig)
20 })
21
22 test_that("print_min", {
23 value <- 5L
24
25 orig <- get_pillar_option_print_min()
26 expect_identical(orig, pillar_options$print_min())
27
28 old <- set_pillar_option_print_min(value)
29 expect_equal(get_pillar_option_print_min(), value)
30 expect_equal(expect_invisible(set_pillar_option_print_min(old)), value)
31
32 old <- pillar_options$print_min(value)
33 expect_equal(pillar_options$print_min(), value)
34 expect_equal(expect_invisible(pillar_options$print_min(old)), value)
35
36 local({
37 expect_equal(expect_invisible(local_pillar_option_print_min(value)), old)
38 expect_equal(get_pillar_option_print_min(), value)
39 })
40 expect_equal(get_pillar_option_print_min(), orig)
41 })
42
43 test_that("width", {
44 value <- 160L
45
46 orig <- get_pillar_option_width()
47 expect_identical(orig, pillar_options$width())
48
49 old <- set_pillar_option_width(value)
50 expect_equal(get_pillar_option_width(), value)
51 expect_equal(expect_invisible(set_pillar_option_width(old)), value)
52
53 old <- pillar_options$width(value)
54 expect_equal(pillar_options$width(), value)
55 expect_equal(expect_invisible(pillar_options$width(old)), value)
56
57 local({
58 expect_equal(expect_invisible(local_pillar_option_width(value)), old)
59 expect_equal(get_pillar_option_width(), value)
60 })
61 expect_equal(get_pillar_option_width(), orig)
62 })
63
64 test_that("max_footer_lines", {
65 value <- 15L
66
67 orig <- get_pillar_option_max_footer_lines()
68 expect_identical(orig, pillar_options$max_footer_lines())
69
70 old <- set_pillar_option_max_footer_lines(value)
71 expect_equal(get_pillar_option_max_footer_lines(), value)
72 expect_equal(expect_invisible(set_pillar_option_max_footer_lines(old)), value)
73
74 old <- pillar_options$max_footer_lines(value)
75 expect_equal(pillar_options$max_footer_lines(), value)
76 expect_equal(expect_invisible(pillar_options$max_footer_lines(old)), value)
77
78 local({
79 expect_equal(expect_invisible(local_pillar_option_max_footer_lines(value)), old)
80 expect_equal(get_pillar_option_max_footer_lines(), value)
81 })
82 expect_equal(get_pillar_option_max_footer_lines(), orig)
83 })
84
85 test_that("max_extra_cols", {
86 value <- 30L
87
88 orig <- get_pillar_option_max_extra_cols()
89 expect_identical(orig, pillar_options$max_extra_cols())
90
91 old <- set_pillar_option_max_extra_cols(value)
92 expect_equal(get_pillar_option_max_extra_cols(), value)
93 expect_equal(expect_invisible(set_pillar_option_max_extra_cols(old)), value)
94
95 old <- pillar_options$max_extra_cols(value)
96 expect_equal(pillar_options$max_extra_cols(), value)
97 expect_equal(expect_invisible(pillar_options$max_extra_cols(old)), value)
98
99 local({
100 expect_equal(expect_invisible(local_pillar_option_max_extra_cols(value)), old)
101 expect_equal(get_pillar_option_max_extra_cols(), value)
102 })
103 expect_equal(get_pillar_option_max_extra_cols(), orig)
104 })
105
106 test_that("bold", {
107 value <- 0L
108
109 orig <- get_pillar_option_bold()
110 expect_identical(orig, pillar_options$bold())
111
112 old <- set_pillar_option_bold(value)
113 expect_equal(get_pillar_option_bold(), value)
114 expect_equal(expect_invisible(set_pillar_option_bold(old)), value)
115
116 old <- pillar_options$bold(value)
117 expect_equal(pillar_options$bold(), value)
118 expect_equal(expect_invisible(pillar_options$bold(old)), value)
119
120 local({
121 expect_equal(expect_invisible(local_pillar_option_bold(value)), old)
122 expect_equal(get_pillar_option_bold(), value)
123 })
124 expect_equal(get_pillar_option_bold(), orig)
125 })
126
127 test_that("subtle", {
128 value <- 0L
129
130 orig <- get_pillar_option_subtle()
131 expect_identical(orig, pillar_options$subtle())
132
133 old <- set_pillar_option_subtle(value)
134 expect_equal(get_pillar_option_subtle(), value)
135 expect_equal(expect_invisible(set_pillar_option_subtle(old)), value)
136
137 old <- pillar_options$subtle(value)
138 expect_equal(pillar_options$subtle(), value)
139 expect_equal(expect_invisible(pillar_options$subtle(old)), value)
140
141 local({
142 expect_equal(expect_invisible(local_pillar_option_subtle(value)), old)
143 expect_equal(get_pillar_option_subtle(), value)
144 })
145 expect_equal(get_pillar_option_subtle(), orig)
146 })
147
148 test_that("subtle_num", {
149 value <- 0L
150
151 orig <- get_pillar_option_subtle_num()
152 expect_identical(orig, pillar_options$subtle_num())
153
154 old <- set_pillar_option_subtle_num(value)
155 expect_equal(get_pillar_option_subtle_num(), value)
156 expect_equal(expect_invisible(set_pillar_option_subtle_num(old)), value)
157
158 old <- pillar_options$subtle_num(value)
159 expect_equal(pillar_options$subtle_num(), value)
160 expect_equal(expect_invisible(pillar_options$subtle_num(old)), value)
161
162 local({
163 expect_equal(expect_invisible(local_pillar_option_subtle_num(value)), old)
164 expect_equal(get_pillar_option_subtle_num(), value)
165 })
166 expect_equal(get_pillar_option_subtle_num(), orig)
167 })
168
169 test_that("neg", {
170 value <- 0L
171
172 orig <- get_pillar_option_neg()
173 expect_identical(orig, pillar_options$neg())
174
175 old <- set_pillar_option_neg(value)
176 expect_equal(get_pillar_option_neg(), value)
177 expect_equal(expect_invisible(set_pillar_option_neg(old)), value)
178
179 old <- pillar_options$neg(value)
180 expect_equal(pillar_options$neg(), value)
181 expect_equal(expect_invisible(pillar_options$neg(old)), value)
182
183 local({
184 expect_equal(expect_invisible(local_pillar_option_neg(value)), old)
185 expect_equal(get_pillar_option_neg(), value)
186 })
187 expect_equal(get_pillar_option_neg(), orig)
188 })
189
190 test_that("sigfig", {
191 value <- 5L
192
193 orig <- get_pillar_option_sigfig()
194 expect_identical(orig, pillar_options$sigfig())
195
196 old <- set_pillar_option_sigfig(value)
197 expect_equal(get_pillar_option_sigfig(), value)
198 expect_equal(expect_invisible(set_pillar_option_sigfig(old)), value)
199
200 old <- pillar_options$sigfig(value)
201 expect_equal(pillar_options$sigfig(), value)
202 expect_equal(expect_invisible(pillar_options$sigfig(old)), value)
203
204 local({
205 expect_equal(expect_invisible(local_pillar_option_sigfig(value)), old)
206 expect_equal(get_pillar_option_sigfig(), value)
207 })
208 expect_equal(get_pillar_option_sigfig(), orig)
209 })
210
211 test_that("min_title_chars", {
212 value <- 12L
213
214 orig <- get_pillar_option_min_title_chars()
215 expect_identical(orig, pillar_options$min_title_chars())
216
217 old <- set_pillar_option_min_title_chars(value)
218 expect_equal(get_pillar_option_min_title_chars(), value)
219 expect_equal(expect_invisible(set_pillar_option_min_title_chars(old)), value)
220
221 old <- pillar_options$min_title_chars(value)
222 expect_equal(pillar_options$min_title_chars(), value)
223 expect_equal(expect_invisible(pillar_options$min_title_chars(old)), value)
224
225 local({
226 expect_equal(expect_invisible(local_pillar_option_min_title_chars(value)), old)
227 expect_equal(get_pillar_option_min_title_chars(), value)
228 })
229 expect_equal(get_pillar_option_min_title_chars(), orig)
230 })
231
232 test_that("min_chars", {
233 value <- 5L
234
235 orig <- get_pillar_option_min_chars()
236 expect_identical(orig, pillar_options$min_chars())
237
238 old <- set_pillar_option_min_chars(value)
239 expect_equal(get_pillar_option_min_chars(), value)
240 expect_equal(expect_invisible(set_pillar_option_min_chars(old)), value)
241
242 old <- pillar_options$min_chars(value)
243 expect_equal(pillar_options$min_chars(), value)
244 expect_equal(expect_invisible(pillar_options$min_chars(old)), value)
245
246 local({
247 expect_equal(expect_invisible(local_pillar_option_min_chars(value)), old)
248 expect_equal(get_pillar_option_min_chars(), value)
249 })
250 expect_equal(get_pillar_option_min_chars(), orig)
251 })
252
253 test_that("max_dec_width", {
254 value <- 0L
255
256 orig <- get_pillar_option_max_dec_width()
257 expect_identical(orig, pillar_options$max_dec_width())
258
259 old <- set_pillar_option_max_dec_width(value)
260 expect_equal(get_pillar_option_max_dec_width(), value)
261 expect_equal(expect_invisible(set_pillar_option_max_dec_width(old)), value)
262
263 old <- pillar_options$max_dec_width(value)
264 expect_equal(pillar_options$max_dec_width(), value)
265 expect_equal(expect_invisible(pillar_options$max_dec_width(old)), value)
266
267 local({
268 expect_equal(expect_invisible(local_pillar_option_max_dec_width(value)), old)
269 expect_equal(get_pillar_option_max_dec_width(), value)
270 })
271 expect_equal(get_pillar_option_max_dec_width(), orig)
272 })
273
274 test_that("bidi", {
275 value <- TRUE
276
277 orig <- get_pillar_option_bidi()
278 expect_identical(orig, pillar_options$bidi())
279
280 old <- set_pillar_option_bidi(value)
281 expect_equal(get_pillar_option_bidi(), value)
282 expect_equal(expect_invisible(set_pillar_option_bidi(old)), value)
283
284 old <- pillar_options$bidi(value)
285 expect_equal(pillar_options$bidi(), value)
286 expect_equal(expect_invisible(pillar_options$bidi(old)), value)
287
288 local({
289 expect_equal(expect_invisible(local_pillar_option_bidi(value)), old)
290 expect_equal(get_pillar_option_bidi(), value)
291 })
292 expect_equal(get_pillar_option_bidi(), orig)
293 })
294
295 test_that("print.tbl ignores max.print option", {
296 trees2 <- as_tbl(trees)
297 expect_output(
298 withr::with_options(list(max.print = 3), print(trees2)),
299 capture_output(print(trees2)),
300 fixed = TRUE
301 )
302 })
303
304 test_that("print.tbl uses tibble.width option", {
305 mtcars2 <- as_tbl(mtcars)
306 expect_output(
307 withr::with_options(list(tibble.width = 40, dplyr.width = 50, width = 60), print(mtcars2)),
308 capture_output(print(mtcars2, width = 40)),
309 fixed = TRUE
310 )
311 expect_output(
312 withr::with_options(list(dplyr.width = 50, width = 60), print(mtcars2)),
313 capture_output(print(mtcars2, width = 50)),
314 fixed = TRUE
315 )
316 expect_output(
317 withr::with_options(list(width = 60), print(mtcars2)),
318 capture_output(print(mtcars2, width = 60)),
319 fixed = TRUE
320 )
321 })