Skip to content

Commit 6200fab

Browse files
committed
add additional test
1 parent 48c65bf commit 6200fab

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/OptionTypeTest.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,36 @@ TEST_CASE_METHOD(TApp, "pair_check", "[optiontype]") {
336336
CHECK_THROWS_AS(run(), CLI::ValidationError);
337337
}
338338

339+
TEST_CASE_METHOD(TApp, "pair_check_string", "[optiontype]") {
340+
std::string myfile{"pair_check_file.txt"};
341+
bool ok = static_cast<bool>(std::ofstream(myfile.c_str()).put('a')); // create file
342+
CHECK(ok);
343+
344+
CHECK(CLI::ExistingFile(myfile).empty());
345+
std::pair<std::string, std::string> findex;
346+
347+
auto v0 = CLI::ExistingFile;
348+
v0.application_index(0);
349+
auto v1 = CLI::PositiveNumber;
350+
v1.application_index(1);
351+
app.add_option("--file", findex)->check(v0)->check(v1);
352+
353+
args = {"--file", myfile, "2"};
354+
355+
CHECK_NOTHROW(run());
356+
357+
CHECK(myfile == findex.first);
358+
CHECK("2" == findex.second);
359+
360+
args = {"--file", myfile, "-3"};
361+
362+
CHECK_THROWS_AS(run(), CLI::ValidationError);
363+
364+
args = {"--file", myfile, "2"};
365+
std::remove(myfile.c_str());
366+
CHECK_THROWS_AS(run(), CLI::ValidationError);
367+
}
368+
339369
TEST_CASE_METHOD(TApp, "pair_check_take_first", "[optiontype]") {
340370
std::string myfile{"pair_check_file2.txt"};
341371
bool ok = static_cast<bool>(std::ofstream(myfile.c_str()).put('a')); // create file

0 commit comments

Comments
 (0)