clang-format: update c/cc coding style
Update all cc code using .clang-format; please do so as well for future PRs etc.; emacs has a handy 'clang-format' mode to make this automatic. For comparing old changes with git blame, we can disregard this one using --ignore-rev (see https://www.moxio.com/blog/43/ignoring-bulk-change-commits-with-git-blame )
This commit is contained in:
@ -31,120 +31,118 @@ using namespace Mu;
|
||||
static void
|
||||
test_param_getters()
|
||||
{
|
||||
const auto sexp { Sexp::make_parse(R"((foo :bar 123 :cuux "456" :boo nil :bah true))")};
|
||||
const auto sexp{Sexp::make_parse(R"((foo :bar 123 :cuux "456" :boo nil :bah true))")};
|
||||
|
||||
if (g_test_verbose())
|
||||
std::cout << sexp << "\n";
|
||||
if (g_test_verbose())
|
||||
std::cout << sexp << "\n";
|
||||
|
||||
g_assert_cmpint(Command::get_int_or(sexp.list(), ":bar"), ==, 123);
|
||||
assert_equal(Command::get_string_or(sexp.list(), ":bra", "bla"), "bla");
|
||||
assert_equal(Command::get_string_or(sexp.list(), ":cuux"), "456");
|
||||
g_assert_cmpint(Command::get_int_or(sexp.list(), ":bar"), ==, 123);
|
||||
assert_equal(Command::get_string_or(sexp.list(), ":bra", "bla"), "bla");
|
||||
assert_equal(Command::get_string_or(sexp.list(), ":cuux"), "456");
|
||||
|
||||
g_assert_true(Command::get_bool_or(sexp.list(),":boo") == false);
|
||||
g_assert_true(Command::get_bool_or(sexp.list(),":bah") == true);
|
||||
g_assert_true(Command::get_bool_or(sexp.list(), ":boo") == false);
|
||||
g_assert_true(Command::get_bool_or(sexp.list(), ":bah") == true);
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
call (const Command::CommandMap& cmap, const std::string& str) try
|
||||
{
|
||||
const auto sexp{Sexp::make_parse(str)};
|
||||
invoke (cmap, sexp);
|
||||
call(const Command::CommandMap& cmap, const std::string& str)
|
||||
try {
|
||||
const auto sexp{Sexp::make_parse(str)};
|
||||
invoke(cmap, sexp);
|
||||
|
||||
return true;
|
||||
return true;
|
||||
|
||||
} catch (const Error& err) {
|
||||
g_warning ("%s", err.what());
|
||||
return false;
|
||||
g_warning("%s", err.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
static void
|
||||
test_command()
|
||||
{
|
||||
using namespace Command;
|
||||
allow_warnings();
|
||||
using namespace Command;
|
||||
allow_warnings();
|
||||
|
||||
CommandMap cmap;
|
||||
CommandMap cmap;
|
||||
|
||||
cmap.emplace("my-command",
|
||||
CommandInfo{
|
||||
ArgMap{ {":param1", ArgInfo{Sexp::Type::String, true, "some string" }},
|
||||
{":param2", ArgInfo{Sexp::Type::Number, false, "some integer"}}},
|
||||
"My command,",
|
||||
{}});
|
||||
cmap.emplace(
|
||||
"my-command",
|
||||
CommandInfo{ArgMap{{":param1", ArgInfo{Sexp::Type::String, true, "some string"}},
|
||||
{":param2", ArgInfo{Sexp::Type::Number, false, "some integer"}}},
|
||||
"My command,",
|
||||
{}});
|
||||
|
||||
g_assert_true(call(cmap, "(my-command :param1 \"hello\")"));
|
||||
g_assert_true(call(cmap, "(my-command :param1 \"hello\" :param2 123)"));
|
||||
g_assert_true(call(cmap, "(my-command :param1 \"hello\")"));
|
||||
g_assert_true(call(cmap, "(my-command :param1 \"hello\" :param2 123)"));
|
||||
|
||||
g_assert_false(call(cmap, "(my-command :param1 \"hello\" :param2 123 :param3 xxx)"));
|
||||
g_assert_false(call(cmap, "(my-command :param1 \"hello\" :param2 123 :param3 xxx)"));
|
||||
}
|
||||
|
||||
static void
|
||||
test_command2()
|
||||
{
|
||||
using namespace Command;
|
||||
allow_warnings();
|
||||
using namespace Command;
|
||||
allow_warnings();
|
||||
|
||||
CommandMap cmap;
|
||||
cmap.emplace("bla",
|
||||
CommandInfo{
|
||||
ArgMap{
|
||||
{":foo", ArgInfo{Sexp::Type::Number, false, "foo"}},
|
||||
{":bar", ArgInfo{Sexp::Type::String, false, "bar"}},
|
||||
},"yeah",
|
||||
[&](const auto& params){}});
|
||||
CommandMap cmap;
|
||||
cmap.emplace("bla",
|
||||
CommandInfo{ArgMap{
|
||||
{":foo", ArgInfo{Sexp::Type::Number, false, "foo"}},
|
||||
{":bar", ArgInfo{Sexp::Type::String, false, "bar"}},
|
||||
},
|
||||
"yeah",
|
||||
[&](const auto& params) {}});
|
||||
|
||||
|
||||
g_assert_true (call(cmap, "(bla :foo nil)"));
|
||||
g_assert_false (call(cmap, "(bla :foo nil :bla nil)"));
|
||||
g_assert_true(call(cmap, "(bla :foo nil)"));
|
||||
g_assert_false(call(cmap, "(bla :foo nil :bla nil)"));
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
test_command_fail()
|
||||
{
|
||||
using namespace Command;
|
||||
using namespace Command;
|
||||
|
||||
allow_warnings();
|
||||
allow_warnings();
|
||||
|
||||
CommandMap cmap;
|
||||
CommandMap cmap;
|
||||
|
||||
cmap.emplace("my-command",
|
||||
CommandInfo{
|
||||
ArgMap{ {":param1", ArgInfo{Sexp::Type::String, true, "some string" }},
|
||||
{":param2", ArgInfo{Sexp::Type::Number, false, "some integer"}}},
|
||||
"My command,",
|
||||
{}});
|
||||
cmap.emplace(
|
||||
"my-command",
|
||||
CommandInfo{ArgMap{{":param1", ArgInfo{Sexp::Type::String, true, "some string"}},
|
||||
{":param2", ArgInfo{Sexp::Type::Number, false, "some integer"}}},
|
||||
"My command,",
|
||||
{}});
|
||||
|
||||
g_assert_false (call(cmap, "(my-command)"));
|
||||
g_assert_false (call(cmap, "(my-command2)"));
|
||||
g_assert_false(call(cmap, "(my-command :param1 123 :param2 123)"));
|
||||
g_assert_false(call(cmap, "(my-command :param1 \"hello\" :param2 \"123\")"));
|
||||
g_assert_false(call(cmap, "(my-command)"));
|
||||
g_assert_false(call(cmap, "(my-command2)"));
|
||||
g_assert_false(call(cmap, "(my-command :param1 123 :param2 123)"));
|
||||
g_assert_false(call(cmap, "(my-command :param1 \"hello\" :param2 \"123\")"));
|
||||
}
|
||||
|
||||
|
||||
static void black_hole() {}
|
||||
static void
|
||||
black_hole()
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[]) try
|
||||
{
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
main(int argc, char* argv[])
|
||||
try {
|
||||
g_test_init(&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func ("/utils/command-parser/param-getters", test_param_getters);
|
||||
g_test_add_func ("/utils/command-parser/command", test_command);
|
||||
g_test_add_func ("/utils/command-parser/command2", test_command2);
|
||||
g_test_add_func ("/utils/command-parser/command-fail", test_command_fail);
|
||||
g_test_add_func("/utils/command-parser/param-getters", test_param_getters);
|
||||
g_test_add_func("/utils/command-parser/command", test_command);
|
||||
g_test_add_func("/utils/command-parser/command2", test_command2);
|
||||
g_test_add_func("/utils/command-parser/command-fail", test_command_fail);
|
||||
|
||||
g_log_set_handler (NULL,
|
||||
(GLogLevelFlags)(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL|
|
||||
G_LOG_FLAG_RECURSION),
|
||||
(GLogFunc)black_hole, NULL);
|
||||
|
||||
|
||||
return g_test_run ();
|
||||
g_log_set_handler(
|
||||
NULL,
|
||||
(GLogLevelFlags)(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION),
|
||||
(GLogFunc)black_hole,
|
||||
NULL);
|
||||
|
||||
return g_test_run();
|
||||
|
||||
} catch (const std::runtime_error& re) {
|
||||
std::cerr << re.what() << "\n";
|
||||
return 1;
|
||||
std::cerr << re.what() << "\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user