diff --git a/schema/schema3.cc b/schema/schema3.cc index a035219d4..a6ad4367f 100644 --- a/schema/schema3.cc +++ b/schema/schema3.cc @@ -315,6 +315,15 @@ namespace schema3 return false; }); + + // add any I/O variables + vector inVars, outVars; + for (auto& i: g.inVariables) + inVars.push_back(itemMap[i.get()]); + for (auto& i: g.outVariables) + outVars.push_back(itemMap[i.get()]); + inVariables=inVars; + outVariables=outVars; // search for and link up integrals to their variables, and Godley table ports g.recursiveDo(&minsky::GroupItems::items,[&](const minsky::Items&,minsky::Items::const_iterator i) { @@ -630,6 +639,14 @@ namespace schema3 if (newItem->variableCast()) schema3VarMap[i.id]=i; } + + if (inVariables) + for (auto i: *inVariables) + g.inVariables.push_back(itemMap[i]); + if (outVariables) + for (auto i: *outVariables) + g.outVariables.push_back(itemMap[i]); + // second loop over items to wire up integrals, and populate Godley table variables for (const auto& i: items) { diff --git a/schema/schema3.h b/schema/schema3.h index 31820f79a..98f0830ed 100644 --- a/schema/schema3.h +++ b/schema/schema3.h @@ -245,6 +245,7 @@ namespace schema3 std::string minskyVersion="unknown"; vector wires; vector items; + Optional> inVariables, outVariables; vector groups; vector lockGroups; minsky::Simulation rungeKutta; diff --git a/test/testModel.cc b/test/testModel.cc index 7dd3aaffb..67182acbc 100644 --- a/test/testModel.cc +++ b/test/testModel.cc @@ -1716,6 +1716,25 @@ SUITE(GodleyTableWindow) } - + TEST_FIXTURE(TestFixture, saveAsGroup) + { + group0->inVariables.push_back(a); + group0->makeSubroutine(); + save("foo.mky"); + CHECK(group0->inVariables.size()); + CHECK(group0->outVariables.size()); + saveGroupAsFile(*group0,"group0.mky"); + insertGroupFromFile("group0.mky"); + Group& newGroup=dynamic_cast(*canvas.itemFocus); + // check I/O variables + CHECK_EQUAL(group0->inVariables.size(),newGroup.inVariables.size()); + CHECK_EQUAL(group0->outVariables.size(),newGroup.outVariables.size()); + for (int i=0; iinVariables.size(); ++i) + CHECK_EQUAL(group0->inVariables[i]->name(), newGroup.inVariables[i]->name()); + for (int i=0; ioutVariables.size(); ++i) + CHECK_EQUAL(group0->outVariables[i]->name(), newGroup.outVariables[i]->name()); + // check items + CHECK_EQUAL(group0->items.size(), newGroup.items.size()); + } }