Navigation Menu

Skip to content

Commit

Permalink
Add Operator::REGEXP
Browse files Browse the repository at this point in the history
GitHub: #65
  • Loading branch information
Masafumi Yokoyama committed Apr 7, 2015
1 parent 74fdf75 commit c2c7162
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ext/groonga/rb-grn-operator.c
Expand Up @@ -220,6 +220,8 @@ rb_grn_operator_from_ruby_object (VALUE rb_operator)
} else if (rb_grn_equal_option(rb_operator, "json-put") ||
rb_grn_equal_option(rb_operator, "json_put")) {
operator = GRN_OP_JSON_PUT;
} else if (rb_grn_equal_option(rb_operator, "regexp")) {
operator = GRN_OP_REGEXP;
} else {
rb_raise(rb_eArgError,
"operator should be one of "
Expand Down Expand Up @@ -426,6 +428,8 @@ rb_grn_init_operator (VALUE mGrn)
UINT2NUM(GRN_OP_TABLE_GROUP));
rb_define_const(rb_mGrnOperator, "JSON_PUT",
UINT2NUM(GRN_OP_JSON_PUT));
rb_define_const(rb_mGrnOperator, "REGEXP",
UINT2NUM(GRN_OP_REGEXP));


/*
Expand Down
59 changes: 59 additions & 0 deletions test/test-operator.rb
@@ -0,0 +1,59 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2015 Masafumi Yokoyama <yokoyama@clear-code.com>
#
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

class OperatorTest < Test::Unit::TestCase
include GroongaTestUtils

setup :setup_database

class RegexpTest < self
setup
def setup_expression
@expression = Groonga::Expression.new
@expression.append_constant(39)
@expression.append_constant(93)
end

def test_constant
@expression.append_operation(Groonga::Operator::REGEXP, 2)
assert_equal(<<-END_OF_INSPECT.chomp, @expression.inspect)
#<Groonga::Expression
vars:{
},
codes:{
0:<push n_args:1, flags:0, modify:2, value:39>,
1:<push n_args:1, flags:0, modify:0, value:93>,
2:<regexp n_args:2, flags:0, modify:0, value:(NULL)>
}>
END_OF_INSPECT
end

def test_name
@expression.append_operation("regexp", 2)
assert_equal(<<-END_OF_INSPECT.chomp, @expression.inspect)
#<Groonga::Expression
vars:{
},
codes:{
0:<push n_args:1, flags:0, modify:2, value:39>,
1:<push n_args:1, flags:0, modify:0, value:93>,
2:<regexp n_args:2, flags:0, modify:0, value:(NULL)>
}>
END_OF_INSPECT
end
end
end

0 comments on commit c2c7162

Please sign in to comment.