- Move CLI internal headers to `includes/internal/cli/` - Split CLI handler and parsing declarations across dedicated internal headers - Move handler map to `option_map.c` and properly update references - Relocate CLI utility source and test files from `utils` to `parse_utils` - Refactor `cli.h` to only expose the public interface, move internal typedefs/functions out - Update build system: add conditional git commit detection
68 lines
1.3 KiB
C
68 lines
1.3 KiB
C
#include <criterion/criterion.h>
|
|
#include "internal/parse_utils.h"
|
|
|
|
/* Test 1: Valid simple number */
|
|
Test(parse_float, valid_number)
|
|
{
|
|
float result;
|
|
int ret = cli_parse_float("42.42", &result);
|
|
|
|
cr_assert_eq(ret, 0);
|
|
cr_assert_float_eq(result, 42.42, 0.0001);
|
|
}
|
|
|
|
/* Test 2: Zero */
|
|
Test(parse_float, zero)
|
|
{
|
|
float result;
|
|
int ret = cli_parse_float("0", &result);
|
|
|
|
cr_assert_eq(ret, 0);
|
|
cr_assert_float_eq(result, 0, 0.0001);
|
|
}
|
|
|
|
/* Test 3: NULL pointer */
|
|
Test(parse_float, null_pointer)
|
|
{
|
|
float result;
|
|
int ret = cli_parse_float(NULL, &result);
|
|
|
|
cr_assert_eq(ret, 1);
|
|
}
|
|
|
|
/* Test 4: Empty string */
|
|
Test(parse_float, empty_string)
|
|
{
|
|
float result;
|
|
int ret = cli_parse_float("", &result);
|
|
|
|
cr_assert_eq(ret, 1);
|
|
}
|
|
|
|
/* Test 5: Negative number */
|
|
Test(parse_float, negative_number)
|
|
{
|
|
float result;
|
|
int ret = cli_parse_float("-42", &result);
|
|
|
|
cr_assert_eq(ret, 1);
|
|
}
|
|
|
|
/* Test 6: Invalid characters */
|
|
Test(parse_float, invalid_characters)
|
|
{
|
|
float result;
|
|
int ret = cli_parse_float("42abc", &result);
|
|
|
|
cr_assert_eq(ret, 1);
|
|
}
|
|
|
|
/* Test 7: Dot + number */
|
|
Test(parse_float, dot)
|
|
{
|
|
float result;
|
|
int ret = cli_parse_float(".42", &result);
|
|
|
|
cr_assert_eq(ret, 0);
|
|
cr_assert_float_eq(result, 0.42, 0.0001);
|
|
}
|