Skip to content

Commit

Permalink
unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
asg017 committed Nov 5, 2024
1 parent 776d86c commit f36d4a0
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sqlite-vec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
51 changes: 51 additions & 0 deletions tests/test-unit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "../sqlite-vec.h"
#include <stdio.h>
#include <string.h>
#include <assert.h>

#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();
}

0 comments on commit f36d4a0

Please sign in to comment.