Skip to content

Commit

Permalink
resolved comments
Browse files Browse the repository at this point in the history
  • Loading branch information
SpectraL519 committed Apr 8, 2024
1 parent 44e755d commit f7c88e9
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 30 deletions.
1 change: 1 addition & 0 deletions change_log.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* Added the `format` workflow
* Switched from the `<algorithm>` to the `<ranges>` library for all current container operations
* Modified the `argument_name` structure - renamed members: `name` to `primary`, `short_name` to `secondary`
* Added `argument_name::match(string_view)` and `argument_name::match(argument_name)` functions
* Added aliases for default argument enum classes:
* `ap::default_argument::positional` = `ap::default_posarg`
* `ap::default_argument::optional` = `ap::default_optarg`
9 changes: 0 additions & 9 deletions include/ap/argument_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,15 +384,6 @@ struct argument_name {
return false;
}

/**
* @brief Equality comparison operator for string variables representing argument names.
* @param name The string view to compare with.
* @return Equality of names comparison (either primary or secondary name).
*/
bool operator==(std::string_view name) const noexcept {
return name == this->primary or (this->secondary and name == this->secondary.value());
}

/// @brief Get a string representation of the argument_name.
[[nodiscard]] std::string str() const noexcept {
return this->secondary
Expand Down
38 changes: 30 additions & 8 deletions test/source/test_argument_name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@ argument_name default_argument_name_primary_and_secondary() {

TEST_SUITE_BEGIN("test_argument_name");

TEST_CASE("argument_name.primary member should be correctly "
"initialized") {
TEST_CASE("argument_name.primary member should be correctly initialized") {
const auto arg_name = default_argument_name_primary();

REQUIRE_EQ(arg_name.primary, primary_name);
}

TEST_CASE("argument_name members should be correctly "
"initialized") {
TEST_CASE("argument_name members should be correctly initialized") {
const auto arg_name = default_argument_name_primary_and_secondary();

REQUIRE_EQ(arg_name.primary, primary_name);
Expand All @@ -47,6 +45,15 @@ 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 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::operator==(argument_name) should return false if primary names are not "
"equal") {
const auto arg_name_a = default_argument_name_primary();
Expand All @@ -55,13 +62,28 @@ TEST_CASE("argument_name::operator==(argument_name) should return false if prima
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 secondary names are not "
"equal") {
const auto arg_name_a = default_argument_name_primary_and_secondary();
const auto arg_name_b = argument_name{ primary_name, other_primary_name };

REQUIRE_NE(arg_name_a, arg_name_b);
}

TEST_CASE("argument_name::operator==(argument_name) should return true if primary names are equal "
"and secondary names are null") {
const auto arg_name_a = default_argument_name_primary();
const auto arg_name_b = default_argument_name_primary();

REQUIRE_EQ(arg_name_a, arg_name_b);
}

TEST_CASE("argument_name::operator==(argument_name) should return true if both primary and "
"secondary names are equal") {
const auto arg_name_a = default_argument_name_primary_and_secondary();
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);
REQUIRE_EQ(arg_name_a, arg_name_b);
}

TEST_CASE("argument_name::match(string_view) should return true if the given string matches at "
Expand Down
2 changes: 1 addition & 1 deletion test/source/test_argument_parser_parse_args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ TEST_CASE_FIXTURE(argument_parser_test_fixture, "_preprocess_input should return
std::size_t opt_arg_idx = non_default_args_split;
for (std::size_t i = non_default_args_split; i < cmd_args.size(); i += 2) { // optional args
REQUIRE_EQ(cmd_args.at(i).discriminator, cmd_argument::type_discriminator::flag);
REQUIRE_EQ(cmd_args.at(i).value, prepare_arg_name(opt_arg_idx));
REQUIRE(prepare_arg_name(opt_arg_idx).match(cmd_args.at(i).value));
REQUIRE_EQ(cmd_args.at(i + 1).discriminator, cmd_argument::type_discriminator::value);
REQUIRE_EQ(cmd_args.at(i + 1).value, prepare_arg_value(opt_arg_idx));
opt_arg_idx++;
Expand Down
10 changes: 4 additions & 6 deletions test/source/test_optional_argument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ TEST_CASE_FIXTURE(optional_argument_test_fixture, "is_optional() should return t

TEST_CASE_FIXTURE(optional_argument_test_fixture, "name() should return value passed to the optional argument constructor for primary name") {
const auto sut = prepare_argument(primary_name);

const auto name = sut_get_name(sut);

REQUIRE_EQ(name, primary_name);
REQUIRE_NE(name, secondary_name);
REQUIRE(name.match(primary_name));
REQUIRE_FALSE(name.match(secondary_name));
}

TEST_CASE_FIXTURE(
Expand All @@ -69,11 +68,10 @@ TEST_CASE_FIXTURE(
"argument constructor for both primary and secondary names"
) {
const auto sut = prepare_argument(primary_name, secondary_name);

const auto name = sut_get_name(sut);

REQUIRE_EQ(name, primary_name);
REQUIRE_EQ(name, secondary_name);
REQUIRE(name.match(primary_name));
REQUIRE(name.match(secondary_name));
}

TEST_CASE_FIXTURE(optional_argument_test_fixture, "help() should return nullopt by default") {
Expand Down
10 changes: 4 additions & 6 deletions test/source/test_positional_argument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ TEST_CASE_FIXTURE(positional_argument_test_fixture, "is_optional() should return

TEST_CASE_FIXTURE(positional_argument_test_fixture, "name() should return value passed to the optional argument constructor for primary name") {
const auto sut = prepare_argument(primary_name);

const auto name = sut_get_name(sut);

REQUIRE_EQ(name, primary_name);
REQUIRE_NE(name, secondary_name);
REQUIRE(name.match(primary_name));
REQUIRE_FALSE(name.match(secondary_name));
}

TEST_CASE_FIXTURE(
Expand All @@ -62,11 +61,10 @@ TEST_CASE_FIXTURE(
"argument constructor for both primary and secondary names"
) {
const auto sut = prepare_argument(primary_name, secondary_name);

const auto name = sut_get_name(sut);

REQUIRE_EQ(name, primary_name);
REQUIRE_EQ(name, secondary_name);
REQUIRE(name.match(primary_name));
REQUIRE(name.match(secondary_name));
}

TEST_CASE_FIXTURE(positional_argument_test_fixture, "help() should return nullopt by default") {
Expand Down

0 comments on commit f7c88e9

Please sign in to comment.