@@ 55,6 55,10 @@ void test_countargs(void)
TEST_ASSERT_FALSE(argspec[0].seen);
TEST_ASSERT_EQUAL(0, argspec[0].val_int);
reset_args(argspec);
+
+ testarg = (char *[]){ "--verbose", "-vv", "--verbose=5" };
+ TEST_ASSERT_LESS_THAN_INT(0, sc_argparse(argspec, 3, testarg));
+ reset_args(argspec);
}
void test_intargs(void)
@@ 77,7 81,7 @@ void test_intargs(void)
argspec[0].val_int = 5; /* need to reset default */
testarg = (char *[]){ "--argb=-500", "-c", "1234" };
- sc_argparse(argspec, 4, testarg);
+ sc_argparse(argspec, 3, testarg);
TEST_ASSERT_EQUAL(1234, argspec[0].val_int);
TEST_ASSERT_EQUAL(-500, argspec[1].val_int);
TEST_ASSERT_TRUE(argspec[0].seen);
@@ 130,6 134,13 @@ void test_stringargs(void)
argspec[1].val_string = "default b";
/* missing argument! */
+ testarg = (char *[]){ "-ac", "theres an arg but its all wrong" };
+ TEST_ASSERT_LESS_THAN_INT(0, sc_argparse(argspec, 1, testarg));
+
+ reset_args(argspec);
+ argspec[1].val_string = "default b";
+
+ /* missing argument! */
testarg = (char *[]){ "-ca" };
TEST_ASSERT_LESS_THAN_INT(0, sc_argparse(argspec, 1, testarg));
@@ 173,11 184,53 @@ void test_stringargs(void)
TEST_ASSERT_EQUAL_STRING("a special value", argspec[0].val_string);
}
+void test_unknown_args(void)
+{
+ char **testarg;
+ struct sc_arg argspec[] = {
+ SC_ARG_DEF_INT('a', "--arga", 20, "help text"),
+ SC_ARG_DEF_STRING('b', "--argb", "default b", "help text"),
+ SC_ARG_COUNT('c', "--argc", "help text"),
+ SC_ARG_END(),
+ };
+
+ testarg = (char *[]){ "-d" };
+ TEST_ASSERT_LESS_THAN_INT(0, sc_argparse(argspec, 1, testarg));
+
+ testarg = (char *[]){ "--not-an-arg" };
+ TEST_ASSERT_LESS_THAN_INT(0, sc_argparse(argspec, 1, testarg));
+
+ testarg = (char *[]){ "--argc-but-only-substring" };
+ TEST_ASSERT_LESS_THAN_INT(0, sc_argparse(argspec, 1, testarg));
+}
+
+void test_stop_parsing(void)
+{
+ char **testarg;
+ struct sc_arg argspec[] = {
+ SC_ARG_DEF_INT('a', "--arga", 20, "help text"),
+ SC_ARG_DEF_STRING('b', "--argb", "default b", "help text"),
+ SC_ARG_COUNT('c', "--argc", "help text"),
+ SC_ARG_END(),
+ };
+
+ testarg = (char *[]){ "-a", "1", "--", "-c" };
+ TEST_ASSERT_GREATER_OR_EQUAL_INT(0, sc_argparse(argspec, 4, testarg));
+ TEST_ASSERT_EQUAL(1, argspec[0].val_int);
+ TEST_ASSERT_EQUAL_STRING("default b", argspec[1].val_string);
+ TEST_ASSERT_EQUAL(0, argspec[2].val_int);
+ TEST_ASSERT_TRUE(argspec[0].seen);
+ TEST_ASSERT_FALSE(argspec[1].seen);
+ TEST_ASSERT_FALSE(argspec[2].seen);
+}
+
int main(void)
{
UNITY_BEGIN();
RUN_TEST(test_countargs);
RUN_TEST(test_intargs);
RUN_TEST(test_stringargs);
+ RUN_TEST(test_unknown_args);
+ RUN_TEST(test_stop_parsing);
return UNITY_END();
}