1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#include "utils/actions.hpp"
#include "common/test.hpp"
using namespace polybar;
using namespace actions_util;
template <typename T1, typename T2, typename T3>
using triple = std::tuple<T1, T2, T3>;
class GetActionStringTest : public ::testing::TestWithParam<pair<triple<string, string, string>, string>> {};
vector<pair<triple<string, string, string>, string>> get_action_string_list = {
{{"foo", "bar", ""}, "#foo.bar"},
{{"foo", "bar", "data"}, "#foo.bar.data"},
{{"foo", "bar", "data.data2"}, "#foo.bar.data.data2"},
{{"a", "b", "c"}, "#a.b.c"},
{{"a", "b", ""}, "#a.b"},
};
TEST_P(GetActionStringTest, correctness) {
auto action = GetParam().first;
auto exp = GetParam().second;
auto res = get_action_string(std::get<0>(action), std::get<1>(action), std::get<2>(action));
EXPECT_EQ(res, exp);
}
INSTANTIATE_TEST_SUITE_P(Inst, GetActionStringTest, ::testing::ValuesIn(get_action_string_list));
class ParseActionStringTest : public ::testing::TestWithParam<pair<string, triple<string, string, string>>> {};
vector<pair<string, triple<string, string, string>>> parse_action_string_list = {
{"#foo.bar", {"foo", "bar", ""}},
{"#foo.bar.", {"foo", "bar", ""}},
{"#foo.bar.data", {"foo", "bar", "data"}},
{"#foo.bar.data.data2", {"foo", "bar", "data.data2"}},
{"#a.b.c", {"a", "b", "c"}},
{"#a.b.", {"a", "b", ""}},
{"#a.b", {"a", "b", ""}},
};
TEST_P(ParseActionStringTest, correctness) {
auto action_string = GetParam().first;
auto exp = GetParam().second;
auto res = parse_action_string(action_string);
EXPECT_EQ(res, exp);
}
INSTANTIATE_TEST_SUITE_P(Inst, ParseActionStringTest, ::testing::ValuesIn(parse_action_string_list));
class ParseActionStringThrowTest : public ::testing::TestWithParam<string> {};
vector<string> parse_action_string_throw_list = {
"#",
"#.",
"#..",
"#handler..",
"#.action.",
"#.action.data",
"#..data",
"#.data",
};
INSTANTIATE_TEST_SUITE_P(Inst, ParseActionStringThrowTest, ::testing::ValuesIn(parse_action_string_throw_list));
TEST_P(ParseActionStringThrowTest, correctness) {
EXPECT_THROW(parse_action_string(GetParam()), std::runtime_error);
}
|