Commit 9f4cc234 authored by GILLES Sebastien's avatar GILLES Sebastien

#1468 The case without sections at all work. However several other test cases...

#1468 The case without sections at all work. However several other test cases fail; I have to keep robustifying it (all the problematic cases will of course be added to the test suite).
parent e2087a7a
......@@ -249,20 +249,20 @@ BOOST_FIXTURE_TEST_CASE(map_in_vector, TestNS::FixtureNS::Environment)
}
//BOOST_FIXTURE_TEST_CASE(no_section, TestNS::FixtureNS::Environment)
//{
// decltype(auto) environment = Utilities::Environment::CreateOrGetInstance(__FILE__, __LINE__);
//
// decltype(auto) input_file =
// environment.SubstituteValues("${MOREFEM_ROOT}/Sources/Test/Utilities/LuaOptionFile/no_section.lua");
//
// LuaOptionFile lua(input_file, __FILE__, __LINE__);
//
// std::ostringstream oconv;
// Utilities::PrintContainer<>::Do(lua.GetEntryKeyList(), oconv, ", ", "[", "]");
//
// BOOST_CHECK_EQUAL(oconv.str(),
// "[a, b, c, d, e, f]");
//}
BOOST_FIXTURE_TEST_CASE(no_section, TestNS::FixtureNS::Environment)
{
decltype(auto) environment = Utilities::Environment::CreateOrGetInstance(__FILE__, __LINE__);
decltype(auto) input_file =
environment.SubstituteValues("${MOREFEM_ROOT}/Sources/Test/Utilities/LuaOptionFile/no_section.lua");
LuaOptionFile lua(input_file, __FILE__, __LINE__);
std::ostringstream oconv;
Utilities::PrintContainer<>::Do(lua.GetEntryKeyList(), oconv, ", ", "[", "]");
BOOST_CHECK_EQUAL(oconv.str(),
"[a, b, c, d, e, f]");
}
PRAGMA_DIAGNOSTIC(pop)
......@@ -91,7 +91,11 @@ namespace MoReFEM
//! Extract the names of the data and the section (not knowing yet which is which).
void ComputeEntryOrSectionNames();
void Stuff();
//! Pair braces together (identify which close the block opened by another).
std::vector<std::pair<std::size_t, std::size_t>> PairBraces();
//! Identify the sections (so far we had a list of names which might have been sections or entries).
void IdentifySections(const std::vector<std::pair<std::size_t, std::size_t>>& pair_braces_list);
private:
......@@ -110,12 +114,10 @@ namespace MoReFEM
std::vector<EntryOrSection> entry_or_section_list_;
std::vector<Section> section_list_;
};
} // namespace anonymous
......@@ -201,8 +203,9 @@ namespace MoReFEM
ComputeEntryOrSectionNames();
Stuff();
auto pair_list = PairBraces();
IdentifySections(pair_list);
}
......@@ -299,13 +302,6 @@ namespace MoReFEM
while (!std::isalnum(content_[pos]) && pos > 0)
--pos;
if (pos == 0)
{
std::ostringstream oconv;
oconv << "Unable to find name before the first equal sign in file " << file_;
throw Exception(oconv.str(), __FILE__, __LINE__);
}
bool letter_already_read = false;
while (std::isalnum(content_[pos]) && pos > 0)
{
......@@ -338,11 +334,9 @@ namespace MoReFEM
}
void ExtractKeysFromFile::Stuff()
{
std::vector<std::pair<std::size_t, std::size_t>> ExtractKeysFromFile::PairBraces()
{
if (!brace_position_list_.empty()) // the emptiness case might happen for VERY simple cases...
{
if (brace_position_list_.front() < 0)
......@@ -365,7 +359,7 @@ namespace MoReFEM
// Pair the braces together.
std::vector<std::pair<int, int>> pair_list;
std::vector<std::pair<std::size_t, std::size_t>> pair_list;
auto copy = brace_position_list_;
......@@ -389,23 +383,25 @@ namespace MoReFEM
assert(it != copy.cend());
assert(it != copy.cbegin());
pair_list.push_back(std::make_pair(*(it - 1), - *it));
pair_list.emplace_back(std::make_pair(static_cast<std::size_t>(*(it - 1)),
static_cast<std::size_t>(- *it)));
copy.erase(it);
--it;
copy.erase(it);
}
for (const auto& pair : pair_list)
Utilities::PrintTuple(pair);
// Filter out the braces without values inside: they were Lua vectors and not sections.
std::vector<std::pair<int, int>> filtered_pair_list;
return pair_list;
}
void ExtractKeysFromFile
::IdentifySections(const std::vector<std::pair<std::size_t, std::size_t>>& pair_braces_list)
{
std::vector<std::pair<std::size_t, std::size_t>> filtered_pair_list;
assert (entry_or_section_list_.size() >= pair_braces_list.size());
for (const auto& pair : pair_list)
for (const auto& pair : pair_braces_list)
{
const auto opening = pair.first;
const auto closing = pair.second;
......@@ -418,34 +414,11 @@ namespace MoReFEM
break;
}
}
}
std::cout << "After filtering (i.e. the sections!): " << std::endl;
for (const auto& pair : filtered_pair_list)
Utilities::PrintTuple(pair);
// There should be as many pair as there are names
assert (entry_or_section_list_.size() >= pair_list.size());
// Each brace pair is associated to the closer equal before it.
const auto Npair = filtered_pair_list.size();
for (const auto& foo : entry_or_section_list_)
{
std::cout << "Name " << foo.name << " found relared to equal " << foo.equal_position << std::endl;
}
for (auto i = 0ul; i < Npair; ++i)
{
const auto opening_brace = filtered_pair_list[i].first;
......@@ -462,7 +435,7 @@ namespace MoReFEM
if (it->equal_position < opening_brace)
break;
}
std::cout << it->name << "\n";
assert(it != end);
Section section;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment