tests/testthat/test-utils-text.R

test_that("get_text_dim_cm works", {

  style <- theme_gray()$text

  withr::with_pdf(
    tempfile(fileext = ".pdf"),
    {
      width  <- get_text_dim_cm("foobar", style, "width")
      height <- get_text_dim_cm("foobar", style, "height")
      both   <- get_text_dim_cm("foobar", style, "both")
    }
  )

  expect_equal(both$width, width)
  expect_equal(both$height, height)

  expect_error(
    get_text_dim_cm("foobar", element_rect(), "both"),
    "must be"
  )
})

test_that("get_fontmetrics works", {
  style <- theme_gray()$text
  metrics <- get_fontmetrics(style)
  expect_true(is.list(metrics))
})

Try the legendry package in your browser

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

legendry documentation built on April 4, 2025, 2:12 a.m.