2024-06-13 15:28:21 +02:00
|
|
|
#include "../src/StringView/StringView.h"
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
void test_split(void)
|
|
|
|
{
|
|
|
|
const char* source = "this,is,a,csv,header";
|
|
|
|
|
|
|
|
StringView sourceSV = StringView_FromString(source);
|
|
|
|
StringView delim = StringView_FromString(",");
|
|
|
|
StringView split;
|
|
|
|
|
|
|
|
assert(StringView_NextSplit(&split, &sourceSV, delim));
|
|
|
|
assert(StringView_Equal(split, StringView_FromString("this")));
|
|
|
|
|
|
|
|
assert(StringView_NextSplit(&split, &sourceSV, delim));
|
|
|
|
assert(StringView_Equal(split, StringView_FromString("is")));
|
|
|
|
|
|
|
|
assert(StringView_NextSplit(&split, &sourceSV, delim));
|
|
|
|
assert(StringView_Equal(split, StringView_FromString("a")));
|
|
|
|
|
|
|
|
assert(StringView_NextSplit(&split, &sourceSV, delim));
|
|
|
|
assert(StringView_Equal(split, StringView_FromString("csv")));
|
|
|
|
|
|
|
|
assert(StringView_NextSplit(&split, &sourceSV, delim));
|
|
|
|
assert(StringView_Equal(split, StringView_FromString("header")));
|
|
|
|
|
|
|
|
assert(! StringView_NextSplit(&split, &sourceSV, delim));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-09-23 18:37:54 +02:00
|
|
|
void test_fext(void)
|
|
|
|
{
|
|
|
|
const char* filepath = "database.sqlite.old";
|
|
|
|
|
|
|
|
StringView sourceSV = StringView_FromString(filepath);
|
|
|
|
StringView delim = StringView_FromString(".");
|
|
|
|
StringView split;
|
|
|
|
|
|
|
|
assert(StringView_LastSplit(&split, &sourceSV, delim));
|
|
|
|
assert(StringView_Equal(split, StringView_FromString("old")));
|
|
|
|
assert(StringView_Equal(sourceSV, StringView_FromString("database.sqlite")));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-06-13 15:28:21 +02:00
|
|
|
int main()
|
|
|
|
{
|
|
|
|
test_split();
|
2024-09-23 18:37:54 +02:00
|
|
|
test_fext();
|
2024-06-13 15:28:21 +02:00
|
|
|
return 0;
|
|
|
|
}
|