[Groonga-commit] droonga/fluent-plugin-droonga at 368cb7a [master] command: add :include? operator

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Jan 31 18:11:26 JST 2014


Kouhei Sutou	2014-01-31 18:11:26 +0900 (Fri, 31 Jan 2014)

  New Revision: 368cb7a47a86b803b7c704fd737860640e647022
  https://github.com/droonga/fluent-plugin-droonga/commit/368cb7a47a86b803b7c704fd737860640e647022

  Message:
    command: add :include? operator

  Modified files:
    lib/droonga/command.rb
    test/unit/test_command.rb

  Modified: lib/droonga/command.rb (+6 -1)
===================================================================
--- lib/droonga/command.rb    2014-01-31 18:06:40 +0900 (08a53ee)
+++ lib/droonga/command.rb    2014-01-31 18:11:26 +0900 (19d1547)
@@ -28,7 +28,7 @@ module Droonga
     #      * PATTERN = [TARGET_PATH, OPERATOR, ARGUMENTS*]
     #      * PATTERN = [PATTERN, LOGICAL_OPERATOR, PATTERN]
     #      * TARGET_PATH = "COMPONENT(.COMPONENT)*"
-    #      * OPERATOR = :equal, :in
+    #      * OPERATOR = :equal, :in, :include?
     #                   (More operators may be added in the future.
     #                    For example, :exist?, :start_with and so on.)
     #      * ARGUMENTS = OBJECT_DEFINED_IN_JSON*
@@ -99,6 +99,11 @@ module Droonga
         [target] == arguments
       when :in
         arguments.include?(target)
+      when :include?
+        return false unless target.respond_to?(:include?)
+        arguments.any? do |argument|
+          target.include?(argument)
+        end
       else
         raise ArgumentError, "Unknown operator"
       end

  Modified: test/unit/test_command.rb (+28 -0)
===================================================================
--- test/unit/test_command.rb    2014-01-31 18:06:40 +0900 (86c2d17)
+++ test/unit/test_command.rb    2014-01-31 18:11:26 +0900 (04d0a4a)
@@ -95,5 +95,33 @@ class CommandTest < Test::Unit::TestCase
                             }))
       end
     end
+
+    class IncludeTest < self
+      def test_exist
+        assert_true(match?([["originalTypes", :include?, "select"]],
+                           {
+                             "originalTypes" => ["search", "select"],
+                           }))
+      end
+
+      def test_not_exist
+        assert_false(match?([["originalTypes", :include?, "select"]],
+                            {
+                              "originalTypes" => ["load"],
+                            }))
+      end
+
+      def test_no_key
+        assert_false(match?([["originalTypes", :include?, "select"]],
+                            {}))
+      end
+
+      def test_not_enumerable
+        assert_false(match?([["originalTypes", :include?, "select"]],
+                            {
+                              "originalTypes" => 29,
+                            }))
+      end
+    end
   end
 end
-------------- next part --------------
HTML����������������������������...
Download 



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