"project parameter works in core functions"
"Projects in temp directories use flat structure"
"Project listing not supported in temp directories with flat structure"
"default project maintains backward compatibility"

project parameter works in core functions

dest_db$measures$anxiety$description not equal to "Anxiety scale".
target is NULL, current is character

dest_db$measures$anxiety$items not equal to 10.
target is NULL, current is numeric

default project maintains backward compatibility

Error in `boilerplate_save(db, data_path = temp_dir, confirm = FALSE, quiet = TRUE)`: Directory does not exist: D:\temp\2025_06_12_16_45_17_25820\RtmpwPIMz6\file2dbac7d751c41/projects/default/data. Set create_dirs=TRUE to create it.

# Note: ask_yes_no() uses readline() and can only be tested interactively.
# Since most utilities.R functions are internal (not exported),
# we'll test them indirectly through the functions that use them.
# Here we'll add some integration tests that exercise the internal utilities.
test_that("internal utilities work through public functions", {
# These tests exercise internal functions like:
# - sort_db_recursive (through boilerplate_sort_db)
# - get_nested_folder (through various path operations)
# - modify_nested_entry (through boilerplate_add_entry, etc.)
# - merge_recursive_lists (through boilerplate_merge_databases)
# - apply_template_vars (through boilerplate_generate_text)
# Test sort_db_recursive via boilerplate_sort_db
# Test get_nested_folder via boilerplate_path_exists
# Create temp directory for file-based tests
# Test modify_nested_entry via management functions
list(description = "Linear regression", text = "Using lm()")
# Test merge_recursive_lists via boilerplate_merge_databases
# Use direct merge without user interaction
# Since this is testing internal merge functionality, we'll skip this interactive test
# The merge function requires user input when conflicts exist
expect_equal(merged$a$b$d, "value2")  # Preserved from db1
expect_equal(merged$a$b$f, "new_value")  # Added from db2
expect_equal(merged$a$e, "value3")  # Preserved from db1
expect_equal(merged$a$g, "another_new")  # Added from db2
test_that("path utility functions handle edge cases", {
# Test with paths containing special characters
data = "should not be confused with path separator"
# These should work as the actual structure uses these as keys
test_db <- list(a = list(b = list(c = "value")))
expect_false(boilerplate_path_exists(test_db, "a..c"))  # Empty component
expect_false(boilerplate_path_exists(test_db, ".b.c"))   # Leading dot
# Note: "a.b." might return TRUE if it treats trailing dot as "a.b"
# This behavior may vary based on implementation
test_that("file path utilities work correctly", {
# Test that get_db_file_path generates correct paths (via boilerplate_save)
# Create a unified database with multiple categories
measures = list(test = list(description = "Test measure"))
# Save unified database - boilerplate_save should detect it's unified
boilerplate_save(db, data_path = temp_dir, confirm = FALSE, quiet = TRUE)
# Check file was created with correct naming (JSON by default)
files <- list.files(temp_dir, pattern = "\\.json$")
files <- list.files(temp_dir, pattern = "methods_db.*\\.json$")
test_that("template variable application works correctly", {
default = "We analysed {{dataset}} using {{method}} with {{software}}."
"We analysed NHANES data using linear regression with R version 4.3."
# Test with missing variables - warning is expected
test_that("recursive list operations preserve structure", {