@@ -119,6 +119,30 @@ TEST_F(TApp, BasicOptionGroupMax) {
119
119
EXPECT_NE (exactloc, std::string::npos);
120
120
}
121
121
122
+ TEST_F (TApp, BasicOptionGroupMax1) {
123
+ auto ogroup = app.add_option_group (" clusters" );
124
+ int res;
125
+ ogroup->add_option (" --test1" , res);
126
+ ogroup->add_option (" --test2" , res);
127
+ ogroup->add_option (" --test3" , res);
128
+ int val2;
129
+ app.add_option (" --option" , val2);
130
+ ogroup->require_option (-1 );
131
+ args = {" --test1" , " 5" };
132
+ run ();
133
+ EXPECT_EQ (res, 5 );
134
+
135
+ args = {" --option" , " 9" };
136
+ EXPECT_NO_THROW (run ());
137
+
138
+ args = {" --test1" , " 5" , " --test2" , " 4" };
139
+ EXPECT_THROW (run (), CLI::RequiredError);
140
+
141
+ std::string help = ogroup->help ();
142
+ auto exactloc = help.find (" [At most 1" );
143
+ EXPECT_NE (exactloc, std::string::npos);
144
+ }
145
+
122
146
TEST_F (TApp, BasicOptionGroupMin) {
123
147
auto ogroup = app.add_option_group (" clusters" );
124
148
int res;
@@ -140,6 +164,51 @@ TEST_F(TApp, BasicOptionGroupMin) {
140
164
EXPECT_NE (exactloc, std::string::npos);
141
165
}
142
166
167
+ TEST_F (TApp, BasicOptionGroupExact2) {
168
+ auto ogroup = app.add_option_group (" clusters" );
169
+ int res;
170
+ ogroup->add_option (" --test1" , res);
171
+ ogroup->add_option (" --test2" , res);
172
+ ogroup->add_option (" --test3" , res);
173
+ int val2;
174
+ app.add_option (" --option" , val2);
175
+ ogroup->require_option (2 );
176
+
177
+ args = {" --option" , " 9" };
178
+ EXPECT_THROW (run (), CLI::RequiredError);
179
+
180
+ args = {" --test1" , " 5" , " --test2" , " 4" , " --test3=5" };
181
+ EXPECT_THROW (run (), CLI::RequiredError);
182
+
183
+ args = {" --test1" , " 5" , " --test3=5" };
184
+ EXPECT_NO_THROW (run ());
185
+
186
+ std::string help = ogroup->help ();
187
+ auto exactloc = help.find (" [Exactly 2" );
188
+ EXPECT_NE (exactloc, std::string::npos);
189
+ }
190
+
191
+ TEST_F (TApp, BasicOptionGroupMin2) {
192
+ auto ogroup = app.add_option_group (" clusters" );
193
+ int res;
194
+ ogroup->add_option (" --test1" , res);
195
+ ogroup->add_option (" --test2" , res);
196
+ ogroup->add_option (" --test3" , res);
197
+ int val2;
198
+ app.add_option (" --option" , val2);
199
+ ogroup->require_option (2 , 0 );
200
+
201
+ args = {" --option" , " 9" };
202
+ EXPECT_THROW (run (), CLI::RequiredError);
203
+
204
+ args = {" --test1" , " 5" , " --test2" , " 4" , " --test3=5" };
205
+ EXPECT_NO_THROW (run ());
206
+
207
+ std::string help = ogroup->help ();
208
+ auto exactloc = help.find (" [At least 2" );
209
+ EXPECT_NE (exactloc, std::string::npos);
210
+ }
211
+
143
212
TEST_F (TApp, BasicOptionGroupMinMoved) {
144
213
145
214
int res;
@@ -223,6 +292,23 @@ TEST_F(TApp, BasicOptionGroupAddFailures) {
223
292
EXPECT_THROW (ogroup->add_option (opt3), CLI::OptionAlreadyAdded);
224
293
}
225
294
295
+ TEST_F (TApp, BasicOptionGroupScrewedUpMove) {
296
+
297
+ int res;
298
+ auto opt1 = app.add_option (" --test1" , res);
299
+ auto opt2 = app.add_option (" --test2" , res);
300
+ int val2;
301
+ app.add_option (" --option" , val2);
302
+
303
+ auto ogroup = app.add_option_group (" clusters" );
304
+ ogroup->require_option ();
305
+ auto ogroup2 = ogroup->add_option_group (" clusters2" );
306
+ EXPECT_THROW (ogroup2->add_options (opt1, opt2), CLI::OptionNotFound);
307
+
308
+ CLI::Option_group EmptyGroup (" description" , " new group" , nullptr );
309
+
310
+ EXPECT_THROW (EmptyGroup.add_option (opt2), CLI::OptionNotFound);
311
+ }
226
312
/*
227
313
struct SubcommandProgram : public TApp {
228
314
0 commit comments