#include "stdafx.h" #include "doctest.h" #include "utilities/Names.h" #include // the table of names: a repeated name goes to the later item, and while the statements of a scenery load out of the order of the file, // to the item of the later statement (docs/world-format-eu07.md, D4) namespace { struct named { std::string label; std::string const &name() const { return label; } }; } // namespace TEST_CASE("a repeated name goes to the item inserted later, as it always did") { basic_table table; auto *first{new named{"tor1"}}; auto *second{new named{"tor1"}}; CHECK(table.insert(first)); CHECK_FALSE(table.insert(second)); CHECK(table.find("tor1") == second); } TEST_CASE("with the statements loading out of order, a repeated name goes to the item of the later statement") { basic_table table; auto *later{new named{"tor1"}}; auto *earlier{new named{"tor1"}}; // the statement 20 of the file loads first, the statement 5 after it table_statement_order() = 20; CHECK(table.insert(later)); table_statement_order() = 5; CHECK_FALSE(table.insert(earlier)); table_statement_order().reset(); CHECK(table.find("tor1") == later); // an item added after the load, at no statement, is the newest one auto *added{new named{"tor1"}}; CHECK_FALSE(table.insert(added)); CHECK(table.find("tor1") == added); }