/usr/share/doc/r-cran-tibble/tests/testthat/test-trunc-mat.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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | context("Truncated matrix")
test_that("interface of print() identical to trunc_mat()", {
print_arg_names <- names(formals(print.tbl))
print_arg_names_without_ellipsis <- setdiff(print_arg_names, "...")
trunc_mat_arg_names <- names(formals(trunc_mat))
expect_equal(print_arg_names_without_ellipsis, trunc_mat_arg_names)
})
test_that("print() returns output invisibly", {
expect_output(ret <- withVisible(print(as_tibble(mtcars))))
expect_false(ret$visible)
expect_identical(ret$value, as_tibble(mtcars))
})
test_that("trunc_mat output matches known output", {
skip("Skip tests requiring mockr")
expect_output_file_rel(
print_without_body(as_tibble(mtcars), n = 8L, width = 30L),
"trunc_mat/mtcars-8-30.txt"
)
expect_output_file_rel(
print_without_body(as_tibble(iris), n = 5L, width = 30L),
"trunc_mat/iris-5-30.txt"
)
expect_output_file_rel(
print_without_body(as_tibble(iris), n = 3L, width = 5L),
"trunc_mat/iris-3-5.txt"
)
expect_output_file_rel(
print_without_body(as_tibble(iris), n = NULL, width = 70L),
"trunc_mat/iris--70.txt"
)
expect_output_file_rel(
print_without_body(as_unknown_rows(iris), n = 10, width = 70L),
"trunc_mat/iris_unk-10-70.txt"
)
expect_output_file_rel(
print_without_body(df_all, n = NULL, width = 30L),
"trunc_mat/all--30.txt"
)
expect_output_file_rel(
print_without_body(df_all, n = NULL, width = 300L),
"trunc_mat/all--300.txt"
)
expect_output_file_rel(
print_without_body(tibble(a = seq.int(10000)), n = 5L, width = 30L),
"trunc_mat/long-5-30.txt"
)
expect_output_file_rel(
print_without_body(tibble(a = character(), b = logical()), width = 30L),
"trunc_mat/zero_rows--30.txt"
)
expect_output_file_rel(
print_without_body(as_tibble(iris)[character()], n = 5L, width = 30L),
"trunc_mat/zero_cols-5-30.txt"
)
expect_output_file_rel(
print_without_body(as_unknown_rows(iris[integer(), ]), n = 5L, width = 30L),
"trunc_mat/zero-rows_unk-5-30.txt"
)
expect_output_file_rel(
print_without_body(as_unknown_rows(iris[, character()]), n = 5L, width = 30L),
"trunc_mat/zero-cols_unk-5-30.txt"
)
expect_output_file_rel(
print_without_body(
as_unknown_rows(tibble(a = seq.int(10000))),
n = 5L,
width = 30L
),
"trunc_mat/long_unk-5-30.txt"
)
expect_output_file_rel(
print_without_body(trunc_mat(df_all, n = 1L, n_extra = 2L, width = 30L)),
"trunc_mat/all-1-30-2.txt"
)
expect_output_file_rel(
print_without_body(trunc_mat(df_all, n = 1L, n_extra = 0L, width = 30L)),
"trunc_mat/all-1-30-0.txt"
)
expect_output_file_rel(
print_without_body(trunc_mat(tibble("mean(x)" = 5, "var(x)" = 3), width = 28)),
"trunc_mat/non-syntactic.txt"
)
})
test_that("trunc_mat for POSIXlt columns (#86)", {
skip_on_os("windows")
df <- tibble(x = as.POSIXct("2016-01-01 12:34:56 GMT") + 1:12)
df$y <- as.POSIXlt(df$x)
expect_output_file_rel(
print(as_tibble(df), n = 8L, width = 60L),
"trunc_mat/POSIXlt-8-60.txt"
)
})
test_that("trunc_mat for wide-character columns (#100)", {
skip_on_os("windows") # capture_output_lines() forces native encoding
x <- c("\u6210\u4ea4\u65e5\u671f", "\u5408\u540c\u5f55\u5165\u65e5\u671f")
df <- setNames(tibble(1:3, 4:6), x)
expect_output_file_rel(
print(df, n = 8L, width = 60L),
"trunc_mat/wide-8-60.txt"
)
})
test_that("trunc_mat for wide-character columns in non-UTF-8 locale", {
skip_on_os("windows") # capture_output_lines() forces native encoding
with_non_utf8_locale({
x <- c("\u6210\u4ea4\u65e5\u671f", "\u5408\u540c\u5f55\u5165\u65e5\u671f")
df <- setNames(tibble(1:3, 4:6), x)
expect_output_file_rel(
print(df, n = 8L, width = 60L),
"trunc_mat/wide-8-60.txt"
)
})
})
|