#pragma once #include #include #include #include #include #include #include "edit/edit.h" #include "model/json.h" #include "model/xml.h" inline const std::filesystem::path TEST_DIR = ANM2ED_TEST_DIR; inline const std::filesystem::path CORPUS_DIR = TEST_DIR / "corpus"; inline const std::filesystem::path GOLDEN_DIR = TEST_DIR / "golden"; inline constexpr std::pair PRESETS[] = {{"default", SERIALIZE_DEFAULT}, {"editor", SERIALIZE_EDITOR_DEFAULT}, {"isaac", SERIALIZE_ISAAC_DEFAULT}, {"anm2ed", SERIALIZE_ANM2ED_DEFAULT}}; inline constexpr std::pair MERGES[] = {{"merge_prepend", MERGE_PREPEND}, {"merge_append", MERGE_APPEND}, {"merge_replace", MERGE_REPLACE}, {"merge_ignore", MERGE_IGNORE}}; using Variant = std::pair; inline std::string file_load(const std::filesystem::path& path) { std::ifstream file(path, std::ios::binary); return {std::istreambuf_iterator(file), {}}; } inline void file_save(const std::filesystem::path& path, const std::string& text) { std::filesystem::create_directories(path.parent_path()); std::ofstream(path, std::ios::binary) << text; } inline bool is_env_set(const char* name) { return std::getenv(name) != nullptr; } inline std::vector fixtures_get() { std::vector fixtures{}; for (const auto& entry : std::filesystem::directory_iterator(CORPUS_DIR)) if (entry.path().extension() == ".anm2") fixtures.push_back(entry.path()); std::ranges::sort(fixtures); return fixtures; } inline Model model_load(const std::string& text) { Model model{}; REQUIRE(model_load_string(model, text)); return model; } // Every serialization and merge the editor can produce for a document; goldens lock each one down. inline std::vector variants_get(const Model& model) { std::vector variants{}; for (auto [name, flags] : PRESETS) variants.emplace_back(name, model_serialize(model, flags)); variants.emplace_back("save", model_to_string(model)); for (auto [name, type] : MERGES) { auto merged = model; std::set sources{0, 1, 2}; animations_merge(merged, 0, sources, type, type == MERGE_PREPEND || type == MERGE_REPLACE, {}); variants.emplace_back(name, model_serialize(merged, SERIALIZE_ANM2ED_DEFAULT)); } return variants; } // The outer document of a save with its SourceDocument (the root's last child, on lines of its own) removed: what // the game reads. inline std::string game_document_get(std::string text) { constexpr std::string_view END = ""; auto start = text.find("\n