void test_parse(gconstpointer data) { grn_obj *v; prepare_data(); cond = grn_expr_create(&context, NULL, 0); cut_assert_not_null(cond); v = grn_expr_add_var(&context, cond, NULL, 0); cut_assert_not_null(v); GRN_RECORD_INIT(v, 0, grn_obj_id(&context, docs)); PARSE(cond, gcut_data_get_string(data, "query_hoge_moge"), gcut_data_get_int(data, "query_hoge_moge_parse_level")); PARSE(cond, gcut_data_get_string(data, "query_poyo"), gcut_data_get_int(data, "query_poyo_parse_level")); grn_expr_append_op(&context, cond, GRN_OP_AND, 2); grn_test_assert_expr(&context, "noname($1:0){2body GET_VALUE,0\"hoge\",4MATCH," "2body GET_VALUE,0\"moge\",0MATCH,4AND," "2body GET_VALUE,0\"poyo\",0MATCH,0AND}", cond); res = grn_table_create(&context, NULL, 0, NULL, GRN_TABLE_HASH_KEY|GRN_OBJ_WITH_SUBREC, docs, NULL); cut_assert_not_null(res); cut_assert_not_null(grn_table_select(&context, docs, cond, res, GRN_OP_OR)); grn_test_assert_select(&context, gcut_take_new_list_string("poyo moge hoge " "moge moge moge", NULL), res, "body"); grn_test_assert(grn_obj_close(&context, res)); res = NULL; grn_test_assert(grn_obj_close(&context, cond)); cond = NULL; cond = grn_expr_create(&context, NULL, 0); cut_assert_not_null(cond); v = grn_expr_add_var(&context, cond, NULL, 0); cut_assert_not_null(v); GRN_RECORD_INIT(v, 0, grn_obj_id(&context, docs)); PARSE(cond, gcut_data_get_string(data, "query_size"), gcut_data_get_int(data, "query_size_parse_level")); grn_test_assert_expr(&context, "noname($1:0){2size GET_VALUE,014,0EQUAL}", cond); res = grn_table_create(&context, NULL, 0, NULL, GRN_TABLE_HASH_KEY|GRN_OBJ_WITH_SUBREC, docs, NULL); cut_assert_not_null(res); cut_assert_not_null(grn_table_select(&context, docs, cond, res, GRN_OP_OR)); grn_test_assert_select(&context, gcut_take_new_list_string("moge moge moge", "hoge fuga fuga", "moge hoge hoge", NULL), res, "body"); }
void test_parse(gconstpointer data) { grn_obj *v; prepare_data(); cond = grn_expr_create(&context, NULL, 0); cut_assert_not_null(cond); v = grn_expr_add_var(&context, cond, NULL, 0); cut_assert_not_null(v); GRN_RECORD_INIT(v, 0, grn_obj_id(&context, docs)); PARSE(cond, gcut_data_get_string(data, "query_hoge_moge"), gcut_data_get_int(data, "query_hoge_moge_parse_level")); PARSE(cond, gcut_data_get_string(data, "query_poyo"), gcut_data_get_int(data, "query_poyo_parse_level")); grn_expr_append_op(&context, cond, GRN_OP_AND, 2); grn_test_assert_expr( &context, "#<expr\n" " vars:{\n" " $1:#<record:no_key:docs id:0(nonexistent)>\n" " },\n" " codes:{\n" " 0:<get_value(), modify:2, " "value:#<column:var_size docs.body range:Text type:scalar compress:none>>,\n" " 1:<push(), modify:0, value:\"hoge\">,\n" " 2:<match(), modify:4, value:(NULL)>,\n" " 3:<get_value(), modify:2, " "value:#<column:var_size docs.body range:Text type:scalar compress:none>>,\n" " 4:<push(), modify:0, value:\"moge\">,\n" " 5:<match(), modify:0, value:(NULL)>,\n" " 6:<and(), modify:4, value:(NULL)>,\n" " 7:<get_value(), modify:2, " "value:#<column:var_size docs.body range:Text type:scalar compress:none>>,\n" " 8:<push(), modify:0, value:\"poyo\">,\n" " 9:<match(), modify:0, value:(NULL)>,\n" " 10:<and(), modify:0, value:(NULL)>\n" " }\n" ">", cond); res = grn_table_create(&context, NULL, 0, NULL, GRN_TABLE_HASH_KEY|GRN_OBJ_WITH_SUBREC, docs, NULL); cut_assert_not_null(res); cut_assert_not_null(grn_table_select(&context, docs, cond, res, GRN_OP_OR)); grn_test_assert_select(&context, gcut_take_new_list_string("poyo moge hoge " "moge moge moge", NULL), res, "body"); grn_test_assert(grn_obj_close(&context, res)); res = NULL; grn_test_assert(grn_obj_close(&context, cond)); cond = NULL; cond = grn_expr_create(&context, NULL, 0); cut_assert_not_null(cond); v = grn_expr_add_var(&context, cond, NULL, 0); cut_assert_not_null(v); GRN_RECORD_INIT(v, 0, grn_obj_id(&context, docs)); PARSE(cond, gcut_data_get_string(data, "query_size"), gcut_data_get_int(data, "query_size_parse_level")); grn_test_assert_expr( &context, "#<expr\n" " vars:{\n" " $1:#<record:no_key:docs id:0(nonexistent)>\n" " },\n" " codes:{\n" " 0:<get_value(), modify:2, " "value:#<column:fix_size docs.size range:UInt32 type:scalar compress:none>>,\n" " 1:<push(), modify:0, value:14>,\n" " 2:<equal(), modify:0, value:(NULL)>\n" " }\n" ">", cond); res = grn_table_create(&context, NULL, 0, NULL, GRN_TABLE_HASH_KEY|GRN_OBJ_WITH_SUBREC, docs, NULL); cut_assert_not_null(res); cut_assert_not_null(grn_table_select(&context, docs, cond, res, GRN_OP_OR)); grn_test_assert_select(&context, gcut_take_new_list_string("moge moge moge", "hoge fuga fuga", "moge hoge hoge", NULL), res, "body"); }