diff --git a/src/preprocessor.h b/src/preprocessor.h index 0fdbffb17..26e1d29a9 100644 --- a/src/preprocessor.h +++ b/src/preprocessor.h @@ -126,8 +126,16 @@ private: static std::string getdef(std::string line, bool def); +public: + /** + * Evaluate condition 'numerically' + * @param cfg configuration + * @param def condition + * @return result when evaluating the condition + */ static bool match_cfg_def(std::string cfg, std::string def); +private: /** * Search includes from code and append code from the included * file diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 3cd67f77b..fb24ae1e7 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -86,6 +86,9 @@ private: TEST_CASE(elif); + // Test the Preprocessor::match_cfg_def + TEST_CASE(match_cfg_def); + TEST_CASE(if_cond1); TEST_CASE(if_cond2); TEST_CASE(if_cond3); @@ -518,6 +521,14 @@ private: + void match_cfg_def() + { + TODO_ASSERT_EQUALS(true, Preprocessor::match_cfg_def("A=1", "A==1")); + TODO_ASSERT_EQUALS(true, Preprocessor::match_cfg_def("A=1", "A<2")); + ASSERT_EQUALS(false, Preprocessor::match_cfg_def("A=1", "A==2")); + ASSERT_EQUALS(false, Preprocessor::match_cfg_def("A=1", "A<1")); + } + void if_cond1() {