tests/testthat/test-snapshot.R

test_that("the data extracted from font file are as expected", {
  expect_snapshot(string2path("A", "./font/test.ttf"))
  expect_snapshot(string2stroke("A", "./font/test.ttf"))
  expect_snapshot(string2fill("A", "./font/test.ttf"))
})

test_that("handle white spaces", {
  expect_snapshot(string2path("A A", "./font/test.ttf"))
})


test_that("the data extracted from installed font are as expected", {
  skip_if_not(isTRUE("Arial" %in% dump_fontdb()$family))

  expect_snapshot(string2path("A", "Arial"))
  expect_snapshot(string2stroke("A", "Arial"))
  expect_snapshot(string2fill("A", "Arial"))
})

test_that("path and fill match", {
  skip_if_not(isTRUE("Arial" %in% dump_fontdb()$family))
  skip_if_not_installed("vdiffr")

  do_plot_s <- function() {
    p <- string2path("s", "Arial", tolerance = 3e-3)
    f <- string2fill("s", "Arial", tolerance = 3e-3)
    
    plot(NULL, xlim = c(0, 0.45), ylim = c(0, 0.45))
    for (tri in split(f, f$triangle_id)) {
      polygon(tri$x, tri$y, col = "#ff3344", border = "transparent")
    }
    lines(p$x, p$y, lwd = 10)
  }
  vdiffr::expect_doppelganger("path and fill match", do_plot_s())
})

Try the string2path package in your browser

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

string2path documentation built on April 3, 2025, 10:29 p.m.