diff --git a/defines.h b/defines.h index f518492..f9ee939 100644 --- a/defines.h +++ b/defines.h @@ -78,7 +78,7 @@ # endif #endif -#if !defined(EV_BUILDTYPE_DEBUG) && !defined(EV_BUILDTYPE_DEBUG_OPT) && !defined(EV_BUILDTYPE_RELEASE) +#if !defined(EV_BUILDTYPE_DEBUG) && !defined(EV_BUILDTYPE_DEBUGOPT) && !defined(EV_BUILDTYPE_RELEASE) #define EV_BUILDTYPE_RELEASE 1 #endif diff --git a/ev_str.h b/ev_str.h index 2ef1bb1..2f19d10 100644 --- a/ev_str.h +++ b/ev_str.h @@ -330,7 +330,7 @@ evstring_free( { evstr_asserttype(s); if(META(s)->allocationType == EV_STR_ALLOCATION_TYPE_HEAP) { - free(META(s)); + ev_str_free(META(s)); } } @@ -546,9 +546,10 @@ __evstring_findFirst_impl( }; for(u64 i = text.offset; i < text.offset + text.len; i++) { - if(text.data[i] == query.data[query.offset + found_progress]) { + if(text.data[i] == query.data[query.offset + found_progress]) found_progress++; - } + else + found_progress = 0; if(found_progress == query.len) { result.offset = (i+1) - query.len; result.len = query.len; diff --git a/meson.build b/meson.build index 263b9cd..c4423a4 100644 --- a/meson.build +++ b/meson.build @@ -43,6 +43,8 @@ headers_dep = declare_dependency( # Tests str_test = executable('str_test', 'str_test.c', dependencies: [str_dep], c_args: evh_c_args) test('evstr', str_test) +vec_test = executable('vec_test', 'vec_test.c', dependencies: [vec_dep], c_args: evh_c_args) +test('evvec', vec_test) log_test = executable('log_test', 'log_test.c', dependencies: [log_dep], c_args: evh_c_args) test('evlog', log_test) diff --git a/str_test.c b/str_test.c index 5236f9c..ff6b773 100644 --- a/str_test.c +++ b/str_test.c @@ -77,5 +77,30 @@ int main() evstring_free(heap_str); } + { // Incorrectly handled mismatches + evstring text = evstr("aab"); + evstring query = evstr("ab"); + evstring_view match = evstring_findFirst(text, query); + assert(match.len == 2); + assert(match.offset == 1); + } + + { // Underflowing getSpace for stack strings + evstring stack_str = evstr("abc"); + assert(evstring_getSpace(stack_str) == 0); + } + + { // Overlapping push + 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; } diff --git a/vec_test.c b/vec_test.c new file mode 100644 index 0000000..88883d5 --- /dev/null +++ b/vec_test.c @@ -0,0 +1,22 @@ +#define EV_VEC_IMPLEMENTATION +#include "ev_vec.h" + +#include + +int main(void) +{ + { + 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; +}