/usr/share/doc/r-cran-rlang/tests/testthat/test-expr.R is in r-cran-rlang 0.2.0-1.
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 | context("expr")
# expr_text() --------------------------------------------------------
test_that("always returns single string", {
out <- expr_text(quote({
a + b
}))
expect_length(out, 1)
})
test_that("can truncate lines", {
out <- expr_text(quote({
a + b
}), nlines = 2)
expect_equal(out, "{\n...")
})
# expr_label() -------------------------------------------------------
test_that("quotes strings", {
expect_equal(expr_label("a"), '"a"')
expect_equal(expr_label("\n"), '"\\n"')
})
test_that("backquotes names", {
expect_equal(expr_label(quote(x)), "`x`")
})
test_that("converts atomics to strings", {
expect_equal(expr_label(0.5), "0.5")
})
test_that("expr_label() truncates blocks", {
expect_identical(expr_label(quote({ a + b })), "`{ ... }`")
expect_identical(expr_label(expr(function() { a; b })), "`function() ...`")
})
test_that("expr_label() truncates long calls", {
long_call <- quote(foo())
long_arg <- quote(longlonglonglonglonglonglonglonglonglonglonglong)
long_call[c(2, 3, 4)] <- list(long_arg, long_arg, long_arg)
expect_identical(expr_label(long_call), "`foo(...)`")
})
# expr_name() --------------------------------------------------------
test_that("name symbols, calls, and scalars", {
expect_identical(expr_name(quote(foo)), "foo")
expect_identical(expr_name(quote(foo(bar))), "foo(bar)")
expect_identical(expr_name(1L), "1")
expect_identical(expr_name("foo"), "foo")
expect_identical(expr_name(function() NULL), "function () ...")
expect_error(expr_name(1:2), "must quote a symbol, scalar, or call")
expect_identical(expr_name(expr(function() { a; b })), "function() ...")
})
# --------------------------------------------------------------------
test_that("get_expr() supports closures", {
skip("Disabled because causes dplyr to fail")
expect_identical(get_expr(identity), quote(x))
})
test_that("set_expr() supports closures", {
fn <- function(x) x
expect_equal(set_expr(fn, quote(y)), function(x) y)
})
test_that("expressions are deparsed and printed", {
expect_output(expr_print(1:2), "<int: 1L, 2L>")
expect_identical(expr_deparse(1:2), "<int: 1L, 2L>")
})
|