mirror of
https://github.com/polybar/polybar.git
synced 2024-11-25 13:55:47 -05:00
test(parser): Add tests for parse_action_cmd
This commit is contained in:
parent
18e2609f11
commit
38f551f884
3 changed files with 51 additions and 0 deletions
|
@ -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] != ':') {
|
||||
|
|
|
@ -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})
|
||||
|
|
37
tests/unit_tests/components/parser.cpp
Normal file
37
tests/unit_tests/components/parser.cpp
Normal 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);
|
||||
}
|
Loading…
Reference in a new issue