Universal additions (all generic, header-only, tested; full suite 1127 pass): - Void::Encoding::Url — RFC 3986 percent encode/decode + query_encode. - Void::Text::html_unescape — numeric + common named HTML entities -> UTF-8. - Void::Time::parse_iso8601_interval — parse PT#H#M#S / P#DT#H#M#S durations (distinct from the unit-suffix parse_duration). - Void::FileSystem::TempFile — RAII unique temp file (alongside TempDir), with keep() to persist. - Void::Random::random_string(n, charset) overload. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
61 lines
1.6 KiB
C++
61 lines
1.6 KiB
C++
#include <Void/System/TempFile.hpp>
|
|
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Test.hpp>
|
|
|
|
#include <filesystem>
|
|
#include <fstream>
|
|
#include <utility>
|
|
|
|
Void::Testing::Test temp_file_creates_under_temp_and_removes()
|
|
{
|
|
std::filesystem::path captured;
|
|
{
|
|
Void::FileSystem::TempFile tmp;
|
|
captured = tmp.path();
|
|
Void::Testing::expect(std::filesystem::is_regular_file(captured));
|
|
Void::Testing::expect(captured.parent_path() ==
|
|
std::filesystem::temp_directory_path());
|
|
}
|
|
Void::Testing::expect(!std::filesystem::exists(captured));
|
|
}
|
|
|
|
Void::Testing::Test temp_file_honors_extension()
|
|
{
|
|
Void::FileSystem::TempFile tmp{"void_", ".so"};
|
|
Void::Testing::expect_eq(tmp.path().extension().string(),
|
|
std::string{".so"});
|
|
}
|
|
|
|
Void::Testing::Test temp_file_keep_persists()
|
|
{
|
|
std::filesystem::path captured;
|
|
{
|
|
Void::FileSystem::TempFile tmp;
|
|
captured = tmp.keep();
|
|
}
|
|
Void::Testing::expect(std::filesystem::exists(captured));
|
|
std::error_code ec;
|
|
std::filesystem::remove(captured, ec); // manual cleanup
|
|
}
|
|
|
|
Void::Testing::Test temp_file_move_transfers_ownership()
|
|
{
|
|
std::filesystem::path captured;
|
|
{
|
|
Void::FileSystem::TempFile a;
|
|
captured = a.path();
|
|
Void::FileSystem::TempFile b = std::move(a);
|
|
Void::Testing::expect_eq(b.path(), captured);
|
|
Void::Testing::expect(a.path().empty());
|
|
}
|
|
// Removed once (by b); no double-remove crash.
|
|
Void::Testing::expect(!std::filesystem::exists(captured));
|
|
}
|
|
|
|
Void::Testing::Test temp_files_are_unique()
|
|
{
|
|
Void::FileSystem::TempFile a;
|
|
Void::FileSystem::TempFile b;
|
|
Void::Testing::expect(a.path() != b.path());
|
|
}
|