tests/testthat/test-construct_reprex.R

test_that("construct_reprex", {
  fun <- function() {
    hello <- 0
    outer(100, hello + world)
  }

  outer <- function(a, b) {
    a <- a + 1
    c <- 3
    inner1(a, c)
    inner2(a, c)
    inner3(a, c)
  }

  inner1 <- function(x, y) {
    writeLines("# 1 ------------------------------------------------------\n")
    x <- x + 1
    z <- 3
    reprex <- construct_reprex()
    print(reprex)
  }

  inner2 <- function(x, y) {
    writeLines("\n# 2 ------------------------------------------------------\n")
    x <- x + 1
    z <- 3
    reprex <- construct_reprex(1)
    print(reprex)
  }

  inner3 <- function(x, y) {
    writeLines("\n# 3 ------------------------------------------------------\n")
    x <- x + 1
    z <- 3
    .z <- 33
    reprex <- construct_reprex(2, include_dotted = FALSE)
    print(reprex)
  }

  expect_snapshot({
    fun()
  })
})

Try the constructive package in your browser

Any scripts or data that you put into this service are public.

constructive documentation built on April 3, 2025, 9:39 p.m.