This internal helper identifies expectation calls (e.g., `expect_equal()`, `expect_true()`, etc.) within parse data extracted from a testthat test file. The function locates expectation function calls by matching their token text and returns a structured data frame containing the expectation names and their corresponding source line ranges.
get_expect(parsed_data, token_text = "^expect_")A data.frame where each row corresponds to a detected expectation.
The data frame contains:
Character. Name of the expectation function (e.g.,
"expect_equal").
Integer. Starting line number of the expression.
Integer. Ending line number of the expression.
Returns NULL if no matching expectations are found.
data.frame. Parse data produced by
utils::getParseData(parse(file, keep.source = TRUE), includeText = TRUE).
Must include the columns token, text, line1,
and line2.
Character. A regular expression used to detect
expectation‑style function calls. Defaults to "^expect_".
The function:
locates all rows where the token is "SYMBOL_FUNCTION_CALL"
and the text matches token_text,
identifies the expression node corresponding to each expectation,
extracts line ranges (line1, line2) describing where the
expectation appears in the source file, and
returns a consolidated data frame of results.
If no expectation calls are found, the function returns NULL.
This helper is used internally by STF mapping functions (such as
map_test() and map_tests_stf()) when constructing a full
hierarchy of test blocks and expectations.