Initial commit

This commit is contained in:
2026-01-17 12:19:24 -06:00
commit a2dbda162f
17 changed files with 563 additions and 0 deletions

15
tests/01_sv_str.c Normal file
View File

@@ -0,0 +1,15 @@
#define DEBUG
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "../include/sv.h"
int main(void){
const char *s = "Hello World!";
SV sv = sv_str(s);
assert(sv.buf != NULL);
assert(strlen(s) == sv.len);
assert( memcmp(sv.buf, s, strlen(s) ) == 0);
return EXIT_SUCCESS;
}

15
tests/02_sv_strn.c Normal file
View File

@@ -0,0 +1,15 @@
#define DEBUG
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "../include/sv.h"
int main(void){
const char *s = "Hello World!";
SV sv = sv_strn(s, strlen(s));
assert(sv.buf != NULL);
assert(strlen(s) == sv.len);
assert( memcmp(sv.buf, s, strlen(s) ) == 0);
return EXIT_SUCCESS;
}

24
tests/03_trim_left.c Normal file
View File

@@ -0,0 +1,24 @@
#define DEBUG
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include "../include/sv.h"
int main(void){
const char *s = " Hello World!";
const char *s2 = "Hello World!";
SV sv = sv_str(s);
assert(sv.buf != NULL);
assert(strlen(s) == sv.len);
assert( memcmp(sv.buf, s, strlen(s)) == 0);
SV sv2 = sv_trim_left(sv);
assert(sv2.len != strlen(s));
assert( memcmp(sv2.buf, s, sv2.len) != 0);
assert( memcmp(sv2.buf, s2, sv2.len) == 0);
assert( sv2.len == strlen(s2));
return EXIT_SUCCESS;
}

21
tests/04_trim_right.c Normal file
View File

@@ -0,0 +1,21 @@
#define DEBUG
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include "../include/sv.h"
int main(void){
const char *s = "Hello World! ";
const char *s2 = "Hello World!";
SV sv = sv_str(s);
assert(sv.buf != NULL);
assert(strlen(s) == sv.len);
assert( memcmp(sv.buf, s, strlen(s)) == 0);
SV sv2 = sv_trim_right(sv);
assert(sv2.len == strlen(s2));
assert(memcmp(s2, sv2.buf, sv2.len) == 0);
assert(sv2.len != strlen(s));
return EXIT_SUCCESS;
}

22
tests/05_trim.c Normal file
View File

@@ -0,0 +1,22 @@
#define DEBUG
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include "../include/sv.h"
int main(void){
const char *s = " Hello World! ";
const char *s2 = "Hello World!";
SV sv = sv_str(s);
assert(sv.buf != NULL);
assert(strlen(s) == sv.len);
assert( memcmp(sv.buf, s, strlen(s)) == 0);
SV sv2 = sv_trim(sv);
assert(sv2.len == strlen(s2));
assert(memcmp(s2, sv2.buf, sv2.len) == 0);
assert(sv2.len != strlen(s));
assert( memcmp(s, sv2.buf, sv2.len) != 0);
return EXIT_SUCCESS;
}

25
tests/06_sv_eq.c Normal file
View File

@@ -0,0 +1,25 @@
#define DEBUG
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include "../include/sv.h"
int main(void){
const char *s = " Hello World! ";
const char *s2 = "Hello World!";
SV sv = sv_str(s);
SV sv3 = sv_str(s2);
assert(sv.buf != NULL);
assert(strlen(s) == sv.len);
assert( memcmp(sv.buf, s, strlen(s)) == 0);
SV sv2 = sv_trim(sv);
assert(sv2.len == strlen(s2));
assert(memcmp(s2, sv2.buf, sv2.len) == 0);
assert(sv2.len != strlen(s));
assert( memcmp(s, sv2.buf, sv2.len) != 0);
assert( !sv_eq(sv, sv2));
assert( sv_eq(sv2,sv3));
return EXIT_SUCCESS;
}

