Checkpoint 4: harden native paths, authoring workflows and Player lifecycle
This commit is contained in:
+40
-2
@@ -33,6 +33,44 @@ int main() {
|
||||
faset::sha256(faset::read_text(directory / "state.json")));
|
||||
CHECK(std::filesystem::equivalent(faset::project_path(directory, "assets/../state.json"),
|
||||
directory / "state.json"));
|
||||
const auto unicode = directory / faset::path_from_utf8("Faset Café 世界/Сцена 😀.json");
|
||||
faset::atomic_write_json(unicode, {{"hello", "Unicode paths"}});
|
||||
faset::atomic_write_json(unicode, {{"hello", "Replaced"}});
|
||||
CHECK(faset::read_json(unicode).at("hello") == "Replaced");
|
||||
CHECK(faset::sha256_file(unicode) == faset::sha256(faset::read_text(unicode)));
|
||||
CHECK(faset::path_from_utf8(faset::path_to_utf8(unicode)) == unicode);
|
||||
CHECK(faset::generic_path_to_utf8(unicode.lexically_relative(directory)) ==
|
||||
"Faset Café 世界/Сцена 😀.json");
|
||||
CHECK(std::filesystem::equivalent(
|
||||
faset::project_path(directory, faset::path_from_utf8("Faset Café 世界/Сцена 😀.json")),
|
||||
unicode));
|
||||
for (const auto& invalid :
|
||||
std::vector<std::string>{std::string("a\0b", 3), "\xc0\xaf", "\xed\xa0\x80",
|
||||
"\xf4\x90\x80\x80", "\xe2\x82", "\x80"}) {
|
||||
bool invalid_rejected = false;
|
||||
try {
|
||||
faset::path_from_utf8(invalid);
|
||||
} catch (const faset::Error& error) {
|
||||
invalid_rejected = error.json().at("code") == "path.encoding";
|
||||
}
|
||||
CHECK(invalid_rejected);
|
||||
}
|
||||
auto deep = directory / faset::path_from_utf8("Long Café 世界");
|
||||
while (deep.native().size() < 310)
|
||||
deep /= "directory-segment-0123456789";
|
||||
const auto long_file = deep / faset::path_from_utf8("Сцена 世界.json");
|
||||
faset::atomic_write_json(long_file, {{"long_path", true}});
|
||||
CHECK(faset::read_json(long_file).at("long_path") == true);
|
||||
CHECK(faset::sha256_file(long_file) == faset::sha256(faset::read_text(long_file)));
|
||||
CHECK(std::filesystem::is_regular_file(faset::native_io_path(long_file)));
|
||||
CHECK(faset::path_to_utf8(long_file).find("\\\\?\\") == std::string::npos);
|
||||
#ifdef _WIN32
|
||||
CHECK(faset::native_io_path(long_file).native().starts_with(LR"(\\?\)"));
|
||||
CHECK(faset::native_io_path(std::filesystem::path(LR"(\\server\share\file.txt)")) ==
|
||||
std::filesystem::path(LR"(\\?\UNC\server\share\file.txt)"));
|
||||
CHECK(faset::native_io_path(faset::native_io_path(long_file)) ==
|
||||
faset::native_io_path(long_file));
|
||||
#endif
|
||||
bool rejected = false;
|
||||
try {
|
||||
faset::project_path(directory, "../escape");
|
||||
@@ -47,12 +85,12 @@ int main() {
|
||||
rejected = true;
|
||||
}
|
||||
CHECK(rejected);
|
||||
std::filesystem::remove_all(directory);
|
||||
std::filesystem::remove_all(faset::native_io_path(directory));
|
||||
std::cout << "Core: SHA-256 vectors, persistent IDs, durable replace, Unicode, path "
|
||||
"boundaries passed\n";
|
||||
return 0;
|
||||
} catch (const std::exception& error) {
|
||||
std::filesystem::remove_all(directory);
|
||||
std::filesystem::remove_all(faset::native_io_path(directory));
|
||||
std::cerr << error.what() << '\n';
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user