#include #include #include #include #include #include #include Void::Testing::Test exists_returns_true_for_existing_file() { Void::FileSystem::TempDir tmp; auto p = tmp / "f.txt"; (void)Void::FileSystem::write_file(p, "x"); Void::Testing::expect(Void::FileSystem::exists(p)); } Void::Testing::Test exists_returns_false_for_missing() { Void::FileSystem::TempDir tmp; Void::Testing::expect(!Void::FileSystem::exists(tmp / "no_such.txt")); } Void::Testing::Test file_size_returns_correct_byte_count() { Void::FileSystem::TempDir tmp; auto p = tmp / "sized.txt"; (void)Void::FileSystem::write_file(p, "hello"); auto r = Void::FileSystem::file_size(p); Void::Testing::expect(r.has_value()); Void::Testing::expect_eq(*r, std::uintmax_t{5}); } Void::Testing::Test file_size_fails_for_missing_path() { auto r = Void::FileSystem::file_size("/no/such/file.txt"); Void::Testing::expect(!r.has_value()); } Void::Testing::Test last_modified_returns_a_time() { Void::FileSystem::TempDir tmp; auto p = tmp / "ts.txt"; (void)Void::FileSystem::write_file(p, "data"); auto r = Void::FileSystem::last_modified(p); Void::Testing::expect(r.has_value()); } Void::Testing::Test last_modified_fails_for_missing_path() { auto r = Void::FileSystem::last_modified("/no/such/file.txt"); Void::Testing::expect(!r.has_value()); } Void::Testing::Test list_directory_returns_created_entries() { Void::FileSystem::TempDir tmp; (void)Void::FileSystem::write_file(tmp / "a.txt", ""); (void)Void::FileSystem::write_file(tmp / "b.txt", ""); auto r = Void::FileSystem::list_directory(tmp.path()); Void::Testing::expect(r.has_value()); Void::Testing::expect(r->size() >= 2); const auto has_a = std::any_of(r->begin(), r->end(), [&](const auto& p) { return p.filename() == "a.txt"; }); const auto has_b = std::any_of(r->begin(), r->end(), [&](const auto& p) { return p.filename() == "b.txt"; }); Void::Testing::expect(has_a); Void::Testing::expect(has_b); } Void::Testing::Test list_directory_fails_for_missing_path() { auto r = Void::FileSystem::list_directory("/no/such/directory"); Void::Testing::expect(!r.has_value()); } Void::Testing::Test copy_file_creates_duplicate() { Void::FileSystem::TempDir tmp; auto src = tmp / "src.txt"; auto dst = tmp / "dst.txt"; (void)Void::FileSystem::write_file(src, "contents"); auto r = Void::FileSystem::copy_file(src, dst); Void::Testing::expect(r.has_value()); auto back = Void::FileSystem::read_file(dst); Void::Testing::expect(back.has_value()); Void::Testing::expect_eq(*back, std::string{"contents"}); } Void::Testing::Test copy_file_fails_without_overwrite_when_dst_exists() { Void::FileSystem::TempDir tmp; auto src = tmp / "src.txt"; auto dst = tmp / "dst.txt"; (void)Void::FileSystem::write_file(src, "new"); (void)Void::FileSystem::write_file(dst, "old"); auto r = Void::FileSystem::copy_file(src, dst, /*overwrite=*/false); Void::Testing::expect(!r.has_value()); } Void::Testing::Test copy_file_with_overwrite_replaces_dst() { Void::FileSystem::TempDir tmp; auto src = tmp / "src.txt"; auto dst = tmp / "dst.txt"; (void)Void::FileSystem::write_file(src, "new_content"); (void)Void::FileSystem::write_file(dst, "old_content"); auto r = Void::FileSystem::copy_file(src, dst, /*overwrite=*/true); Void::Testing::expect(r.has_value()); auto back = Void::FileSystem::read_file(dst); Void::Testing::expect_eq(*back, std::string{"new_content"}); } Void::Testing::Test copy_dir_duplicates_tree() { Void::FileSystem::TempDir tmp; auto src = tmp / "src"; auto dst = tmp / "dst"; (void)Void::FileSystem::ensure_directory(src); (void)Void::FileSystem::write_file(src / "file.txt", "tree"); auto r = Void::FileSystem::copy_dir(src, dst); Void::Testing::expect(r.has_value()); auto back = Void::FileSystem::read_file(dst / "file.txt"); Void::Testing::expect(back.has_value()); Void::Testing::expect_eq(*back, std::string{"tree"}); }