Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
SpectraL519 committed Apr 8, 2024
1 parent 124e338 commit e145aae
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 37 deletions.
18 changes: 10 additions & 8 deletions include/ap/argument_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<default_argument::optional>& arg_discriminator_list) noexcept {
argument_parser& default_optional_arguments(const std::vector<default_argument::optional>& arg_discriminator_list
) noexcept {
for (const auto arg_discriminator : arg_discriminator_list)
this->_add_default_optional_argument(arg_discriminator);
return *this;
Expand All @@ -1218,7 +1219,7 @@ class argument_parser {
argument::positional_argument<T>& 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);

Expand All @@ -1237,7 +1238,7 @@ class argument_parser {
argument::positional_argument<T>& 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);

Expand All @@ -1255,7 +1256,7 @@ class argument_parser {
argument::optional_argument<T>& 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);

Expand All @@ -1274,7 +1275,7 @@ class argument_parser {
argument::optional_argument<T>& 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);

Expand Down Expand Up @@ -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); };
}

Expand Down Expand Up @@ -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;
}
Expand Down
34 changes: 20 additions & 14 deletions test/source/test_argument_name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,25 @@ 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();

REQUIRE_NE(arg_name_a, arg_name_b);
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();

Expand All @@ -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();

Expand All @@ -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));
}
}
Expand All @@ -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();
Expand Down
16 changes: 12 additions & 4 deletions test/source/test_argument_parser_add_argument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}

Expand All @@ -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
);
}
}

Expand Down
7 changes: 0 additions & 7 deletions test/source/test_argument_parser_parse_args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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") {
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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") {
Expand Down
4 changes: 2 additions & 2 deletions test/source/test_optional_argument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ using invalid_value_type = double;
using sut_type = optional_argument<test_value_type>;

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 = "";
Expand Down
4 changes: 2 additions & 2 deletions test/source/test_positional_argument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ using test_value_type = int;
using sut_type = positional_argument<test_value_type>;

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 = "";
Expand Down

0 comments on commit e145aae

Please sign in to comment.