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,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;
|
||||
}
|
||||
Reference in New Issue
Block a user