test(parser): Add tests for parse_action_cmd

This commit is contained in:
patrick96 2018-10-10 17:03:51 +02:00 committed by NBonaparte
parent 18e2609f11
commit 38f551f884
3 changed files with 51 additions and 0 deletions

View File

@ -232,6 +232,11 @@ mousebtn parser::parse_action_btn(const string& data) {
/**
* Process action command string
*
* data is the action cmd surrounded by unescaped colons followed by an
* arbitrary string
*
* Returns everything inside the unescaped colons as is
*/
string parser::parse_action_cmd(string&& data) {
if (data[0] != ':') {

View File

@ -100,5 +100,14 @@ unit_test(components/builder unit_tests
SOURCES
${files})
unit_test(components/parser unit_tests
SOURCES
components/parser.cpp
utils/factory.cpp
utils/string.cpp
events/signal_emitter.cpp
events/signal_receiver.cpp
)
# Compile all unit tests with 'make all_unit_tests'
add_custom_target("all_unit_tests" DEPENDS ${unit_tests})

View File

@ -0,0 +1,37 @@
#include "common/test.hpp"
#include "events/signal_emitter.hpp"
#include "components/parser.hpp"
using namespace polybar;
class TestableParser : public parser {
using parser::parser;
public: using parser::parse_action_cmd;
};
class Parser : public ::testing::Test {
protected:
TestableParser m_parser{signal_emitter::make()};
};
/**
* The first element of the pair is the expected return text, the second element
* is the input to parse_action_cmd
*/
class ParseActionCmd :
public Parser,
public ::testing::WithParamInterface<pair<string, string>> {};
vector<pair<string, string>> parse_action_cmd_list = {
{"abc", ":abc:\\abc"},
{"abc\\:", ":abc\\::\\abc"},
{"\\:\\:\\:", ":\\:\\:\\::\\abc"},
};
INSTANTIATE_TEST_CASE_P(Inst, ParseActionCmd,
::testing::ValuesIn(parse_action_cmd_list),);
TEST_P(ParseActionCmd, correctness) {
auto input = GetParam().second;
auto result = m_parser.parse_action_cmd(std::move(input));
EXPECT_EQ(GetParam().first, result);
}