-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MISC] Change value_list_validator construction. #1298
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
#include <seqan3/alphabet/all.hpp> | ||
#include <seqan3/core/char_operations/predicate.hpp> | ||
#include <seqan3/range/views/persist.hpp> | ||
#include <seqan3/range/views/take.hpp> | ||
#include <seqan3/std/filesystem> | ||
#include <seqan3/test/tmp_filename.hpp> | ||
|
||
|
@@ -689,18 +690,44 @@ TEST(validator_test, arithmetic_range_validator_error) | |
EXPECT_THROW(parser7.parse(), validation_failed); | ||
} | ||
|
||
enum class foo | ||
{ | ||
one, | ||
two, | ||
three | ||
}; | ||
|
||
TEST(validator_test, value_list_validator_success) | ||
{ | ||
// type deduction | ||
// -------------- | ||
// all arithmetic types are deduced to double in order to easily allow chaining of arithmetic validators | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This explanation could also go into the class docs. I was actually wondering why it's |
||
EXPECT_TRUE((std::same_as<value_list_validator<double>, decltype(value_list_validator{1})>)); | ||
// The same holds for a range of arithmetic types | ||
std::vector v{1, 2, 3}; | ||
EXPECT_TRUE((std::same_as<value_list_validator<double>, decltype(value_list_validator{v})>)); | ||
EXPECT_TRUE((std::same_as<value_list_validator<double>, decltype(value_list_validator{v | views::take(2)})>)); | ||
// const char * is deduced to std::string | ||
std::vector v2{"ha", "ba", "ma"}; | ||
EXPECT_TRUE((std::same_as<value_list_validator<std::string>, decltype(value_list_validator{"ha", "ba", "ma"})>)); | ||
EXPECT_TRUE((std::same_as<value_list_validator<std::string>, decltype(value_list_validator{v2})>)); | ||
EXPECT_TRUE((std::same_as<value_list_validator<std::string>, decltype(value_list_validator{v2 | views::take(2)})>)); | ||
// custom types are used as is | ||
EXPECT_TRUE((std::same_as<value_list_validator<foo>, decltype(value_list_validator{foo::one, foo::two})>)); | ||
|
||
// usage | ||
// ----- | ||
std::string option_value; | ||
int option_value_int; | ||
std::vector<std::string> option_vector; | ||
std::vector<int> option_vector_int; | ||
|
||
// option | ||
std::vector<std::string> valid_str_values{"ha", "ba", "ma"}; | ||
const char * argv[] = {"./argument_parser_test", "-s", "ba"}; | ||
argument_parser parser{"test_parser", 3, argv, false}; | ||
parser.add_option(option_value, 's', "string-option", "desc", | ||
option_spec::DEFAULT, value_list_validator{{"ha", "ba", "ma"}}); | ||
option_spec::DEFAULT, value_list_validator{valid_str_values | views::take(2)}); | ||
|
||
testing::internal::CaptureStderr(); | ||
EXPECT_NO_THROW(parser.parse()); | ||
|
@@ -711,7 +738,7 @@ TEST(validator_test, value_list_validator_success) | |
const char * argv2[] = {"./argument_parser_test", "-i", "-21"}; | ||
argument_parser parser2{"test_parser", 3, argv2, false}; | ||
parser2.add_option(option_value_int, 'i', "int-option", "desc", | ||
option_spec::DEFAULT, value_list_validator<int>{{0, -21, 10}}); | ||
option_spec::DEFAULT, value_list_validator<int>{0, -21, 10}); | ||
|
||
testing::internal::CaptureStderr(); | ||
EXPECT_NO_THROW(parser2.parse()); | ||
|
@@ -721,7 +748,7 @@ TEST(validator_test, value_list_validator_success) | |
// positional option | ||
const char * argv3[] = {"./argument_parser_test", "ma"}; | ||
argument_parser parser3{"test_parser", 2, argv3, false}; | ||
parser3.add_positional_option(option_value, "desc", value_list_validator{{"ha", "ba", "ma"}}); | ||
parser3.add_positional_option(option_value, "desc", value_list_validator{valid_str_values}); | ||
|
||
testing::internal::CaptureStderr(); | ||
EXPECT_NO_THROW(parser3.parse()); | ||
|
@@ -731,8 +758,7 @@ TEST(validator_test, value_list_validator_success) | |
// positional option - vector | ||
const char * argv4[] = {"./argument_parser_test", "ha", "ma"}; | ||
argument_parser parser4{"test_parser", 3, argv4, false}; | ||
parser4.add_positional_option(option_vector, "desc", | ||
value_list_validator{{"ha", "ba", "ma"}}); | ||
parser4.add_positional_option(option_vector, "desc", value_list_validator{"ha", "ba", "ma"}); | ||
|
||
testing::internal::CaptureStderr(); | ||
EXPECT_NO_THROW(parser4.parse()); | ||
|
@@ -744,7 +770,7 @@ TEST(validator_test, value_list_validator_success) | |
const char * argv5[] = {"./argument_parser_test", "-i", "-10", "-i", "48"}; | ||
argument_parser parser5{"test_parser", 5, argv5, false}; | ||
parser5.add_option(option_vector_int, 'i', "int-option", "desc", | ||
option_spec::DEFAULT, value_list_validator<int>{{-10,48,50}}); | ||
option_spec::DEFAULT, value_list_validator<int>{-10, 48, 50}); | ||
|
||
testing::internal::CaptureStderr(); | ||
EXPECT_NO_THROW(parser5.parse()); | ||
|
@@ -757,7 +783,7 @@ TEST(validator_test, value_list_validator_success) | |
const char * argv7[] = {"./argument_parser_test", "-h"}; | ||
argument_parser parser7{"test_parser", 2, argv7, false}; | ||
parser7.add_option(option_vector_int, 'i', "int-option", "desc", | ||
option_spec::DEFAULT, value_list_validator<int>{{-10,48,50}}); | ||
option_spec::DEFAULT, value_list_validator<int>{-10, 48, 50}); | ||
|
||
option_vector_int.clear(); | ||
testing::internal::CaptureStdout(); | ||
|
@@ -767,7 +793,7 @@ TEST(validator_test, value_list_validator_success) | |
"===========" + | ||
basic_options_str + | ||
" -i, --int-option (List of signed 32 bit integer's)" | ||
" desc Default: []. Value must be one of [-10,48,50]." + | ||
" desc Default: []. Value must be one of [-10, 48, 50]." + | ||
basic_version_str); | ||
EXPECT_TRUE(ranges::equal((my_stdout | std::views::filter(!is_space)), | ||
expected | std::views::filter(!is_space))); | ||
|
@@ -784,30 +810,30 @@ TEST(validator_test, value_list_validator_error) | |
const char * argv[] = {"./argument_parser_test", "-s", "sa"}; | ||
argument_parser parser{"test_parser", 3, argv, false}; | ||
parser.add_option(option_value, 's', "string-option", "desc", | ||
option_spec::DEFAULT, value_list_validator{{"ha", "ba", "ma"}}); | ||
option_spec::DEFAULT, value_list_validator{"ha", "ba", "ma"}); | ||
|
||
EXPECT_THROW(parser.parse(), validation_failed); | ||
|
||
// positional option | ||
const char * argv3[] = {"./argument_parser_test", "30"}; | ||
argument_parser parser3{"test_parser", 2, argv3, false}; | ||
parser3.add_positional_option(option_value_int, "desc", value_list_validator{{0, 5, 10}}); | ||
parser3.add_positional_option(option_value_int, "desc", value_list_validator{0, 5, 10}); | ||
|
||
EXPECT_THROW(parser3.parse(), validation_failed); | ||
|
||
// positional option - vector | ||
const char * argv4[] = {"./argument_parser_test", "fo", "ma"}; | ||
argument_parser parser4{"test_parser", 3, argv4, false}; | ||
parser4.add_positional_option(option_vector, "desc", | ||
value_list_validator{{"ha", "ba", "ma"}}); | ||
value_list_validator{"ha", "ba", "ma"}); | ||
|
||
EXPECT_THROW(parser4.parse(), validation_failed); | ||
|
||
// option - vector | ||
const char * argv5[] = {"./argument_parser_test", "-i", "-10", "-i", "488"}; | ||
argument_parser parser5{"test_parser", 5, argv5, false}; | ||
parser5.add_option(option_vector_int, 'i', "int-option", "desc", | ||
option_spec::DEFAULT, value_list_validator<int>{{-10,48,50}}); | ||
option_spec::DEFAULT, value_list_validator<int>{-10, 48, 50}); | ||
|
||
EXPECT_THROW(parser5.parse(), validation_failed); | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general these files seem not to follow our style guide which they actually should but that is for another time. It seems we need to go through the tutorials anyway before the release. But maybe you can mark it already as a card so we do not forget about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which style do you mean specifically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the all-or-nothing rule:
if you break on a line, then put every argument on a separate line