[Groonga-commit] groonga/groonga [master] support record uvector inspection.

Back to archive index

null+****@clear***** null+****@clear*****
2010年 7月 15日 (木) 17:25:59 JST


Kouhei Sutou	2010-07-15 08:25:59 +0000 (Thu, 15 Jul 2010)

  New Revision: e139b59e96041d0fdcb206e79fc8a17e36552f33

  Log:
    support record uvector inspection.

  Modified files:
    lib/util.c
    test/unit/core/test-inspect.c

  Modified: lib/util.c (+41 -0)
===================================================================
--- lib/util.c    2010-07-15 08:10:04 +0000 (5a3c7f9)
+++ lib/util.c    2010-07-15 08:25:59 +0000 (70ecd70)
@@ -392,6 +392,8 @@ grn_record_inspect(grn_ctx *ctx, grn_obj *buf, grn_obj *obj)
   table = grn_ctx_at(ctx, obj->header.domain);
   GRN_TEXT_PUTS(ctx, buf, "#<record:");
   grn_table_type_inspect(ctx, buf, table);
+  GRN_TEXT_PUTS(ctx, buf, ":");
+  grn_name_inspect(ctx, buf, table);
 
   GRN_TEXT_PUTS(ctx, buf, " id:");
   id = GRN_RECORD_VALUE(obj);
@@ -437,6 +439,29 @@ grn_record_inspect(grn_ctx *ctx, grn_obj *buf, grn_obj *obj)
   return GRN_SUCCESS;
 }
 
+static grn_rc
+grn_uvector_record_inspect(grn_ctx *ctx, grn_obj *buf, grn_obj *obj)
+{
+  int i;
+  grn_id *v, *ve;
+  grn_obj record;
+
+  v = (grn_id *)GRN_BULK_HEAD(obj);
+  ve = (grn_id *)GRN_BULK_CURR(obj);
+  GRN_RECORD_INIT(&record, 0, obj->header.domain);
+  GRN_TEXT_PUTS(ctx, buf, "[");
+  while (v < ve) {
+    if (i++ > 0) { GRN_TEXT_PUTS(ctx, buf, ", "); }
+    GRN_RECORD_SET(ctx, &record, *v);
+    grn_inspect(ctx, buf, &record);
+    v++;
+  }
+  GRN_TEXT_PUTS(ctx, buf, "]");
+  GRN_OBJ_FIN(ctx, &record);
+
+  return GRN_SUCCESS;
+}
+
 grn_obj *
 grn_inspect(grn_ctx *ctx, grn_obj *buffer, grn_obj *obj)
 {
@@ -468,6 +493,22 @@ grn_inspect(grn_ctx *ctx, grn_obj *buffer, grn_obj *obj)
       }
     }
     break;
+  case GRN_UVECTOR :
+    domain = grn_ctx_at(ctx, obj->header.domain);
+    if (domain) {
+      grn_id type = domain->header.type;
+      grn_obj_unlink(ctx, domain);
+      switch (type) {
+      case GRN_TABLE_HASH_KEY :
+      case GRN_TABLE_PAT_KEY :
+      case GRN_TABLE_NO_KEY :
+        grn_uvector_record_inspect(ctx, buffer, obj);
+        return buffer;
+      default :
+        break;
+      }
+    }
+    break;
   case GRN_EXPR :
     grn_expr_inspect(ctx, buffer, obj);
     return buffer;

  Modified: test/unit/core/test-inspect.c (+6 -2)
===================================================================
--- test/unit/core/test-inspect.c    2010-07-15 08:10:04 +0000 (e6dd6ed)
+++ test/unit/core/test-inspect.c    2010-07-15 08:25:59 +0000 (fb198f7)
@@ -502,7 +502,11 @@ test_uvector_with_records(void)
   GRN_RECORD_PUT(context, uvector, 1);
   GRN_RECORD_PUT(context, uvector, 2);
   inspected = grn_inspect(context, NULL, uvector);
-  cut_assert_equal_string("[\"groonga.org\",\"razil.jp\"]", inspected_string());
+  cut_assert_equal_string("["
+                          "#<record:pat:Sites id:1 key:\"groonga.org\">, "
+                          "#<record:pat:Sites id:2 key:\"razil.jp\">"
+                          "]",
+                          inspected_string());
 }
 
 void
@@ -725,7 +729,7 @@ test_record(void)
                         grn_obj_id(context, get_object("Sites")));
   GRN_RECORD_SET(context, record, 1);
   inspected = grn_inspect(context, NULL, record);
-  cut_assert_equal_string("#<record:hash "
+  cut_assert_equal_string("#<record:hash:Sites "
                           "id:1 "
                           "key:\"groonga.org\" "
                           "name:\"groonga\""




Groonga-commit メーリングリストの案内
Back to archive index