46 lines
1.2 KiB
C
46 lines
1.2 KiB
C
#include "../include/vstr.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#ifdef NDEBUG
|
|
#define TEST(expr)
|
|
#else
|
|
#define TEST(expr) \
|
|
do { \
|
|
if (expr) { \
|
|
printf(__DATE__" " __TIME__ " [%s@%d] " "\x1b[32m" "| PASSED | " "(%s)" "\x1b[0m \n", __FILE__, __LINE__, #expr); \
|
|
} else { \
|
|
printf(__DATE__" " __TIME__ " [%s@%d] " "\x1b[31m" "| FAILED | " "(%s)" "\x1b[0m \n", __FILE__, __LINE__, #expr); \
|
|
} \
|
|
} while (0)
|
|
#endif
|
|
|
|
int main(void){
|
|
|
|
const char *s = "Hello World";
|
|
const char *left = " Hello World";
|
|
Vstr v = vstr_n(s,strlen(s));
|
|
Vstr l = vstr_n(left,strlen(left));
|
|
|
|
TEST(strncmp(s,v.buf,v.len) == 0);
|
|
|
|
TEST(strncmp(s,l.buf,l.len) != 0);
|
|
l = vstr_trim_left(v);
|
|
|
|
TEST(strncmp(s,l.buf,l.len) == 0);
|
|
Vstr b = vstr_before_delim(l," ");
|
|
Vstr a = vstr_after_delim(l," ");
|
|
const char *bs = "Hello";
|
|
const char *as = "World";
|
|
|
|
Vstr bc = vstr_n(bs,strlen(bs));
|
|
Vstr ac = vstr_n(as,strlen(as));
|
|
TEST(strncmp("Hello",b.buf,b.len) == 0);
|
|
TEST(strncmp("World",a.buf,a.len) == 0);
|
|
TEST(vstr_cmp(b,bc) == 0);
|
|
TEST(vstr_cmp(a,ac) == 0);
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|