Files
Library/tests/standalone/FileSystem/Query.cpp
T
faumarayandClaude Sonnet 4.6 a09e000f0f Add Hash, Random, Uuid, Encoding, Bits, Math modules + make Testing deps optional
New header-only modules:
- Void::Hash — FNV-1a 32/64, CRC-32, DJB2, MurmurHash3-32, UDL literals
- Void::Random — Xoshiro256** PRNG, uniform_int/real, coin_flip, shuffle, random_string
- Void::Uuid — v4 (random), v5_lite (name-based), parse, RFC 4122 namespaces
- Void::Encoding — Base64 (standard + URL-safe), Hex encode/decode
- Void::Bits — popcount, bit extract/deposit, rotation, align, byteswap, masks
- Void::Math — Vec2/Vec3/Vec4, Mat4 (identity, translation, scale, rotation)

Testing module: move Stacktrace from INTERNAL_DEPS to OPTIONAL_DEPS. Added
Detail/Color.hpp shim that delegates to Stacktrace::Color when present or
provides inline ANSI fallback otherwise. All Stacktrace calls in SignalHandler,
ConsoleReporter, and Runner are gated on VOID_HAS_STACKTRACE.

Fix Repr.hpp reflect_struct to handle template specializations that lack
std::meta::identifier_of (now guarded by has_identifier check).

33/33 tests pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 21:52:22 +03:00

129 lines
4.0 KiB
C++

#include <Void/FileSystem/Path.hpp>
#include <Void/FileSystem/Query.hpp>
#include <Void/FileSystem/TempDir.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <algorithm>
#include <filesystem>
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"});
}