[Groonga-commit] groonga/groonga [master] add a test for prefix search in --filter.

Back to archive index

null+****@clear***** null+****@clear*****
2011年 3月 25日 (金) 16:12:07 JST


Kouhei Sutou	2011-03-25 07:12:07 +0000 (Fri, 25 Mar 2011)

  New Revision: cd862867c9d79b9d39b8d38527771fb685b814ff

  Log:
    add a test for prefix search in --filter.

  Added files:
    test/unit/core/test-command-select-filter.c
  Modified files:
    test/unit/core/Makefile.am

  Modified: test/unit/core/Makefile.am (+2 -0)
===================================================================
--- test/unit/core/Makefile.am    2011-03-15 07:42:24 +0000 (900450a)
+++ test/unit/core/Makefile.am    2011-03-25 07:12:07 +0000 (a6cbe28)
@@ -47,6 +47,7 @@ noinst_LTLIBRARIES =				\
 	test-command-select-prefix-search.la	\
 	test-command-select-filter-invalid.la	\
 	test-command-select-query.la		\
+	test-command-select-filter.la		\
 	test-command-define-selector.la		\
 	test-command-cache-limit.la		\
 	test-command-delete.la			\
@@ -123,6 +124,7 @@ test_command_select_sort_la_SOURCES	= test-command-select-sort.c
 test_command_select_prefix_search_la_SOURCES	= test-command-select-prefix-search.c
 test_command_select_filter_invalid_la_SOURCES	= test-command-select-filter-invalid.c
 test_command_select_query_la_SOURCES	= test-command-select-query.c
+test_command_select_filter_la_SOURCES	= test-command-select-filter.c
 test_command_define_selector_la_SOURCES	= test-command-define-selector.c
 test_command_cache_limit_la_SOURCES	= test-command-cache-limit.c
 test_command_delete_la_SOURCES		= test-command-delete.c

  Added: test/unit/core/test-command-select-filter.c (+97 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/core/test-command-select-filter.c    2011-03-25 07:12:07 +0000 (307463a)
@@ -0,0 +1,97 @@
+/* -*- c-basic-offset: 2; coding: utf-8 -*- */
+/*
+  Copyright(C) 2011 Kouhei Sutou <kou****@clear*****>
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+#include "str.h"
+#include <stdio.h>
+
+#include <gcutter.h>
+
+#include "../lib/grn-assertions.h"
+
+void test_prefix_search(void);
+
+static gchar *tmp_directory;
+
+static grn_ctx *context;
+static grn_obj *database;
+
+void
+cut_startup(void)
+{
+  tmp_directory = g_build_filename(grn_test_get_tmp_dir(),
+                                   "command-select-filter",
+                                   NULL);
+}
+
+void
+cut_shutdown(void)
+{
+  g_free(tmp_directory);
+}
+
+static void
+remove_tmp_directory(void)
+{
+  cut_remove_path(tmp_directory, NULL);
+}
+
+void
+cut_setup(void)
+{
+  const gchar *database_path;
+
+  remove_tmp_directory();
+  g_mkdir_with_parents(tmp_directory, 0700);
+
+  context = g_new0(grn_ctx, 1);
+  grn_ctx_init(context, 0);
+
+  database_path = cut_build_path(tmp_directory, "database.groonga", NULL);
+  database = grn_db_create(context, database_path, NULL);
+}
+
+void
+cut_teardown(void)
+{
+  if (context) {
+    grn_obj_unlink(context, database);
+    grn_ctx_fin(context);
+    g_free(context);
+  }
+
+  remove_tmp_directory();
+}
+
+void
+test_prefix_search(void)
+{
+  assert_send_command("table_create Users TABLE_PAT_KEY ShortText");
+  assert_send_command("load --table Users\n"
+                      "[\n"
+                      "{\"_key\":\"mori\"},\n"
+                      "{\"_key\":\"morita\"},\n"
+                      "{\"_key\":\"mona\"}\n"
+                      "]");
+  cut_assert_equal_string(
+      "[[[2],"
+       "[[\"_id\",\"UInt32\"],[\"_key\",\"ShortText\"]],"
+       "[2,\"morita\"],"
+       "[1,\"mori\"]]]",
+    send_command("select Users "
+                 "--filter '_key @^ \"mor\"'"));
+}




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