@@ -336,6 +336,36 @@ TEST_CASE_METHOD(TApp, "pair_check", "[optiontype]") {
336
336
CHECK_THROWS_AS (run (), CLI::ValidationError);
337
337
}
338
338
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
+
339
369
TEST_CASE_METHOD (TApp, " pair_check_take_first" , " [optiontype]" ) {
340
370
std::string myfile{" pair_check_file2.txt" };
341
371
bool ok = static_cast <bool >(std::ofstream (myfile.c_str ()).put (' a' )); // create file
0 commit comments