@@ -204,6 +204,75 @@ TEST_CASE("Positional options are required by default") {
204
204
CHECK_THROWS (options::parse (0 , nullptr , error_handler));
205
205
}
206
206
207
+ TEST_CASE (" Positional values<> work" ) {
208
+ using string_options = clopts<positional<" format" , " Output format" , values<" foo" , " bar" >>>;
209
+ using int_options = clopts<positional<" format" , " Output format" , values<0 , 1 >>>;
210
+
211
+ SECTION (" Correct values are accepted" ) {
212
+ std::array args1 = {" test" , " foo" };
213
+ std::array args2 = {" test" , " bar" };
214
+ std::array args3 = {" test" , " 0" };
215
+ std::array args4 = {" test" , " 1" };
216
+
217
+ auto opts1 = string_options::parse (args1.size (), args1.data (), error_handler);
218
+ auto opts2 = string_options::parse (args2.size (), args2.data (), error_handler);
219
+ auto opts3 = int_options::parse (args3.size (), args3.data (), error_handler);
220
+ auto opts4 = int_options::parse (args4.size (), args4.data (), error_handler);
221
+
222
+ REQUIRE (opts1.get <" format" >());
223
+ REQUIRE (opts2.get <" format" >());
224
+ REQUIRE (opts3.get <" format" >());
225
+ REQUIRE (opts4.get <" format" >());
226
+
227
+ CHECK (*opts1.get <" format" >() == " foo" );
228
+ CHECK (*opts2.get <" format" >() == " bar" );
229
+ CHECK (*opts3.get <" format" >() == 0 );
230
+ CHECK (*opts4.get <" format" >() == 1 );
231
+ }
232
+
233
+ SECTION (" Invalid values raise an error" ) {
234
+ std::array args1 = {" test" , " baz" };
235
+ std::array args2 = {" test" , " 2" };
236
+
237
+ CHECK_THROWS (string_options::parse (args1.size (), args1.data (), error_handler));
238
+ CHECK_THROWS (int_options::parse (args2.size (), args2.data (), error_handler));
239
+ }
240
+ }
241
+
242
+ TEST_CASE (" Multiple positional values<> work" ) {
243
+ using string_options = clopts<multiple<positional<" format" , " Output format" , values<" foo" , " bar" >>>>;
244
+ using int_options = clopts<multiple<positional<" format" , " Output format" , values<0 , 1 >>>>;
245
+
246
+ SECTION (" Correct values are accepted" ) {
247
+ std::array args1 = {" test" , " foo" , " bar" , " foo" };
248
+ std::array args2 = {" test" , " 0" , " 1" , " 1" };
249
+
250
+ auto opts1 = string_options::parse (args1.size (), args1.data (), error_handler);
251
+ auto opts2 = int_options::parse (args2.size (), args2.data (), error_handler);
252
+
253
+ REQUIRE (opts1.get <" format" >());
254
+ REQUIRE (opts2.get <" format" >());
255
+
256
+ REQUIRE (opts1.get <" format" >()->size () == 3 );
257
+ REQUIRE (opts2.get <" format" >()->size () == 3 );
258
+
259
+ CHECK (opts1.get <" format" >()->at (0 ) == " foo" );
260
+ CHECK (opts1.get <" format" >()->at (1 ) == " bar" );
261
+ CHECK (opts1.get <" format" >()->at (2 ) == " foo" );
262
+ CHECK (opts2.get <" format" >()->at (0 ) == 0 );
263
+ CHECK (opts2.get <" format" >()->at (1 ) == 1 );
264
+ CHECK (opts2.get <" format" >()->at (2 ) == 1 );
265
+ }
266
+
267
+ SECTION (" Invalid values raise an error" ) {
268
+ std::array args1 = {" test" , " foo" , " baz" , " foo" };
269
+ std::array args2 = {" test" , " 0" , " 2" , " 1" };
270
+
271
+ CHECK_THROWS (string_options::parse (args1.size (), args1.data (), error_handler));
272
+ CHECK_THROWS (int_options::parse (args2.size (), args2.data (), error_handler));
273
+ }
274
+ }
275
+
207
276
TEST_CASE (" Short option options are parsed properly" ) {
208
277
using options = clopts<
209
278
experimental::short_option<" s" , " A string" , std::string>,
@@ -360,7 +429,7 @@ TEST_CASE("Calling from main() works as expected") {
360
429
}
361
430
362
431
TEST_CASE (" File option can map a file properly" ) {
363
- auto run = [] <typename file> {
432
+ auto run = []<typename file> {
364
433
using options = clopts<option<" file" , " A file" , file>>;
365
434
366
435
std::array args = {
0 commit comments