Improve int parsing and allow negatives
This commit is contained in:
@@ -320,6 +320,35 @@ static void test_parse_mismatched_closed(void) {
|
||||
TEST_ASSERT_OBJ_ERROR(response);
|
||||
}
|
||||
|
||||
static void test_parse_int(void) {
|
||||
response = ucl_parse("123");
|
||||
|
||||
TEST_ASSERT_OBJ_INT_V(response->cell.car, 123);
|
||||
}
|
||||
|
||||
static void test_parse_int_hex(void) {
|
||||
response = ucl_parse("0xa");
|
||||
|
||||
TEST_ASSERT_OBJ_INT_V(response->cell.car, 0xa);
|
||||
}
|
||||
|
||||
static void test_parse_int_neg(void) {
|
||||
response = ucl_parse("-7");
|
||||
|
||||
TEST_ASSERT_OBJ_INT_V(response->cell.car, -7);
|
||||
}
|
||||
|
||||
static void test_parse_int_plus(void) {
|
||||
response = ucl_parse("+7");
|
||||
|
||||
TEST_ASSERT_OBJ_INT_V(response->cell.car, 7);
|
||||
}
|
||||
|
||||
static void test_parse_int_garbled(void) {
|
||||
response = ucl_parse("+1234g7");
|
||||
|
||||
TEST_ASSERT_OBJ_ERROR(response);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
UNITY_BEGIN();
|
||||
@@ -348,5 +377,10 @@ int main(void) {
|
||||
RUN_TEST(test_parse_nested);
|
||||
RUN_TEST(test_parse_mismatched_open);
|
||||
RUN_TEST(test_parse_mismatched_closed);
|
||||
RUN_TEST(test_parse_int);
|
||||
RUN_TEST(test_parse_int_hex);
|
||||
RUN_TEST(test_parse_int_neg);
|
||||
RUN_TEST(test_parse_int_plus);
|
||||
RUN_TEST(test_parse_int_garbled);
|
||||
return UNITY_END();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user