29
tests/07_case_cmp.c Normal file
View File

@@ -0,0 +1,29 @@
#define DEBUG
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include "../include/sv.h"
int main(void){
const char *s = " Hello World! ";
const char *s2 = "Hello World!";
const char *s3 = "hElLo wOrLD!";
const char *s4 = "Goodbye World!";
SV sv = sv_str(s);
SV sv3 = sv_str(s3);
SV sv4 = sv_str(s4);
assert(sv.buf != NULL);
assert(strlen(s) == sv.len);
assert( memcmp(sv.buf, s, strlen(s)) == 0);
SV sv2 = sv_trim(sv);
assert(sv2.len == strlen(s2));
assert(memcmp(s2, sv2.buf, sv2.len) == 0);
assert(sv2.len != strlen(s));
assert( memcmp(s, sv2.buf, sv2.len) != 0);
assert( !sv_eq(sv, sv2));
assert( sv_casecmp(sv2,sv3) == 0);
assert( sv_casecmp(sv3,sv4) == 1);
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,18 @@
#define DEBUG
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include "../include/sv.h"
int main(void){
const char *s = "Hello World!,Goodbye World!";
const char *s3 = "Hello World!";
struct String_View sv = sv_strn(s, strlen(s));
struct String_View sv2 = sv_before_delim(sv,",");
assert(sv2.len == strlen(s3));
assert( memcmp(sv2.buf, s3, sv2.len) == 0);
return EXIT_SUCCESS;
}

18
tests/09_after_delims.c Normal file
View File

@@ -0,0 +1,18 @@
#define DEBUG
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include "../include/sv.h"
int main(void){
const char *s = "Hello World!,Goodbye World!";
const char *s3 = "Goodbye World!";
struct String_View sv = sv_strn(s, strlen(s));
struct String_View sv2 = sv_after_delim(sv,",");
assert(sv2.len == strlen(s3));
assert( memcmp(sv2.buf, s3, sv2.len) == 0);
return EXIT_SUCCESS;
}

20
tests/10_strstr.c Normal file
View File

@@ -0,0 +1,20 @@
#define DEBUG
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include "../include/sv.h"
int main(void){
const char *s = "Hello World!,Goodbye World!";
const char *n = "Goodbye";
const char *test = "Goodbye World!";
struct String_View sv = sv_strn(s, strlen(s));
struct String_View sv2 = sv_strn(n, strlen(n));
struct String_View found = sv_str_str(sv, sv2);
assert(found.len == strlen(test));
assert( memcmp(found.buf, test, found.len) == 0);
return EXIT_SUCCESS;
}

24
tests/11_sv_pack.c Normal file
View File

@@ -0,0 +1,24 @@
#define DEBUG
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <stdint.h>
#include <stdio.h>
#include "../include/sv.h"
int main(void){
const char *s = "Hello";
struct String_View sv = sv_strn(s, strlen(s));
size_t offset = sv_pack_size(sv);
unsigned char *buf = malloc(offset);
sv_pack(buf, sv);
struct String_View out = sv_unpack(buf);
assert(out.len == strlen(s));
assert( memcmp(out.buf, s, out.len) == 0);
assert( sv_eq(sv, out));
assert( sv_casecmp(sv, out ) == 0);
free(buf);
return EXIT_SUCCESS;
}

21
tests/12_sv_pack2.c Normal file
View File

@@ -0,0 +1,21 @@
#define DEBUG
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <stdint.h>
#include <stdio.h>
#include "../include/sv.h"
int main(void){
const char *s = "Hello";
size_t offset = strlen(s) + sizeof(uint64_t);
unsigned char *buf = malloc(offset);
struct String_View sv = sv_strn(s, strlen(s));
sv_pack(buf, sv);
struct String_View out = sv_unpack(buf);
assert(out.len == strlen(s));
assert( memcmp(out.buf, s, out.len) == 0);
free(buf);
return EXIT_SUCCESS;
}