- XML text is printed straight from the node tree by a Printer that matches tinyxml2's XMLPrinter byte for byte; no tinyxml2 document is built to save. - Numbers format with std::to_chars (whole numbers as integers) instead of snprintf, with the same text as "%.8g". - Frame attribute and track child vectors are reserved up front. - Repeated attributes in a read file collapse as tinyxml2 wrote them. Corpus (1,251 files, Release): save 4.2 s -> 0.77 s, extended save 0.61 s -> 0.12 s, hash 0.28 s -> 0.13 s; every output is byte-identical. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
30 lines
984 B
C++
30 lines
984 B
C++
#include "common.hpp"
|
|
|
|
using namespace anm2ed;
|
|
using namespace anm2ed::test;
|
|
|
|
TEST_CASE("per-fixture invariants")
|
|
{
|
|
for (const auto& fixture : fixtures_get())
|
|
{
|
|
INFO("fixture: ", fixture.filename().string());
|
|
invariants_check(model_load(file_load(fixture)));
|
|
}
|
|
}
|
|
|
|
TEST_CASE("saved text is what tinyxml2 prints for the same document")
|
|
{
|
|
auto model = model_load(file_load(CORPUS_DIR / "11_unknown.anm2"));
|
|
model.extras.children.emplace_back(
|
|
0, model::XmlNode{.tag = "Note",
|
|
.attributes = {{"Quote", "it's \"x\" & <y>"}},
|
|
.text = "a & b > c 'd' \"e\"",
|
|
.children = {{.tag = "Inner", .children = {{.tag = "Leaf", .attributes = {{"A", "1"}}}}}}});
|
|
auto text = model::model_to_string(model);
|
|
tinyxml2::XMLDocument document{};
|
|
REQUIRE(document.Parse(text.c_str()) == tinyxml2::XML_SUCCESS);
|
|
tinyxml2::XMLPrinter printer{};
|
|
document.Print(&printer);
|
|
CHECK(text == printer.CStr());
|
|
}
|