mirror of
https://github.com/asg017/sqlite-vec.git
synced 2026-04-25 08:46:49 +02:00
unit tests
This commit is contained in:
parent
776d86cc0c
commit
f36d4a02c6
2 changed files with 52 additions and 1 deletions
|
|
@ -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;
|
return p->numVectorColumns + p->numPartitionColumns;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
51
tests/test-unit.c
Normal file
51
tests/test-unit.c
Normal file
|
|
@ -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();
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue