null+****@clear*****
null+****@clear*****
2010年 7月 8日 (木) 13:47:37 JST
Kouhei Sutou 2010-07-08 04:47:37 +0000 (Thu, 08 Jul 2010) New Revision: b6981db129118943c34e239c615843946afdb0d5 Log: add inspector for type. Modified files: lib/util.c test/unit/core/test-inspect.c Modified: lib/util.c (+46 -0) =================================================================== --- lib/util.c 2010-07-08 04:38:10 +0000 (d105dcb) +++ lib/util.c 2010-07-08 04:47:37 +0000 (21f2d42) @@ -69,6 +69,49 @@ grn_accessor_inspect(grn_ctx *ctx, grn_obj *buf, grn_obj *obj) } static grn_rc +grn_type_inspect(grn_ctx *ctx, grn_obj *buf, grn_obj *obj) +{ + int name_size; + grn_id range_id; + + GRN_TEXT_PUTS(ctx, buf, "#<type "); + name_size = grn_obj_name(ctx, obj, NULL, 0); + if (name_size) { + grn_bulk_space(ctx, buf, name_size); + grn_obj_name(ctx, obj, GRN_BULK_CURR(buf) - name_size, name_size); + } + + range_id = grn_obj_get_range(ctx, obj); + GRN_TEXT_PUTS(ctx, buf, " size:"); + grn_text_lltoa(ctx, buf, range_id); + + GRN_TEXT_PUTS(ctx, buf, " type:"); + if (obj->header.flags & GRN_OBJ_KEY_VAR_SIZE) { + GRN_TEXT_PUTS(ctx, buf, "var_size"); + } else { + switch (obj->header.flags & GRN_OBJ_KEY_MASK) { + case GRN_OBJ_KEY_UINT : + GRN_TEXT_PUTS(ctx, buf, "uint"); + break; + case GRN_OBJ_KEY_INT : + GRN_TEXT_PUTS(ctx, buf, "int"); + break; + case GRN_OBJ_KEY_FLOAT : + GRN_TEXT_PUTS(ctx, buf, "float"); + break; + case GRN_OBJ_KEY_GEO_POINT : + GRN_TEXT_PUTS(ctx, buf, "geo_point"); + break; + default : + break; + } + } + + GRN_TEXT_PUTS(ctx, buf, ">"); + return GRN_SUCCESS; +} + +static grn_rc grn_column_inspect_common(grn_ctx *ctx, grn_obj *buf, grn_obj *obj) { int name_size; @@ -229,6 +272,9 @@ grn_inspect(grn_ctx *ctx, grn_obj *buffer, grn_obj *obj) case GRN_ACCESSOR_VIEW : grn_accessor_inspect(ctx, buffer, obj); return buffer; + case GRN_TYPE : + grn_type_inspect(ctx, buffer, obj); + return buffer; case GRN_COLUMN_FIX_SIZE : grn_ra_inspect(ctx, buffer, obj); return buffer; Modified: test/unit/core/test-inspect.c (+16 -0) =================================================================== --- test/unit/core/test-inspect.c 2010-07-08 04:38:10 +0000 (683ca72) +++ test/unit/core/test-inspect.c 2010-07-08 04:47:37 +0000 (6afe64b) @@ -62,6 +62,7 @@ void test_accessor_dynamic_pseudo_column_name(gconstpointer data); void test_column_fix_size(void); void test_column_var_size(void); void test_column_index(void); +void test_type(void); static gchar *tmp_directory; @@ -638,3 +639,18 @@ test_column_index(void) ">", inspected_string()); } + +void +test_type(void) +{ + grn_obj *type; + + type = get_object("ShortText"); + inspected = grn_inspect(context, NULL, type); + cut_assert_equal_string("#<type " + "ShortText " + "size:4096 " + "type:var_size" + ">", + inspected_string()); +}