test: Add unit tests for file handling and configuration merging (#7)

* test: Add unit tests for file handling and configuration merging

* test: Update IO error conversion test to use new error creation method
This commit is contained in:
Eli Peter 2025-06-24 23:38:32 +02:00 committed by GitHub
parent 8497800b13
commit 46c4732f6e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 225 additions and 57 deletions

View file

@ -31,33 +31,32 @@ pub fn sanitize_project_name(name: &str) -> String {
#[test]
fn sanitize_project_name_is_idempotent_and_lossless_enough() {
let samples = [
("My Project", "my_project"),
("Hello-World", "hello-world"),
("mixed_case", "mixed_case"),
("tabs\tspaces\n", "tabs_spaces"),
(" multiple ", "multiple"),
("weird@$*chars", "weird_chars"),
];
let samples = [
("My Project", "my_project"),
("Hello-World", "hello-world"),
("mixed_case", "mixed_case"),
("tabs\tspaces\n", "tabs_spaces"),
(" multiple ", "multiple"),
("weird@$*chars", "weird_chars"),
];
for (input, expected) in samples {
assert_eq!(sanitize_project_name(input), expected, "input: {}", input);
assert_eq!(sanitize_project_name(expected), expected);
}
for (input, expected) in samples {
assert_eq!(sanitize_project_name(input), expected, "input: {}", input);
assert_eq!(sanitize_project_name(expected), expected);
}
}
#[test]
fn get_project_info_uses_sanitized_name_in_sqlite_path() {
let tmp = tempfile::tempdir().unwrap();
let root = tmp.path();
let project_dir = root.join("Example Project");
std::fs::create_dir(&project_dir).unwrap();
let tmp = tempfile::tempdir().unwrap();
let root = tmp.path();
let (project_name, db_path) =
get_project_info(&project_dir, root).expect("should detect project");
let project_dir = root.join("Example Project");
std::fs::create_dir(&project_dir).unwrap();
assert_eq!(project_name, "Example Project");
assert_eq!(db_path, root.join("example_project.sqlite"));
let (project_name, db_path) =
get_project_info(&project_dir, root).expect("should detect project");
assert_eq!(project_name, "Example Project");
assert_eq!(db_path, root.join("example_project.sqlite"));
}