diff --git a/sqlite-vec.c b/sqlite-vec.c index 1265c18..87ba10a 100644 --- a/sqlite-vec.c +++ b/sqlite-vec.c @@ -3427,7 +3427,7 @@ void vec0_free(vec0_vtab *p) { } } -inline int vec0_num_defined_user_columns(vec0_vtab *p) { +int vec0_num_defined_user_columns(vec0_vtab *p) { return p->numVectorColumns + p->numPartitionColumns; } diff --git a/tests/test-unit.c b/tests/test-unit.c new file mode 100644 index 0000000..107945d --- /dev/null +++ b/tests/test-unit.c @@ -0,0 +1,51 @@ +#include "../sqlite-vec.h" +#include +#include +#include + +#define countof(x) (sizeof(x) / sizeof((x)[0])) + +void test_vec0_parse_partition_key_definition() { + typedef struct { + char * test; + int expected_rc; + const char *expected_column_name; + int expected_column_type; + } TestCase; + + TestCase suite[] = { + {"user_id integer partition key", SQLITE_OK, "user_id", SQLITE_INTEGER}, + {"USER_id int partition key", SQLITE_OK, "USER_id", SQLITE_INTEGER}, + {"category text partition key", SQLITE_OK, "category", SQLITE_TEXT}, + + {"", SQLITE_EMPTY, "", 0}, + {"document_id text primary key", SQLITE_EMPTY, "", 0}, + {"document_id text partition keyy", SQLITE_EMPTY, "", 0}, + }; + for(int i = 0; i < countof(suite); i++) { + char * out_column_name; + int out_column_name_length; + int out_column_type; + int rc; + rc = vec0_parse_partition_key_definition( + suite[i].test, + strlen(suite[i].test), + &out_column_name, + &out_column_name_length, + &out_column_type + ); + assert(rc == suite[i].expected_rc); + + if(rc == SQLITE_OK) { + assert(out_column_name_length == strlen(suite[i].expected_column_name)); + assert(strncmp(out_column_name, suite[i].expected_column_name, out_column_name_length) == 0); + assert(out_column_type == suite[i].expected_column_type); + } + + printf("✅ %s\n", suite[i].test); + } +} + +int main() { + test_vec0_parse_partition_key_definition(); +}