-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #253 from skrobinson/fix-string-crash
Fix crash with char[] default values
- Loading branch information
Showing
3 changed files
with
26 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <argparse/argparse.hpp> | ||
#include <doctest.hpp> | ||
#include <string> | ||
|
||
using doctest::test_suite; | ||
|
||
TEST_CASE("Use a 'string' default value" * test_suite("default_value")) { | ||
argparse::ArgumentParser program("test"); | ||
|
||
SUBCASE("Use a const char[] default value") { | ||
program.add_argument("--arg").default_value("array of char"); | ||
REQUIRE_NOTHROW(program.parse_args({"test"})); | ||
REQUIRE(program.get("--arg") == std::string("array of char")); | ||
} | ||
|
||
SUBCASE("Use a std::string default value") { | ||
program.add_argument("--arg").default_value(std::string("string object")); | ||
REQUIRE_NOTHROW(program.parse_args({"test"})); | ||
REQUIRE(program.get("--arg") == std::string("string object")); | ||
} | ||
} |