From e145aae8b6b2dfa321caf303b9976fc68f9b405a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Musia=C5=82?= <111433005+SpectraL519@users.noreply.github.com> Date: Mon, 8 Apr 2024 19:42:47 +0200 Subject: [PATCH] format --- include/ap/argument_parser.hpp | 18 +++++----- test/source/test_argument_name.cpp | 34 +++++++++++-------- .../test_argument_parser_add_argument.cpp | 16 ++++++--- .../test_argument_parser_parse_args.cpp | 7 ---- test/source/test_optional_argument.cpp | 4 +-- test/source/test_positional_argument.cpp | 4 +-- 6 files changed, 46 insertions(+), 37 deletions(-) diff --git a/include/ap/argument_parser.hpp b/include/ap/argument_parser.hpp index 380c3f5..7db0663 100644 --- a/include/ap/argument_parser.hpp +++ b/include/ap/argument_parser.hpp @@ -1202,7 +1202,8 @@ class argument_parser { * @param arg_discriminator_list Vector of default optional argument categories. * @return Reference to the argument parser. */ - argument_parser& default_optional_arguments(const std::vector& arg_discriminator_list) noexcept { + argument_parser& default_optional_arguments(const std::vector& arg_discriminator_list + ) noexcept { for (const auto arg_discriminator : arg_discriminator_list) this->_add_default_optional_argument(arg_discriminator); return *this; @@ -1218,7 +1219,7 @@ class argument_parser { argument::positional_argument& add_positional_argument(std::string_view primary_name) { // TODO: check forbidden characters - const argument::detail::argument_name arg_name = {primary_name}; + const argument::detail::argument_name arg_name = { primary_name }; if (this->_is_arg_name_used(arg_name)) throw error::argument_name_used_error(arg_name); @@ -1237,7 +1238,7 @@ class argument_parser { argument::positional_argument& add_positional_argument(std::string_view primary_name, std::string_view secondary_name) { // TODO: check forbidden characters - const argument::detail::argument_name arg_name = {primary_name, secondary_name}; + const argument::detail::argument_name arg_name = { primary_name, secondary_name }; if (this->_is_arg_name_used(arg_name)) throw error::argument_name_used_error(arg_name); @@ -1255,7 +1256,7 @@ class argument_parser { argument::optional_argument& add_optional_argument(std::string_view primary_name) { // TODO: check forbidden characters - const argument::detail::argument_name arg_name = {primary_name}; + const argument::detail::argument_name arg_name = { primary_name }; if (this->_is_arg_name_used(arg_name)) throw error::argument_name_used_error(arg_name); @@ -1274,7 +1275,7 @@ class argument_parser { argument::optional_argument& add_optional_argument(std::string_view primary_name, std::string_view secondary_name) { // TODO: check forbidden characters - const argument::detail::argument_name arg_name = {primary_name, secondary_name}; + const argument::detail::argument_name arg_name = { primary_name, secondary_name }; if (this->_is_arg_name_used(arg_name)) throw error::argument_name_used_error(arg_name); @@ -1539,7 +1540,8 @@ class argument_parser { * @param arg_name The name of the argument. * @return Argument predicate based on the provided name. */ - [[nodiscard]] argument_predicate_type _name_match_predicate(const argument::detail::argument_name& arg_name) const noexcept { + [[nodiscard]] argument_predicate_type _name_match_predicate(const argument::detail::argument_name& arg_name + ) const noexcept { return [&arg_name](const argument_ptr_type& arg) { return arg->name().match(arg_name); }; } @@ -1594,10 +1596,10 @@ class argument_parser { */ [[nodiscard]] bool _is_flag(const std::string& arg) const noexcept { if (arg.starts_with(this->_flag_prefix)) - return this->_is_arg_name_used({arg.substr(this->_flag_prefix_length)}); + return this->_is_arg_name_used({ arg.substr(this->_flag_prefix_length) }); if (arg.starts_with(this->_flag_prefix_char)) - return this->_is_arg_name_used({arg.substr(this->_flag_prefix_char_length)}); + return this->_is_arg_name_used({ arg.substr(this->_flag_prefix_char_length) }); return false; } diff --git a/test/source/test_argument_name.cpp b/test/source/test_argument_name.cpp index 151b56a..570b288 100644 --- a/test/source/test_argument_name.cpp +++ b/test/source/test_argument_name.cpp @@ -47,14 +47,16 @@ TEST_CASE("argument_name members should be correctly " REQUIRE_EQ(arg_name.secondary.value(), secondary_name); } -TEST_CASE("argument_name::operator==(argument_name) should return false if primary names are not equal") { +TEST_CASE("argument_name::operator==(argument_name) should return false if primary names are not " + "equal") { const auto arg_name_a = default_argument_name_primary(); - const auto arg_name_b = argument_name{other_primary_name}; + const auto arg_name_b = argument_name{ other_primary_name }; REQUIRE_NE(arg_name_a, arg_name_b); } -TEST_CASE("argument_name::operator==(argument_name) should return false if only one argument has both primary and secondary values") { +TEST_CASE("argument_name::operator==(argument_name) should return false if only one argument has " + "both primary and secondary values") { const auto arg_name_a = default_argument_name_primary(); const auto arg_name_b = default_argument_name_primary_and_secondary(); @@ -62,7 +64,8 @@ TEST_CASE("argument_name::operator==(argument_name) should return false if only REQUIRE_NE(arg_name_b, arg_name_a); } -TEST_CASE("argument_name::match(string_view) should return true if the given string matches at least one name") { +TEST_CASE("argument_name::match(string_view) should return true if the given string matches at " + "least one name") { SUBCASE("argument_name with primary name only") { const auto arg_name = default_argument_name_primary(); @@ -77,7 +80,8 @@ TEST_CASE("argument_name::match(string_view) should return true if the given str } } -TEST_CASE("argument_name::match(string_view) should return false if the given string dosn't match any name") { +TEST_CASE("argument_name::match(string_view) should return false if the given string dosn't match " + "any name") { SUBCASE("argument_name with primary name only") { const auto arg_name = default_argument_name_primary(); @@ -93,18 +97,19 @@ TEST_CASE("argument_name::match(string_view) should return false if the given st } } -TEST_CASE("argument_name::match(argument_name) should return true if either the primary or the secondary name " +TEST_CASE("argument_name::match(argument_name) should return true if either the primary or the " + "secondary name " "of the passed argument_name matches at least one name") { SUBCASE("argument_name with primary name only") { const auto arg_name = default_argument_name_primary(); SUBCASE("matching primary to primary") { - const auto arg_name_to_match = argument_name{primary_name}; + const auto arg_name_to_match = argument_name{ primary_name }; REQUIRE(arg_name.match(arg_name_to_match)); } SUBCASE("matching secondary to primary") { - const auto arg_name_to_match = argument_name{other_primary_name, primary_name}; + const auto arg_name_to_match = argument_name{ other_primary_name, primary_name }; REQUIRE(arg_name.match(arg_name_to_match)); } } @@ -113,30 +118,31 @@ TEST_CASE("argument_name::match(argument_name) should return true if either the const auto arg_name = default_argument_name_primary_and_secondary(); SUBCASE("matching primary to primary") { - const auto arg_name_to_match = argument_name{primary_name, other_secondary_name}; + const auto arg_name_to_match = argument_name{ primary_name, other_secondary_name }; REQUIRE(arg_name.match(arg_name_to_match)); } SUBCASE("matching primary to secondary") { - const auto arg_name_to_match = argument_name{secondary_name, primary_name}; + const auto arg_name_to_match = argument_name{ secondary_name, primary_name }; REQUIRE(arg_name.match(arg_name_to_match)); } SUBCASE("matching secondary to primary") { - const auto arg_name_to_match = argument_name{other_primary_name, primary_name}; + const auto arg_name_to_match = argument_name{ other_primary_name, primary_name }; REQUIRE(arg_name.match(arg_name_to_match)); } SUBCASE("matching secondary to secondary") { - const auto arg_name_to_match = argument_name{other_primary_name, secondary_name}; + const auto arg_name_to_match = argument_name{ other_primary_name, secondary_name }; REQUIRE(arg_name.match(arg_name_to_match)); } } } -TEST_CASE("argument_name::match(argument_name) should return false if neither the primary nor the secondary name " +TEST_CASE("argument_name::match(argument_name) should return false if neither the primary nor the " + "secondary name " "of the passed argument_name matches at least one name") { - const auto arg_name_to_match = argument_name{other_primary_name, other_secondary_name}; + const auto arg_name_to_match = argument_name{ other_primary_name, other_secondary_name }; SUBCASE("argument_name with primary name only") { const auto arg_name = default_argument_name_primary(); diff --git a/test/source/test_argument_parser_add_argument.cpp b/test/source/test_argument_parser_add_argument.cpp index abdd033..6fd66ba 100644 --- a/test/source/test_argument_parser_add_argument.cpp +++ b/test/source/test_argument_parser_add_argument.cpp @@ -92,11 +92,15 @@ TEST_CASE_FIXTURE( } SUBCASE("adding argument with a previously used primary name") { - REQUIRE_THROWS_AS(sut.add_positional_argument(primary_name, other_secondary_name), ap::error::argument_name_used_error); + REQUIRE_THROWS_AS( + sut.add_positional_argument(primary_name, other_secondary_name), ap::error::argument_name_used_error + ); } SUBCASE("adding argument with a previously used secondary name") { - REQUIRE_THROWS_AS(sut.add_positional_argument(other_primary_name, secondary_name), ap::error::argument_name_used_error); + REQUIRE_THROWS_AS( + sut.add_positional_argument(other_primary_name, secondary_name), ap::error::argument_name_used_error + ); } } @@ -117,11 +121,15 @@ TEST_CASE_FIXTURE( } SUBCASE("adding argument with a previously used primary name") { - REQUIRE_THROWS_AS(sut.add_optional_argument(primary_name, other_secondary_name), ap::error::argument_name_used_error); + REQUIRE_THROWS_AS( + sut.add_optional_argument(primary_name, other_secondary_name), ap::error::argument_name_used_error + ); } SUBCASE("adding argument with a previously used secondary name") { - REQUIRE_THROWS_AS(sut.add_optional_argument(other_primary_name, secondary_name), ap::error::argument_name_used_error); + REQUIRE_THROWS_AS( + sut.add_optional_argument(other_primary_name, secondary_name), ap::error::argument_name_used_error + ); } } diff --git a/test/source/test_argument_parser_parse_args.cpp b/test/source/test_argument_parser_parse_args.cpp index c23ffa7..c8506ca 100644 --- a/test/source/test_argument_parser_parse_args.cpp +++ b/test/source/test_argument_parser_parse_args.cpp @@ -68,7 +68,6 @@ TEST_CASE_FIXTURE(argument_parser_test_fixture, "_preprocess_input should return free_argv(argc, argv); } - // _parse_args_impl TEST_CASE_FIXTURE( @@ -92,7 +91,6 @@ TEST_CASE_FIXTURE(argument_parser_test_fixture, "_parse_args_impl should not thr REQUIRE_NOTHROW(sut_parse_args_impl(cmd_args)); } - // _get_argument TEST_CASE_FIXTURE( @@ -119,7 +117,6 @@ TEST_CASE_FIXTURE( } } - // parse_args TEST_CASE_FIXTURE(argument_parser_test_fixture, "parse_args should throw when there is no value specified for a required optional argument") { @@ -228,7 +225,6 @@ TEST_CASE_FIXTURE( free_argv(argc, argv); } - // has_value TEST_CASE_FIXTURE(argument_parser_test_fixture, "has_value should return false if there is no argument with given name present") { @@ -302,7 +298,6 @@ TEST_CASE_FIXTURE(argument_parser_test_fixture, "has_value should return false w free_argv(argc, argv); } - // value TEST_CASE_FIXTURE(argument_parser_test_fixture, "value() should throw if there is no argument with given name present") { @@ -418,7 +413,6 @@ TEST_CASE_FIXTURE( free_argv(argc, argv); } - // count TEST_CASE_FIXTURE(argument_parser_test_fixture, "count should return 0 before calling parse_args") { @@ -490,7 +484,6 @@ TEST_CASE_FIXTURE(argument_parser_test_fixture, "count should return the number free_argv(argc, argv); } - // values TEST_CASE_FIXTURE(argument_parser_test_fixture, "values() should throw when calling with a positional argument's name") { diff --git a/test/source/test_optional_argument.cpp b/test/source/test_optional_argument.cpp index 30ec798..2de0a56 100644 --- a/test/source/test_optional_argument.cpp +++ b/test/source/test_optional_argument.cpp @@ -24,11 +24,11 @@ using invalid_value_type = double; using sut_type = optional_argument; sut_type prepare_argument(std::string_view primary_name) { - return sut_type(argument_name{primary_name}); + return sut_type(argument_name{ primary_name }); } sut_type prepare_argument(std::string_view primary_name, std::string_view secondary_name) { - return sut_type(argument_name{primary_name, secondary_name}); + return sut_type(argument_name{ primary_name, secondary_name }); } const std::string empty_str = ""; diff --git a/test/source/test_positional_argument.cpp b/test/source/test_positional_argument.cpp index e567919..171dbe3 100644 --- a/test/source/test_positional_argument.cpp +++ b/test/source/test_positional_argument.cpp @@ -21,11 +21,11 @@ using test_value_type = int; using sut_type = positional_argument; sut_type prepare_argument(std::string_view primary_name) { - return sut_type(argument_name{primary_name}); + return sut_type(argument_name{ primary_name }); } sut_type prepare_argument(std::string_view primary_name, std::string_view secondary_name) { - return sut_type(argument_name{primary_name, secondary_name}); + return sut_type(argument_name{ primary_name, secondary_name }); } const std::string empty_str = "";