/usr/share/doc/r-cran-tibble/tests/testthat/test-glimpse.R is in r-cran-tibble 1.4.1-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | context("Glimpse")
test_that("format_v for values", {
expect_equal(format_v(1), "1")
expect_equal(format_v(1:3), c("1", "2", "3"))
expect_equal(format_v(NA), "NA")
expect_equal(format_v(TRUE), "TRUE")
expect_equal(format_v(logical()), character())
})
test_that("format_v for character", {
expect_equal(format_v("1"), paste0('"', "1", '"'))
expect_equal(format_v(letters), paste0('"', letters, '"'))
expect_equal(format_v(NA_character_), "NA")
expect_equal(format_v(character()), character())
})
test_that("format_v for list", {
expect_equal(format_v(list(1:3)), "[<1, 2, 3>]")
expect_equal(format_v(as.list(1:3)), "[1, 2, 3]")
expect_equal(format_v(list(1:3, 4)), "[<1, 2, 3>, 4]")
expect_equal(format_v(list(1:3, 4:5)), "[<1, 2, 3>, <4, 5>]")
expect_equal(format_v(list()), "[]")
expect_equal(format_v(list(list())), "[[]]")
expect_equal(format_v(list(character())), "[<>]")
expect_equal(format_v(list(1:3, list(4))), "[<1, 2, 3>, [4]]")
expect_equal(format_v(list(1:3, list(4:5))), "[<1, 2, 3>, [<4, 5>]]")
})
test_that("glimpse output matches known output", {
expect_output_file_rel(
glimpse(as_tibble(mtcars), width = 70L),
"glimpse/mtcars-70.txt"
)
expect_output_file_rel(
glimpse(as_tibble(iris), width = 70L),
"glimpse/iris-70.txt"
)
expect_output_file_rel(
glimpse(as_tibble(iris[integer()]), width = 70L),
"glimpse/iris-empty-70.txt"
)
expect_output_file_rel(
glimpse(tibble("mean(x)" = 5, "var(x)" = 3), width = 28),
"glimpse/non-syntactic.txt"
)
expect_output_file_rel(
glimpse(as_tibble(df_all), width = 70L),
"glimpse/all-70.txt"
)
withr::with_options(
list(tibble.width = 50),
expect_output_file_rel(
glimpse(as_tibble(df_all)),
"glimpse/all-50.txt"
)
)
withr::with_options(
list(tibble.width = 35),
expect_output_file_rel(
glimpse(as_tibble(df_all)),
"glimpse/all-35.txt"
)
)
expect_output_file_rel(
glimpse(5),
"glimpse/5.txt"
)
})
test_that("glimpse(width = Inf) raises legible error", {
expect_error(
glimpse(mtcars, width = Inf),
"`width` must be finite",
fixed = TRUE
)
})
|