Moved tests + Added more tests + Added memory testing to actions
Run tests / Run tests (push) Failing after 6s
Run tests / Run tests (push) Failing after 6s
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
#define EV_LOG_IMPLEMENTATION
|
||||
#include "ev_log.h"
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
ev_log_trace("Trace Log");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
tests = [
|
||||
'basic_log',
|
||||
]
|
||||
|
||||
foreach t : tests
|
||||
exec = executable(t, t+'.c', dependencies: [log_dep], c_args: evh_c_args)
|
||||
test(t, exec, suite: 'log')
|
||||
endforeach
|
||||
@@ -0,0 +1,23 @@
|
||||
#define EV_STR_IMPLEMENTATION
|
||||
#include "ev_str.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
evstring_view search_results[8];
|
||||
evstring search_string = evstr("Hello, this is me saying `Hello` like someone who says 'Hello'");
|
||||
|
||||
assert(evstring_findAll(search_string, evstr("Hello"), search_results) == 3);
|
||||
assert(search_results[0].data == search_string);
|
||||
assert(search_results[1].data == search_string);
|
||||
assert(search_results[2].data == search_string);
|
||||
assert(search_results[0].len == 5);
|
||||
assert(search_results[1].len == 5);
|
||||
assert(search_results[2].len == 5);
|
||||
assert(search_results[0].offset == 0);
|
||||
assert(search_results[1].offset == 26);
|
||||
assert(search_results[2].offset == 56);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#define EV_STR_IMPLEMENTATION
|
||||
#include "ev_str.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
evstring text = evstr("aab");
|
||||
evstring query = evstr("ab");
|
||||
evstring_view match = evstring_findFirst(text, query);
|
||||
|
||||
assert(match.len == 2);
|
||||
assert(match.offset == 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#define EV_STR_IMPLEMENTATION
|
||||
#include "ev_str.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
evstring text = evstr("aaab");
|
||||
evstring query = evstr("aab");
|
||||
evstring_view match = evstring_findFirst(text, query);
|
||||
|
||||
assert(match.len == 3);
|
||||
assert(match.offset == 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
tests = [
|
||||
'stack_global_heap',
|
||||
'slice',
|
||||
'push_variants',
|
||||
'new_format',
|
||||
'replace_first',
|
||||
'find_all',
|
||||
'push_fmt_float',
|
||||
'find_first_mismatch',
|
||||
'find_first_overlapping_prefix',
|
||||
'stack_get_space',
|
||||
'overlapping_push',
|
||||
]
|
||||
|
||||
foreach t : tests
|
||||
exec = executable(t, t+'.c', dependencies: [str_dep], c_args: evh_c_args)
|
||||
test(t, exec, suite: 'str')
|
||||
endforeach
|
||||
@@ -0,0 +1,19 @@
|
||||
#define EV_STR_IMPLEMENTATION
|
||||
#include "ev_str.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
evstring source = evstr("Stack 'Hello, World!'");
|
||||
evstring_view view = evstring_slice(source, 0, -1);
|
||||
|
||||
evstring str_fmt = evstring_new("%d, %d, %.*s", 1, 0, view.len, view.data + view.offset);
|
||||
assert(str_fmt != NULL);
|
||||
assert(strcmp(str_fmt, "1, 0, Stack 'Hello, World!'") == 0);
|
||||
|
||||
evstring_free(str_fmt);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#define EV_STR_IMPLEMENTATION
|
||||
#include "ev_str.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
evstring s = evstring_newFromStr("abc");
|
||||
assert(s != NULL);
|
||||
|
||||
evstring_error_t err = evstring_pushStr(&s, s);
|
||||
assert(err == EV_STR_ERR_NONE);
|
||||
assert(strcmp(s, "abcabc") == 0);
|
||||
|
||||
evstring_free(s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#define EV_STR_IMPLEMENTATION
|
||||
#include "ev_str.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
evstring heap_str = evstring_new("Heap 'Hello, World!'");
|
||||
assert(heap_str != NULL);
|
||||
|
||||
evstring_error_t res = evstring_push(&heap_str, "%.05f", 1.0f);
|
||||
assert(res == EV_STR_ERR_NONE);
|
||||
assert(evstring_getLength(heap_str) == 27);
|
||||
assert(strcmp(heap_str, "Heap 'Hello, World!'1.00000") == 0);
|
||||
|
||||
res = evstring_push(&heap_str, "Something");
|
||||
assert(res == EV_STR_ERR_NONE);
|
||||
assert(evstring_getLength(heap_str) == 36);
|
||||
assert(strcmp(heap_str, "Heap 'Hello, World!'1.00000Something") == 0);
|
||||
|
||||
evstring_free(heap_str);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#define EV_STR_IMPLEMENTATION
|
||||
#include "ev_str.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
evstring heap_str = evstring_new("Heap 'Hello, World!'");
|
||||
assert(heap_str != NULL);
|
||||
|
||||
evstring_error_t push_str_res = evstring_push(&heap_str, "Hello, Sisyphus! %f", 0.001f);
|
||||
assert(push_str_res == EV_STR_ERR_NONE);
|
||||
assert(strcmp(heap_str, "Heap 'Hello, World!'Hello, Sisyphus! 0.001000") == 0);
|
||||
|
||||
evstring_error_t push_char_res = evstring_push(&heap_str, (char)'X');
|
||||
assert(push_char_res == EV_STR_ERR_NONE);
|
||||
assert(strcmp(heap_str, "Heap 'Hello, World!'Hello, Sisyphus! 0.001000X") == 0);
|
||||
|
||||
evstring source = evstr("Stack 'Hello, World!'");
|
||||
evstring_view view = evstring_slice(source, 0, -1);
|
||||
evstring_error_t push_view_res = evstring_push(&heap_str, view);
|
||||
assert(push_view_res == EV_STR_ERR_NONE);
|
||||
assert(strcmp(heap_str, "Heap 'Hello, World!'Hello, Sisyphus! 0.001000XStack 'Hello, World!'") == 0);
|
||||
|
||||
evstring_free(heap_str);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#define EV_STR_IMPLEMENTATION
|
||||
#include "ev_str.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
evstring text = evstring_new("Hello, Hello!");
|
||||
assert(text != NULL);
|
||||
|
||||
evstring rep_str = evstring_replaceFirst(text, evstr("Hello"), evstr("Bye"));
|
||||
assert(rep_str != NULL);
|
||||
assert(strcmp(rep_str, "Bye, Hello!") == 0);
|
||||
|
||||
evstring_free(rep_str);
|
||||
evstring_free(text);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#define EV_STR_IMPLEMENTATION
|
||||
#include "ev_str.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
const evstring stack_str = evstr("Stack 'Hello, World!'");
|
||||
|
||||
evstring_view view = evstring_slice(stack_str, 0, -1);
|
||||
assert(view.data == stack_str);
|
||||
assert(view.offset == 0);
|
||||
assert(view.len == evstring_getLength(stack_str));
|
||||
|
||||
evstring heap_str = evstring_new(view);
|
||||
assert(heap_str != NULL);
|
||||
assert(strcmp(heap_str, stack_str) == 0);
|
||||
assert(evstring_getLength(heap_str) == evstring_getLength(stack_str));
|
||||
|
||||
evstring_free(heap_str);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
#define EV_STR_IMPLEMENTATION
|
||||
#include "ev_str.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
evstring stack_str = evstr("abc");
|
||||
assert(evstring_getSpace(stack_str) == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#define EV_STR_IMPLEMENTATION
|
||||
#include "ev_str.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
static evstring global_str = evstr("Global 'Hello, World!'");
|
||||
|
||||
int main(void)
|
||||
{
|
||||
const evstring stack_str = evstr("Stack 'Hello, World!'");
|
||||
assert(strcmp(stack_str, "Stack 'Hello, World!'") == 0);
|
||||
assert(evstring_getLength(stack_str) == 21);
|
||||
|
||||
assert(strcmp(global_str, "Global 'Hello, World!'") == 0);
|
||||
assert(evstring_getLength(global_str) == 22);
|
||||
|
||||
evstring heap_str = evstring_new("Heap 'Hello, World!'");
|
||||
assert(heap_str != NULL);
|
||||
assert(strcmp(heap_str, "Heap 'Hello, World!'") == 0);
|
||||
assert(evstring_getLength(heap_str) == 20);
|
||||
|
||||
evstring_free(heap_str);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
tests = [
|
||||
'tostr',
|
||||
]
|
||||
|
||||
foreach t : tests
|
||||
exec = executable(t, t+'.c', include_directories: headers_include, c_args: evh_c_args)
|
||||
test(t, exec, suite: 'types')
|
||||
endforeach
|
||||
@@ -0,0 +1,40 @@
|
||||
#include <stdio.h>
|
||||
#include "ev_types.h"
|
||||
#include "ev_numeric.h"
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
int age;
|
||||
char *desc;
|
||||
} Person;
|
||||
|
||||
DEFINE_TOSTR_FUNCTION(Person, PERSON_PRINT)
|
||||
{
|
||||
sprintf(out, "%s:\n\tage: %d\n\tdesc: %s", self->name, self->age, self->desc);
|
||||
}
|
||||
|
||||
TYPEDATA_GEN(Person,
|
||||
TOSTR(PERSON_PRINT),
|
||||
DEFAULT(
|
||||
.name = "sisyphus",
|
||||
.age = 9999,
|
||||
.desc = "One can only imagine him happy"
|
||||
),
|
||||
INVALID(
|
||||
.name = NULL,
|
||||
.age = -1,
|
||||
.desc = NULL
|
||||
)
|
||||
);
|
||||
|
||||
int main()
|
||||
{
|
||||
puts("");
|
||||
char out[256] = {};
|
||||
|
||||
Person sisyphue = EV_DEFAULT(Person);
|
||||
EV_TOSTR(Person)(&sisyphue, out);
|
||||
|
||||
puts(out);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
tests = [
|
||||
'zero_cap_grow',
|
||||
'reducecap_updatelen',
|
||||
'reducecap_free_elems',
|
||||
'reducelen_free_elems',
|
||||
]
|
||||
|
||||
foreach t : tests
|
||||
exec = executable(t, t+'.c', dependencies: [vec_dep], c_args: evh_c_args)
|
||||
test(t, exec, suite: 'vec')
|
||||
endforeach
|
||||
@@ -0,0 +1,28 @@
|
||||
#define EV_VEC_IMPLEMENTATION
|
||||
#include "ev_vec.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
static int free_calls = 0;
|
||||
|
||||
static void count_free(void *self)
|
||||
{
|
||||
(void)self;
|
||||
free_calls++;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ev_vec(i32) v = ev_vec_init(i32, free = count_free);
|
||||
assert(v != NULL);
|
||||
|
||||
for(i32 i = 0; i < 5; i++) {
|
||||
assert(ev_vec_push_impl(&v, &i) >= 0);
|
||||
}
|
||||
|
||||
free_calls = 0;
|
||||
assert(ev_vec_setcapacity(&v, 3) == EV_VEC_ERR_NONE);
|
||||
assert(free_calls == 2);
|
||||
|
||||
ev_vec_fini(&v);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#define EV_VEC_IMPLEMENTATION
|
||||
#include "ev_vec.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
assert(EV_VEC_GROWTH_RATE > 1);
|
||||
|
||||
ev_vec(i32) v = ev_vec_init(i32);
|
||||
assert(v != NULL);
|
||||
|
||||
for(i32 i = 0; i < 5; i++) {
|
||||
assert(ev_vec_push_impl(&v, &i) >= 0);
|
||||
}
|
||||
|
||||
ev_vec_error_t err = ev_vec_setcapacity(&v, 2);
|
||||
assert(err != EV_VEC_ERR_NONE || ev_vec_len(&v) <= ev_vec_capacity(&v));
|
||||
|
||||
ev_vec_fini(&v);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#define EV_VEC_IMPLEMENTATION
|
||||
#include "ev_vec.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
static int free_calls = 0;
|
||||
|
||||
static void count_free(void *self)
|
||||
{
|
||||
(void)self;
|
||||
free_calls++;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ev_vec(i32) v = ev_vec_init(i32, free = count_free);
|
||||
assert(v != NULL);
|
||||
|
||||
free_calls = 0;
|
||||
assert(ev_vec_setlen(&v, 3) == EV_VEC_ERR_NONE);
|
||||
assert(ev_vec_setlen(&v, 1) == EV_VEC_ERR_NONE);
|
||||
assert(free_calls == 2);
|
||||
|
||||
ev_vec_fini(&v);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#define EV_VEC_IMPLEMENTATION
|
||||
#include "ev_vec.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ev_vec(i32) v = ev_vec_init(i32);
|
||||
assert(v != NULL);
|
||||
|
||||
assert(ev_vec_setcapacity(&v, 0) == EV_VEC_ERR_NONE);
|
||||
assert(ev_vec_capacity(&v) == 0);
|
||||
assert(ev_vec_grow(&v) == EV_VEC_ERR_NONE);
|
||||
assert(ev_vec_capacity(&v) > 0);
|
||||
|
||||
ev_vec_fini(&v);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
subdir('ev_log')
|
||||
subdir('ev_str')
|
||||
subdir('ev_types')
|
||||
subdir('ev_vec')
|
||||
Reference in New Issue
Block a user