First version for string_to_number, just one test, is working fine, i'm considering swithching to handling only integers for in the future to manage in special struct that manages doubles as fractions, obviously this will mean changing nodes for general numbers to integers/fractions and shit
This commit is contained in:
27
test/test_lexer.c
Normal file
27
test/test_lexer.c
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "lexer.h"
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <setjmp.h>
|
||||
#include <cmocka.h>
|
||||
|
||||
static void test_string_to_number(void **state) {
|
||||
(void) state;
|
||||
|
||||
char num[16] = "2333t55";
|
||||
size_t offset = 0;
|
||||
double result = 0;
|
||||
assert_int_equal(string_to_number(num, &offset, &result), 0);
|
||||
|
||||
assert_int_equal(offset, 4);
|
||||
assert_double_equal(result, 2333, 1e-6);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(test_string_to_number),
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
||||
Reference in New Issue
Block a user