Add location_dependent_data unit tests

This commit is contained in:
Michael Krasnyk
2017-08-30 22:11:26 +02:00
parent 4eac861eae
commit b15288e0ea
5 changed files with 186 additions and 37 deletions
+34 -2
View File
@@ -978,6 +978,31 @@ void LuaScriptingContext::ProcessNode(const osmium::Node &node,
}
}
namespace
{
// boost::variant visitor that inserts a key-value pair in a Lua table
struct table_setter : public boost::static_visitor<>
{
table_setter(sol::table &table, const std::string &key) : table(table), key(key) {}
template <typename T> void operator()(const T &value) const { table.set(key, value); }
void operator()(const boost::blank &) const { /* ignore */}
sol::table &table;
const std::string &key;
};
// Converts a properties map into a Lua table
sol::table toLua(sol::state &state, const LocationDependentData::properties_t properties)
{
auto table = sol::table(state, sol::create);
std::for_each(properties.begin(), properties.end(), [&table](const auto &property) {
boost::apply_visitor(table_setter(table, property.first), property.second);
});
return table;
}
}
void LuaScriptingContext::ProcessWay(const osmium::Way &way,
ExtractionWay &result,
const ExtractionRelationContainer::RelationList &relations)
@@ -987,10 +1012,17 @@ void LuaScriptingContext::ProcessWay(const osmium::Way &way,
switch (api_version)
{
case 3:
way_function(profile_table, way, result, relations);
if (location_dependent_data.empty())
{
way_function(profile_table, way, result, relations);
}
else
{
way_function(profile_table, way, result, relations, toLua(state, location_dependent_data(way)));
}
break;
case 2:
way_function(profile_table, way, result, location_dependent_data(state, way));
way_function(profile_table, way, result);
break;
case 1:
case 0: