mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-21 05:43:37 +00:00
Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run: git remote add om-historic [om-historic.git repo url] git fetch --tags om-historic git replace squashed-history historic-commits
This commit is contained in:
177
indexer/indexer_tests/drules_selector_parser_test.cpp
Normal file
177
indexer/indexer_tests/drules_selector_parser_test.cpp
Normal file
@@ -0,0 +1,177 @@
|
||||
#include "testing/testing.hpp"
|
||||
|
||||
#include "indexer/drules_selector.hpp"
|
||||
#include "indexer/drules_selector_parser.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace drules_selector_parser_test
|
||||
{
|
||||
using namespace drule;
|
||||
using namespace std;
|
||||
|
||||
UNIT_TEST(TestDruleSelectorIsSet)
|
||||
{
|
||||
SelectorExpression e;
|
||||
TEST(ParseSelector("name", e), ());
|
||||
|
||||
TEST_EQUAL("name", e.m_tag, ());
|
||||
TEST_EQUAL("", e.m_value, ());
|
||||
TEST_EQUAL(SelectorOperatorIsSet, e.m_operator, ());
|
||||
}
|
||||
|
||||
UNIT_TEST(TestDruleSelectorIsSet2)
|
||||
{
|
||||
SelectorExpression e;
|
||||
TEST(ParseSelector("bbox_area", e), ());
|
||||
|
||||
TEST_EQUAL("bbox_area", e.m_tag, ());
|
||||
TEST_EQUAL("", e.m_value, ());
|
||||
TEST_EQUAL(SelectorOperatorIsSet, e.m_operator, ());
|
||||
}
|
||||
|
||||
UNIT_TEST(TestDruleSelectorIsNotSet)
|
||||
{
|
||||
SelectorExpression e;
|
||||
TEST(ParseSelector("!name", e), ());
|
||||
|
||||
TEST_EQUAL("name", e.m_tag, ());
|
||||
TEST_EQUAL("", e.m_value, ());
|
||||
TEST_EQUAL(SelectorOperatorIsNotSet, e.m_operator, ());
|
||||
}
|
||||
|
||||
UNIT_TEST(TestDruleSelectorIsNotSet2)
|
||||
{
|
||||
SelectorExpression e;
|
||||
TEST(ParseSelector("!bbox_area", e), ());
|
||||
|
||||
TEST_EQUAL("bbox_area", e.m_tag, ());
|
||||
TEST_EQUAL("", e.m_value, ());
|
||||
TEST_EQUAL(SelectorOperatorIsNotSet, e.m_operator, ());
|
||||
}
|
||||
|
||||
UNIT_TEST(TestDruleSelectorEqual)
|
||||
{
|
||||
SelectorExpression e;
|
||||
TEST(ParseSelector("population=1000", e), ());
|
||||
|
||||
TEST_EQUAL("population", e.m_tag, ());
|
||||
TEST_EQUAL("1000", e.m_value, ());
|
||||
TEST_EQUAL(SelectorOperatorEqual, e.m_operator, ());
|
||||
}
|
||||
|
||||
UNIT_TEST(TestDruleSelectorNotEqual)
|
||||
{
|
||||
SelectorExpression e;
|
||||
TEST(ParseSelector("population!=1000", e), ());
|
||||
|
||||
TEST_EQUAL("population", e.m_tag, ());
|
||||
TEST_EQUAL("1000", e.m_value, ());
|
||||
TEST_EQUAL(SelectorOperatorNotEqual, e.m_operator, ());
|
||||
}
|
||||
|
||||
UNIT_TEST(TestDruleSelectorLess)
|
||||
{
|
||||
SelectorExpression e;
|
||||
TEST(ParseSelector("population<1000", e), ());
|
||||
|
||||
TEST_EQUAL("population", e.m_tag, ());
|
||||
TEST_EQUAL("1000", e.m_value, ());
|
||||
TEST_EQUAL(SelectorOperatorLess, e.m_operator, ());
|
||||
}
|
||||
|
||||
UNIT_TEST(TestDruleSelectorLess2)
|
||||
{
|
||||
SelectorExpression e;
|
||||
TEST(ParseSelector("bbox_area<1000", e), ());
|
||||
|
||||
TEST_EQUAL("bbox_area", e.m_tag, ());
|
||||
TEST_EQUAL("1000", e.m_value, ());
|
||||
TEST_EQUAL(SelectorOperatorLess, e.m_operator, ());
|
||||
}
|
||||
|
||||
UNIT_TEST(TestDruleSelectorGreater)
|
||||
{
|
||||
SelectorExpression e;
|
||||
TEST(ParseSelector("population>1000", e), ());
|
||||
|
||||
TEST_EQUAL("population", e.m_tag, ());
|
||||
TEST_EQUAL("1000", e.m_value, ());
|
||||
TEST_EQUAL(SelectorOperatorGreater, e.m_operator, ());
|
||||
}
|
||||
|
||||
UNIT_TEST(TestDruleSelectorGreater2)
|
||||
{
|
||||
SelectorExpression e;
|
||||
TEST(ParseSelector("bbox_area>1000", e), ());
|
||||
|
||||
TEST_EQUAL("bbox_area", e.m_tag, ());
|
||||
TEST_EQUAL("1000", e.m_value, ());
|
||||
TEST_EQUAL(SelectorOperatorGreater, e.m_operator, ());
|
||||
}
|
||||
|
||||
UNIT_TEST(TestDruleSelectorLessOrEqual)
|
||||
{
|
||||
SelectorExpression e;
|
||||
TEST(ParseSelector("population<=1000", e), ());
|
||||
|
||||
TEST_EQUAL("population", e.m_tag, ());
|
||||
TEST_EQUAL("1000", e.m_value, ());
|
||||
TEST_EQUAL(SelectorOperatorLessOrEqual, e.m_operator, ());
|
||||
}
|
||||
|
||||
UNIT_TEST(TestDruleSelectorGreaterOrEqual)
|
||||
{
|
||||
SelectorExpression e;
|
||||
TEST(ParseSelector("population>=1000", e), ());
|
||||
|
||||
TEST_EQUAL("population", e.m_tag, ());
|
||||
TEST_EQUAL("1000", e.m_value, ());
|
||||
TEST_EQUAL(SelectorOperatorGreaterOrEqual, e.m_operator, ());
|
||||
}
|
||||
|
||||
UNIT_TEST(TestDruleSelectorInvalid)
|
||||
{
|
||||
char const * const badFormats[] =
|
||||
{
|
||||
"",
|
||||
"=badformat",
|
||||
"!=badformat",
|
||||
">badformat",
|
||||
"<badformat",
|
||||
">=badformat",
|
||||
"<=badformat",
|
||||
"bad$name",
|
||||
"!bad$name",
|
||||
"bad$name=1000",
|
||||
};
|
||||
|
||||
for (auto e : badFormats)
|
||||
{
|
||||
SelectorExpression expr;
|
||||
TEST_EQUAL(false, ParseSelector(e, expr), ("string is", e));
|
||||
}
|
||||
}
|
||||
|
||||
UNIT_TEST(PopulationSelector_Smoke)
|
||||
{
|
||||
TEST(ParseSelector("population<1000"), ());
|
||||
TEST(ParseSelector(vector<string>({"population>1000"})), ());
|
||||
TEST(ParseSelector(vector<string>({"population>=1000","population<=1000000"})), ());
|
||||
}
|
||||
|
||||
UNIT_TEST(NameSelector_Smoke)
|
||||
{
|
||||
TEST(ParseSelector("name"), ());
|
||||
TEST(ParseSelector("!name"), ());
|
||||
}
|
||||
|
||||
UNIT_TEST(InvalidSelector_Smoke)
|
||||
{
|
||||
TEST(!ParseSelector(""), ());
|
||||
TEST(!ParseSelector(vector<string>({""})), ());
|
||||
TEST(!ParseSelector(vector<string>({"population>=1000","population<=1000000", ""})), ());
|
||||
}
|
||||
|
||||
} // namespace drules_selector_parser_test
|
||||
Reference in New Issue
Block a user