Kouhei Sutou
null+****@clear*****
Mon Jan 26 19:30:50 JST 2015
Kouhei Sutou 2015-01-26 19:30:50 +0900 (Mon, 26 Jan 2015) New Revision: 3a315cf7662e1255b3198c6874f4e9165a6ca9d1 https://github.com/groonga/groonga-command/commit/3a315cf7662e1255b3198c6874f4e9165a6ca9d1 Message: Support table_tokenize Added files: lib/groonga/command/table-tokenize.rb test/command/test-table-tokenize.rb Modified files: lib/groonga/command.rb Modified: lib/groonga/command.rb (+1 -0) =================================================================== --- lib/groonga/command.rb 2015-01-26 15:51:40 +0900 (da15db6) +++ lib/groonga/command.rb 2015-01-26 19:30:50 +0900 (437c177) @@ -39,5 +39,6 @@ require "groonga/command/suggest" require "groonga/command/table-create" require "groonga/command/table-remove" require "groonga/command/table-rename" +require "groonga/command/table-tokenize" require "groonga/command/tokenize" require "groonga/command/truncate" Added: lib/groonga/command/table-tokenize.rb (+70 -0) 100644 =================================================================== --- /dev/null +++ lib/groonga/command/table-tokenize.rb 2015-01-26 19:30:50 +0900 (1dd0ba3) @@ -0,0 +1,70 @@ +# Copyright (C) 2015 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 `table_tokenize` command. + # + # @since 1.1.0 + class TableTokenize < Base + Command.register("table_tokenize", self) + + class << self + def parameter_names + [ + :table, + :string, + :flags, + :mode, + ] + end + end + + # @return [String] `table` parameter value. + # + # @since 1.1.0 + def table + self[:table] + end + + # @return [String] `string` parameter value. + # + # @since 1.1.0 + def string + self[:string] + end + + # @return [Array<String>] An array of flag specified in `flags` + # parameter value. This array is extracted by parsing `flags` + # parameter value. If `flags` parameter value is nil or empty, + # an empty array is returned. + # + # @since 1.1.0 + def flags + @flags ||= (self[:flags] || "").split(/\s*[| ]\s*/) + end + + # @return [String] `mode` parameter value. + # + # @since 1.1.0 + def mode + self[:mode] + end + end + end +end Added: test/command/test-table-tokenize.rb (+99 -0) 100644 =================================================================== --- /dev/null +++ test/command/test-table-tokenize.rb 2015-01-26 19:30:50 +0900 (563bed4) @@ -0,0 +1,99 @@ +# Copyright (C) 2015 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 TableTokenizeCommandTest < Test::Unit::TestCase + private + def table_tokenize_command(pair_arguments={}, ordered_arguments=[]) + Groonga::Command::TableTokenize.new("table_tokenize", + pair_arguments, + ordered_arguments) + end + + class ConstructorTest < self + def test_ordered_arguments + table = "Lexicon" + string = "groonga ruby linux" + flags = "NONE" + mode = "ADD" + + ordered_arguments = [ + table, + string, + flags, + mode, + ] + command = tokenize_command({}, ordered_arguments) + assert_equal({ + :table => table, + :string => string, + :flags => flags, + :mode => mode, + }, + command.arguments) + end + end + + class TableTest < self + def test_reader + command = table_tokenize_command(:table => "Lexicon") + assert_equal("Lexicon", command.table) + end + end + + class StringTest < self + def test_reader + command = table_tokenize_command(:string => "Hello World") + assert_equal("Hello World", command.string) + end + end + + class FlagsTest < self + def test_nil + command = table_tokenize_command + assert_equal([], command.flags) + end + + def test_empty + command = table_tokenize_command(:flags => "") + assert_equal([], command.flags) + end + + def test_pipe_separator + flags = "NONE|ENABLE_TOKENIZED_DELIMITER" + command = table_tokenize_command(:flags => flags) + assert_equal(["NONE", "ENABLE_TOKENIZED_DELIMITER"], command.flags) + end + + def test_space_separator + flags = "NONE ENABLE_TOKENIZED_DELIMITER" + command = table_tokenize_command(:flags => flags) + assert_equal(["NONE", "ENABLE_TOKENIZED_DELIMITER"], command.flags) + end + + def test_spaces_around_separator + flags = "NONE | ENABLE_TOKENIZED_DELIMITER" + command = table_tokenize_command(:flags => flag) + assert_equal(["NONE", "ENABLE_TOKENIZED_DELIMITER"], command.flags) + end + end + + class ModeTest < self + def test_reader + command = table_tokenize_command(:mode => "ADD") + assert_equal("ADD", command.mode) + end + end +end -------------- next part -------------- HTML����������������������������...Download