tests/tinytest/test-get_root.R

source("helpers.R")

src <- "
print('hi')
fn <- function() {
  print('hello')
}
"
root <- src |>
  tree_new() |>
  tree_root()

expect_equal(
  root |>
    node_find(ast_rule("print($A)")) |>
    node_get_root() |>
    tree_root() |>
    node_text(),
  root |>
    node_text()
)

Try the astgrepr package in your browser

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

astgrepr documentation built on June 8, 2025, 11:05 a.m.