Error in `grepl(sprintf("^%s", export_dir), dir_path)`: invalid regular expression '^D:\temp\2024_11_11_19_25_02_2745\RtmpOmQzhA\textAnnotatoR-tests\exports', reason 'Invalid back reference'

# Reuse helper functions from previous test file
test_that("validate_directory works with tempdir", {
# Test non-existent directory - Mock handle_error to force error
handle_error = function(expr, error_msg = NULL, ...) {
expect_error(validate_directory(bad_dir), "Directory does not exist")
test_that("update_text_display formats text correctly", {
# Call the actual update_text_display function
# Check for specific HTML patterns using single quotes since that's what the function produces
expect_match(result, "class='code-display'.*?\\[code1\\]", perl = TRUE)
expect_match(result, "class='code-display'.*?\\[code2\\]", perl = TRUE)
# Setup test annotations with larger gap to ensure proper clustering
start = c(1, 5, 100, 200),  # Increased gaps between clusters
code = c("code1", "code2", "code3", "code4"),
# The first cluster should only contain the first two annotations
# since they are close together (1-3 and 5-8)
expect_equal(length(transitions), 2)  # Should have 2 transitions
# Add small delay to ensure different modification times
# Use local_mocked_bindings instead of with_mock
result <- create_backup_dir(max_backups = 3)
# Should only keep 3 most recent backups
skip_on_os("windows") # Skip on Windows as path handling differs
get_export_dir = function() normalizePath(export_dir, winslash = "/", mustWork = FALSE),
if (is.null(res)) return(normalizePath(export_dir, winslash = "/", mustWork = FALSE))
# Test valid path inside export directory
test_path <- normalizePath(test_path, winslash = "/", mustWork = FALSE)
result <- clean_export_path(test_path, create = TRUE)
normalizePath(result, winslash = "/", mustWork = FALSE),
normalizePath(export_dir, winslash = "/", mustWork = FALSE)
# Test path outside export directory gets redirected
# Test path with special regex characters
test_that("clean_export_path handles Windows paths", {
skip_on_os(c("linux", "mac", "solaris")) # Only run on Windows
export_dir <- normalizePath(file.path(env$test_dir, "exports"), winslash = "\\", mustWork = FALSE)
# Test valid Windows path inside export directory
tolower(normalizePath(result, winslash = "\\", mustWork = FALSE)),
tolower(normalizePath(export_dir, winslash = "\\", mustWork = FALSE))
# Test Windows path outside export directory gets redirected