Kouhei Sutou
null+****@clear*****
Fri Jun 17 09:49:17 JST 2016
Kouhei Sutou 2016-06-17 09:49:17 +0900 (Fri, 17 Jun 2016) New Revision: 8534d48ea29f8cf23f4603ab398630218b589076 https://github.com/groonga/groonga-command/commit/8534d48ea29f8cf23f4603ab398630218b589076 Message: Support query_expand command Added files: lib/groonga/command/query-expand.rb test/command/test-query-expand.rb Modified files: lib/groonga/command.rb Modified: lib/groonga/command.rb (+1 -0) =================================================================== --- lib/groonga/command.rb 2016-03-21 23:11:52 +0900 (2932ff4) +++ lib/groonga/command.rb 2016-06-17 09:49:17 +0900 (ecf75e0) @@ -46,6 +46,7 @@ require "groonga/command/object-inspect" require "groonga/command/object-remove" require "groonga/command/plugin-register" require "groonga/command/plugin-unregister" +require "groonga/command/query-expand" require "groonga/command/range-filter" require "groonga/command/register" require "groonga/command/reindex" Added: lib/groonga/command/query-expand.rb (+99 -0) 100644 =================================================================== --- /dev/null +++ lib/groonga/command/query-expand.rb 2016-06-17 09:49:17 +0900 (3424d6a) @@ -0,0 +1,99 @@ +# Copyright (C) 2016 Kouhei Sutou <kou �� 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 as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# 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 + +require "groonga/command/base" + +module Groonga + module Command + # A command class that represents `query_expand` command. + # + # @since 1.2.1 + class QueryExpand < Base + Command.register("query_expand", self) + + class << self + def parameter_names + [ + :expander, + :query, + :flags, + ] + end + end + + # @return [String] `expander` parameter value. + # + # @since 1.2.1 + def expander + self[:expander] + end + + # @return [String] `query` parameter value. + # + # @since 1.2.1 + def query + self[:query] + end + + # @return [Array<String>] `flags` parameter value. + # + # @since 1.2.1 + def flags + @flags ||= (self[:flags] || "").split(/(?:\s*\|\s*)|(?:\s+)/) + end + + # @return [Boolean] `true` if `"ALLOW_PRAGMA"` is specified in + # {#flags}, `false` otherwise. + # + # @since 1.2.1 + def allow_pragma? + flags.include?("ALLOW_PRAGMA") + end + + # @return [Boolean] `true` if `"ALLOW_COLUMN"` is specified in + # {#flags}, `false` otherwise. + # + # @since 1.2.1 + def allow_column? + flags.include?("ALLOW_COLUMN") + end + + # @return [Boolean] `true` if `"ALLOW_UPDATE"` is specified in + # {#flags}, `false` otherwise. + # + # @since 1.2.1 + def allow_update? + flags.include?("ALLOW_UPDATE") + end + + # @return [Boolean] `true` if `"ALLOW_LEADING_NOT"` is specified in + # {#flags}, `false` otherwise. + # + # @since 1.2.1 + def allow_leading_not? + flags.include?("ALLOW_LEADING_NOT") + end + + # @return [Boolean] `true` if `"NONE"` is specified in {#flags}, + # `false` otherwise. + # + # @since 1.2.1 + def none? + flags.include?("NONE") + end + end + end +end Added: test/command/test-query-expand.rb (+171 -0) 100644 =================================================================== --- /dev/null +++ test/command/test-query-expand.rb 2016-06-17 09:49:17 +0900 (6057159) @@ -0,0 +1,171 @@ +# Copyright (C) 2016 Kouhei Sutou <kou �� 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 as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# 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 QueryExpandCommandTest < Test::Unit::TestCase + private + def query_expand_command(pair_arguments={}, ordered_arguments=[]) + Groonga::Command::QueryExpand.new("query_expand", + pair_arguments, + ordered_arguments) + end + + class ConstructorTest < self + def test_ordered_arguments + expander = "QueryExpanderTSV" + query = "Rroonga" + flags = "ALLOW_PRAGMA|ALLOW_COLUMN" + + command = query_expand_command({}, + [ + expander, + query, + flags, + ]) + assert_equal({ + :expander => expander, + :query => query, + :flags => flags, + }, + command.arguments) + end + end + + class ExpanderTest < self + def test_reader + command = query_expand_command(:expander => "QueryExpanderTSV") + assert_equal("QueryExpanderTSV", command.expander) + end + end + + class QueryTest < self + def test_reader + command = query_expand_command(:query => "Rroonga") + assert_equal("Rroonga", command.query) + end + end + + class FlagsTest < self + def test_omitted + command = query_expand_command + assert_equal([], + command.flags) + end + + def test_one + command = query_expand_command(:flags => "ALLOW_COLUMN") + assert_equal(["ALLOW_COLUMN"], + command.flags) + end + + def test_pipe_separator + command = query_expand_command(:flags => "ALLOW_UPDATE|ALLOW_COLUMN") + assert_equal(["ALLOW_UPDATE", "ALLOW_COLUMN"], + command.flags) + end + + def test_pipe_separator_with_space + command = query_expand_command(:flags => "ALLOW_UPDATE | ALLOW_COLUMN") + assert_equal(["ALLOW_UPDATE", "ALLOW_COLUMN"], + command.flags) + end + + def test_space_separator + command = query_expand_command(:flags => "ALLOW_UPDATE ALLOW_COLUMN") + assert_equal(["ALLOW_UPDATE", "ALLOW_COLUMN"], + command.flags) + end + end + + class AllowPragmaTest < self + def test_true + command = query_expand_command(:flags => "ALLOW_PRAGMA") + assert do + command.allow_pragma? + end + end + + def test_false + command = query_expand_command(:flags => "ALLOW_COLUMN") + assert do + not command.allow_pragma? + end + end + end + + class AllowColumnTest < self + def test_true + command = query_expand_command(:flags => "ALLOW_COLUMN") + assert do + command.allow_column? + end + end + + def test_false + command = query_expand_command(:flags => "ALLOW_PRAGMA") + assert do + not command.allow_column? + end + end + end + + class AllowUpdateTest < self + def test_true + command = query_expand_command(:flags => "ALLOW_UPDATE") + assert do + command.allow_update? + end + end + + def test_false + command = query_expand_command(:flags => "ALLOW_PRAGMA") + assert do + not command.allow_update? + end + end + end + + class AllowLeadingNotTest < self + def test_true + command = query_expand_command(:flags => "ALLOW_LEADING_NOT") + assert do + command.allow_leading_not? + end + end + + def test_false + command = query_expand_command(:flags => "ALLOW_PRAGMA") + assert do + not command.allow_leading_not? + end + end + end + + class NoneTest < self + def test_true + command = query_expand_command(:flags => "NONE") + assert do + command.none? + end + end + + def test_false + command = query_expand_command(:flags => "ALLOW_PRAGMA") + assert do + not command.none? + end + end + end +end -------------- next part -------------- HTML����������������������������... Télécharger