[Groonga-commit] groonga/groonga-command at 263338a [fix-travis-ci-error] normalize: add

Back to archive index

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


Kouhei Sutou	2013-10-14 22:42:51 +0900 (Mon, 14 Oct 2013)

  New Revision: 263338a83681d23ef9b5e6eff9d6b1c27c32f314
  https://github.com/groonga/groonga-command/commit/263338a83681d23ef9b5e6eff9d6b1c27c32f314

  Message:
    normalize: add

  Added files:
    lib/groonga/command/normalize.rb
    test/command/test-normalize.rb
  Modified files:
    lib/groonga/command.rb

  Modified: lib/groonga/command.rb (+1 -0)
===================================================================
--- lib/groonga/command.rb    2013-10-14 21:10:41 +0900 (1cca53b)
+++ lib/groonga/command.rb    2013-10-14 22:42:51 +0900 (7827569)
@@ -28,6 +28,7 @@ require "groonga/command/delete"
 require "groonga/command/dump"
 require "groonga/command/get"
 require "groonga/command/load"
+require "groonga/command/normalize"
 require "groonga/command/register"
 require "groonga/command/select"
 require "groonga/command/status"

  Added: lib/groonga/command/normalize.rb (+62 -0) 100644
===================================================================
--- /dev/null
+++ lib/groonga/command/normalize.rb    2013-10-14 22:42:51 +0900 (a11ff72)
@@ -0,0 +1,62 @@
+# -*- 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
+
+require "groonga/command/base"
+
+module Groonga
+  module Command
+    # A command class that represents `normalize` command.
+    #
+    # @since 1.0.6
+    class Normalize < Base
+      Command.register("normalize", self)
+
+      class << self
+        def parameter_names
+          [
+            :normalizer,
+            :string,
+            :flags,
+          ]
+        end
+      end
+
+      # @return [String] `normalizer` parameter value.
+      # @since 1.0.6
+      def normalizer
+        self[:normalizer]
+      end
+
+      # @return [String] `string` parameter value.
+      # @since 1.0.6
+      def string
+        self[:string]
+      end
+
+      # @return [Array<String>] An array of flags 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.0.6
+      def flags
+        @flags ||= (self[:flags] || "").split(/\s*[| ]\s*/)
+      end
+    end
+  end
+end

  Added: test/command/test-normalize.rb (+88 -0) 100644
===================================================================
--- /dev/null
+++ test/command/test-normalize.rb    2013-10-14 22:42:51 +0900 (e599067)
@@ -0,0 +1,88 @@
+# -*- 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 NormalizeCommandTest < Test::Unit::TestCase
+  private
+  def normalize_command(pair_arguments={}, ordered_arguments=[])
+    Groonga::Command::Normalize.new("normalize",
+                                    pair_arguments,
+                                    ordered_arguments)
+  end
+
+  class ConstructorTest < self
+    def test_ordered_arguments
+      normalizer = "NormalizerAuto"
+      string     = "AbcDef"
+      flags      = "REMOVE_BLANK"
+
+      ordered_arguments = [
+        normalizer,
+        string,
+        flags,
+      ]
+      command = normalize_command({}, ordered_arguments)
+      assert_equal({
+                     :normalizer => normalizer,
+                     :string     => string,
+                     :flags      => flags,
+                   },
+                   command.arguments)
+    end
+  end
+
+  class NormalizerTest < self
+    def test_reader
+      command = normalize_command(:normalizer => "NormalizerAuto")
+      assert_equal("NormalizerAuto", command.normalizer)
+    end
+  end
+
+  class StringTest < self
+    def test_reader
+      command = normalize_command(:string => "Hello World")
+      assert_equal("Hello World", command.string)
+    end
+  end
+
+  class FlagsTest < self
+    def test_nil
+      command = normalize_command
+      assert_equal([], command.flags)
+    end
+
+    def test_empty
+      command = normalize_command(:flags => "")
+      assert_equal([], command.flags)
+    end
+
+    def test_pipe_separator
+      command = normalize_command(:flags => "REMOVE_BLANK|WITH_TYPES")
+      assert_equal(["REMOVE_BLANK", "WITH_TYPES"], command.flags)
+    end
+
+    def test_space_separator
+      command = normalize_command(:flags => "REMOVE_BLANK WITH_TYPES")
+      assert_equal(["REMOVE_BLANK", "WITH_TYPES"], command.flags)
+    end
+
+    def test_spaces_around_separator
+      command = normalize_command(:flags => "REMOVE_BLANK | WITH_TYPES")
+      assert_equal(["REMOVE_BLANK", "WITH_TYPES"], command.flags)
+    end
+  end
+end
-------------- next part --------------
HTML����������������������������...
Download 



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