Refactor string tests

This commit is contained in:
Gregory Lirent 2022-06-04 22:17:26 +03:00
parent f6033d0c4f
commit a6a623bff6
3 changed files with 30 additions and 26 deletions

View File

@ -3,6 +3,29 @@
#include "plug.h"
static void string_concat_random(vtype_string* x, unsigned int n) {
char* v;
if (random_boolean()) {
v = random_utf8_cstring(n);
} else v = random_ascii_cstring(n);
string_concat(x, v);
free(v);
}
static void string_replace_random(vtype_string* x, unsigned int n) {
char* v;
if (random_boolean()) {
v = random_utf8_cstring(n);
} else v = random_ascii_cstring(n);
string_replace(x, x, v, -1);
free(v);
}
static void string_print_compare(const vtype_string* s0, const vtype_string* s1) {
int c = string_compare(s0, s1);
char* m;

View File

@ -68,26 +68,3 @@ static vtype_string string_random(unsigned int n) {
return x;
}
static void string_concat_random(vtype_string* x, unsigned int n) {
char* v;
if (random_boolean()) {
v = random_utf8_cstring(n);
} else v = random_ascii_cstring(n);
string_concat(x, v);
free(v);
}
static void string_replace_random(vtype_string* x, unsigned int n) {
char* v;
if (random_boolean()) {
v = random_utf8_cstring(n);
} else v = random_ascii_cstring(n);
string_replace(x, x, v, -1);
free(v);
}

View File

@ -12,17 +12,21 @@ int main(int argc, char** argv) {
x = string_random(12);
string_align_center(&x, 30, 0);
string_info(&x);
string_print(&x, 0);
string_trim_spaces(&x);
string_print(&x, 0);
string_info(&x);
string_print(&x, "trimmed");
put_separator();
string_align_center(&x, 30, c);
string_info(&x);
string_print(&x, 0);
string_trim(&x, c);
string_print(&x, 0);
string_info(&x);
string_print(&x, "trimmed");
string_free(&x);