[Groonga-commit] groonga/groonga-command at 35079e4 [fix-travis-ci-error] tokenize: add

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Jan 13 17:21:41 JST 2016


Kouhei Sutou	2013-10-14 20:59:54 +0900 (Mon, 14 Oct 2013)

  New Revision: 35079e4b17038a672ac1bd16f20d58d9c8e2e23b
  https://github.com/groonga/groonga-command/commit/35079e4b17038a672ac1bd16f20d58d9c8e2e23b

  Message:
    tokenize: add

  Added files:
    test/command/test-tokenize.rb
  Copied files:
    lib/groonga/command/tokenize.rb
      (from lib/groonga/command.rb)
  Modified files:
    lib/groonga/command.rb

  Modified: lib/groonga/command.rb (+1 -0)
===================================================================
--- lib/groonga/command.rb    2013-10-14 20:48:28 +0900 (5a63e4b)
+++ lib/groonga/command.rb    2013-10-14 20:59:54 +0900 (2d5d224)
@@ -34,4 +34,5 @@ require "groonga/command/suggest"
 require "groonga/command/table-create"
 require "groonga/command/table-remove"
 require "groonga/command/table-rename"
+require "groonga/command/tokenize"
 require "groonga/command/truncate"

  Copied: lib/groonga/command/tokenize.rb (+35 -18) 53%
===================================================================
--- lib/groonga/command.rb    2013-10-14 20:48:28 +0900 (5a63e4b)
+++ lib/groonga/command/tokenize.rb    2013-10-14 20:59:54 +0900 (9d10901)
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 #
-# Copyright (C) 2012-2013  Kouhei Sutou <kou �� clear-code.com>
+# Copyright (C) 2013  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
@@ -16,22 +16,39 @@
 # 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/version"
+require "groonga/command/base"
 
-require "groonga/command/error"
+module Groonga
+  module Command
+    class Tokenize < Base
+      Command.register("tokenize", self)
 
-require "groonga/command/column-create"
-require "groonga/command/column-remove"
-require "groonga/command/column-rename"
-require "groonga/command/delete"
-require "groonga/command/dump"
-require "groonga/command/get"
-require "groonga/command/load"
-require "groonga/command/register"
-require "groonga/command/select"
-require "groonga/command/status"
-require "groonga/command/suggest"
-require "groonga/command/table-create"
-require "groonga/command/table-remove"
-require "groonga/command/table-rename"
-require "groonga/command/truncate"
+      class << self
+        def parameter_names
+          [
+            :tokenizer,
+            :string,
+            :normalizer,
+            :flags,
+          ]
+        end
+      end
+
+      def tokenizer
+        self[:tokenizer]
+      end
+
+      def string
+        self[:string]
+      end
+
+      def normalizer
+        self[:normalizer]
+      end
+
+      def flags
+        @flags ||= (self[:flags] || "").split(/\s*[| ]\s*/)
+      end
+    end
+  end
+end

  Added: test/command/test-tokenize.rb (+98 -0) 100644
===================================================================
--- /dev/null
+++ test/command/test-tokenize.rb    2013-10-14 20:59:54 +0900 (03f7280)
@@ -0,0 +1,98 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2013  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 TokenizeCommandTest < Test::Unit::TestCase
+  private
+  def tokenize_command(pair_arguments={}, ordered_arguments=[])
+    Groonga::Command::Tokenize.new("tokenize",
+                                   pair_arguments,
+                                   ordered_arguments)
+  end
+
+  class ConstructorTest < self
+    def test_ordered_arguments
+      tokenizer  = "TokenDelimit"
+      string     = "groonga ruby linux"
+      normalizer = "NormalizerAuto"
+      flags      = "NONE"
+
+      ordered_arguments = [
+        tokenizer,
+        string,
+        normalizer,
+        flags,
+      ]
+      command = tokenize_command({}, ordered_arguments)
+      assert_equal({
+                     :tokenizer  => tokenizer,
+                     :string     => string,
+                     :normalizer => normalizer,
+                     :flags      => flags,
+                   },
+                   command.arguments)
+    end
+  end
+
+  class TokenizerTest < self
+    def test_reader
+      command = tokenize_command(:tokenizer => "TokenBigram")
+      assert_equal("TokenBigram", command.tokenizer)
+    end
+  end
+
+  class StringTest < self
+    def test_reader
+      command = tokenize_command(:string => "Hello World")
+      assert_equal("Hello World", command.string)
+    end
+  end
+
+  class NormalizerTest < self
+    def test_reader
+      command = tokenize_command(:normalizer => "NormalizerAuto")
+      assert_equal("NormalizerAuto", command.normalizer)
+    end
+  end
+
+  class FlagsTest < self
+    def test_nil
+      command = tokenize_command
+      assert_equal([], command.flags)
+    end
+
+    def test_empty
+      command = tokenize_command(:flags => "")
+      assert_equal([], command.flags)
+    end
+
+    def test_pipe_separator
+      command = tokenize_command(:flags => "NONE|ENABLE_TOKENIZED_DELIMITER")
+      assert_equal(["NONE", "ENABLE_TOKENIZED_DELIMITER"], command.flags)
+    end
+
+    def test_space_separator
+      command = tokenize_command(:flags => "NONE ENABLE_TOKENIZED_DELIMITER")
+      assert_equal(["NONE", "ENABLE_TOKENIZED_DELIMITER"], command.flags)
+    end
+
+    def test_spaces_around_separator
+      command = tokenize_command(:flags => "NONE | ENABLE_TOKENIZED_DELIMITER")
+      assert_equal(["NONE", "ENABLE_TOKENIZED_DELIMITER"], command.flags)
+    end
+  end
+end
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index