Navigation Menu

Skip to content

Commit

Permalink
Add grn_obj_is_tokenizer_proc()
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Oct 19, 2015
1 parent 1a6d14f commit a5e8ba7
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/groonga/obj.h
Expand Up @@ -27,6 +27,7 @@ GRN_API grn_bool grn_obj_is_builtin(grn_ctx *ctx, grn_obj *obj);
GRN_API grn_bool grn_obj_is_table(grn_ctx *ctx, grn_obj *obj);
GRN_API grn_bool grn_obj_is_type(grn_ctx *ctx, grn_obj *obj);
GRN_API grn_bool grn_obj_is_proc(grn_ctx *ctx, grn_obj *obj);
GRN_API grn_bool grn_obj_is_tokenizer_proc(grn_ctx *ctx, grn_obj *obj);
GRN_API grn_bool grn_obj_is_function_proc(grn_ctx *ctx, grn_obj *obj);
GRN_API grn_bool grn_obj_is_selector_proc(grn_ctx *ctx, grn_obj *obj);
GRN_API grn_bool grn_obj_is_selector_only_proc(grn_ctx *ctx, grn_obj *obj);
Expand Down
13 changes: 13 additions & 0 deletions lib/obj.c
Expand Up @@ -76,6 +76,19 @@ grn_obj_is_proc(grn_ctx *ctx, grn_obj *obj)
return obj->header.type == GRN_PROC;
}

grn_bool
grn_obj_is_tokenizer_proc(grn_ctx *ctx, grn_obj *obj)
{
grn_proc *proc;

if (!grn_obj_is_proc(ctx, obj)) {
return GRN_FALSE;
}

proc = (grn_proc *)obj;
return proc->type == GRN_PROC_TOKENIZER;
}

grn_bool
grn_obj_is_function_proc(grn_ctx *ctx, grn_obj *obj)
{
Expand Down
34 changes: 34 additions & 0 deletions test/unit/core/test-object.c
Expand Up @@ -33,6 +33,8 @@ void data_is_type(void);
void test_is_type(gconstpointer data);
void data_is_proc(void);
void test_is_proc(gconstpointer data);
void data_is_tokenizer_proc(void);
void test_is_tokenizer_proc(gconstpointer data);
void data_is_function_proc(void);
void test_is_function_proc(gconstpointer data);
void data_is_selector_proc(void);
Expand Down Expand Up @@ -231,6 +233,38 @@ test_is_proc(gconstpointer data)
}
}

void
data_is_tokenizer_proc(void)
{
#define ADD_DATUM(expected, name) \
gcut_add_datum((expected ? \
"tokenizer-proc - " name : \
"not tokenizer-proc - " name), \
"expected", G_TYPE_BOOLEAN, expected, \
"name", G_TYPE_STRING, name, \
NULL)

ADD_DATUM(TRUE, "TokenBigram");
ADD_DATUM(FALSE, "status");

#undef ADD_DATUM
}

void
test_is_tokenizer_proc(gconstpointer data)
{
const gchar *name;
grn_obj *object;

name = gcut_data_get_string(data, "name");
object = grn_ctx_get(context, name, strlen(name));
if (gcut_data_get_string(data, "expected")) {
cut_assert_true(grn_obj_is_tokenizer_proc(context, object));
} else {
cut_assert_false(grn_obj_is_tokenizer_proc(context, object));
}
}

void
data_is_function_proc(void)
{
Expand Down

0 comments on commit a5e8ba7

Please sign in to comment.