tests/testthat/test-add_structural_groups.R

# Basic structure ------------------------------------------------------

test_that("add_structural_groups adds expected columns", {
  df <- data.frame(
    rel_path = c(
      "_packages/eviota/R/a.R",
      "_markdown/report/b.qmd"
    ),
    stringsAsFactors = FALSE
  )

  res <- add_structural_groups(df)

  expect_true(
    all(c("structural_group", "component") %in% names(res))
  )

  expect_equal(nrow(res), nrow(df))
})


# Structural grouping derivation ---------------------------------------

test_that("add_structural_groups derives structural grouping heuristics", {
  df <- data.frame(
    rel_path = "_packages/eviota/R/a.R",
    stringsAsFactors = FALSE
  )

  res <- add_structural_groups(df)

  expect_equal(
    res$structural_group,
    "_packages/eviota"
  )

  expect_equal(
    res$component,
    "R"
  )
})


# Minimal paths --------------------------------------------------------

test_that("add_structural_groups handles shallow paths", {
  df <- data.frame(
    rel_path = "README.md",
    stringsAsFactors = FALSE
  )

  res <- add_structural_groups(df)

  expect_equal(
    res$structural_group,
    "README.md"
  )

  expect_true(is.na(res$component))
})


# Error handling -------------------------------------------------------

test_that("add_structural_groups fails without rel_path", {
  df <- data.frame(x = 1)

  expect_error(
    add_structural_groups(df),
    "rel_path"
  )
})


# Integration with snapshot --------------------------------------------

test_that("add_structural_groups works on fscontextdemo_snapshot_02", {
  data("fscontextdemo_snapshot_02")

  res <- add_structural_groups(fscontextdemo_snapshot_02)

  expect_true(
    all(c("structural_group", "component") %in% names(res))
  )

  expect_equal(nrow(res), nrow(fscontextdemo_snapshot_02))
})

Try the fscontext package in your browser

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

fscontext documentation built on Nov. 19, 2026, 5:11 p.m.