@@ -131,6 +131,73 @@ void test_adopt__returns_unknown_option(void)
131131 cl_assert_equal_i (ADOPT_STATUS_UNKNOWN_OPTION , status );
132132}
133133
134+ void test_adopt__bool (void )
135+ {
136+ int foo = 0 , bar = 0 ;
137+
138+ adopt_spec specs [] = {
139+ { ADOPT_TYPE_BOOL , "foo" , 0 , & foo , 0 },
140+ { ADOPT_TYPE_BOOL , "bar" , 0 , & bar , 0 },
141+ { 0 }
142+ };
143+
144+ char * args [] = { "--foo" , "-b" };
145+ adopt_expected expected [] = {
146+ { & specs [0 ], NULL },
147+ { NULL , "-b" },
148+ };
149+
150+ /* Parse an arg list with only bare arguments */
151+ test_parse (specs , args , 2 , expected , 2 );
152+ cl_assert_equal_i (1 , foo );
153+ cl_assert_equal_i (0 , bar );
154+ }
155+
156+ void test_adopt__bool_converse (void )
157+ {
158+ int foo = 1 , bar = 0 ;
159+
160+ adopt_spec specs [] = {
161+ { ADOPT_TYPE_BOOL , "foo" , 0 , & foo , 0 },
162+ { ADOPT_TYPE_BOOL , "bar" , 0 , & bar , 0 },
163+ { 0 }
164+ };
165+
166+ char * args [] = { "--no-foo" , "--bar" };
167+ adopt_expected expected [] = {
168+ { & specs [0 ], NULL },
169+ { & specs [1 ], NULL },
170+ };
171+
172+ /* Parse an arg list with only bare arguments */
173+ test_parse (specs , args , 2 , expected , 2 );
174+ cl_assert_equal_i (0 , foo );
175+ cl_assert_equal_i (1 , bar );
176+ }
177+
178+ void test_adopt__bool_converse_overrides (void )
179+ {
180+ int foo = 0 , bar = 0 ;
181+
182+ adopt_spec specs [] = {
183+ { ADOPT_TYPE_BOOL , "foo" , 0 , & foo , 0 },
184+ { ADOPT_TYPE_BOOL , "bar" , 0 , & bar , 0 },
185+ { 0 }
186+ };
187+
188+ char * args [] = { "--foo" , "--bar" , "--no-foo" };
189+ adopt_expected expected [] = {
190+ { & specs [0 ], NULL },
191+ { & specs [1 ], NULL },
192+ { & specs [0 ], NULL },
193+ };
194+
195+ /* Parse an arg list with only bare arguments */
196+ test_parse (specs , args , 3 , expected , 3 );
197+ cl_assert_equal_i (0 , foo );
198+ cl_assert_equal_i (1 , bar );
199+ }
200+
134201void test_adopt__long_switches1 (void )
135202{
136203 int foo = 0 , bar = 0 ;
0 commit comments